Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I wanted to wildcard directories and then wildcard all files in those directories.

How would I do so?

I know * is to wildcard all files, but I don't know how to wildcard directories.

For example pdf2djvu -o /dir/[wildcard dirs]/[wildcards.djvu] /dir/[wildcard dirs]/[wildcards.pdf]

On a secondary note can such a wildcard be affected if the location had a space where normally typing with "" for spaces it would be better to use \ - this time?

I tried what I posted above using the standard * for the wildcard dirs and wildcard files like /dir[entire dir had no spaces]/*/*.djvu but got the following error

I/O error (basic_ios::clear)

share|improve this question
I should enable globstar if you are using Bash: have a look at what-command-line-to-reliably-traverse-several-directory-levels. – user76204 Apr 1 '13 at 19:04
ehh that's a bit confusing I enabled globstar then check if it's enabled but * or {**/,} do not work – – user140393 Apr 1 '13 at 19:42
up vote 1 down vote accepted

One possible workaround is to use somethig like:

find . -iname *.pdf | xargs -I% pdf2djvu -o % %.djvu

This would find all pdf files starting in the current directory (recursive) and run the pdf2djvu command to produce file.pdf.djvu files.

share|improve this answer
I get the following error message xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option. I should also mention these files have spaces in them – user140393 Apr 2 '13 at 9:58

The problem is there's no good way to keep the two wildcard expansions in sync and iterate over them, like you're wanting to do. Since you only want to do this on one file at a time, it would be easier to just use find. If you want to recursively do this, I'd do find . -iname '*.pdf' -exec pdf3djvu -o '{}'.djvu '{}' \; If you have only certain directories you want to do this in, come up with shell wildcard which expands to those directories, and use that as the argument to find instead of .. For example, if you have several directories which end with "djvus" (like "pie_djvus" and "flag_djvus"):

find ./*djvus/ -maxdepth 1 -iname '*.pdf' -exec pdf3djvu -o '{}'.djvu '{}' \;

Using the / after the glob ensures that the glob will only match directories, and specifying the maxdepth of 1 ensures that the find won't go more than one level deep in the directories specified (which is the top level)

In both cases, you're going to end up with things like "file.pdf.djvu", which may or may not be annoying to you. So there will be a second post-processing step necessary if you used find. Here's one way to do it if you're using a recent bash as your shell (some shells will split filenames up on spaces, which will break this - but current bash does not).

for F in *.pdf.djvu; do mv -v "$F" "${F%.pdf.djvu}.djvu"; done
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.