I have a set of files:

lium3@l128-37:/DATA/fr94/01 $ ls -l
total 7784
-rw-r--r-- 1 lium3 mcm1 395575 May  2  1996 fr940104.0z
-rw-r--r-- 1 lium3 mcm1 113815 May  2  1996 fr940104.1z
-rw-r--r-- 1 lium3 mcm1 186333 May  2  1996 fr940104.2z
-rw-r--r-- 1 lium3 mcm1 164854 May  2  1996 fr940105.0z
-rw-r--r-- 1 lium3 mcm1  39677 May  2  1996 fr940105.1z
-rw-r--r-- 1 lium3 mcm1 284948 May  2  1996 fr940105.2z

I wish to uncompress them all at once (this is just a sample!).

I tried this

find -name '*.0z' -exec sh -c 'uncompress  "${1%.*}" "$1"' _ {} \;

and just got:

gzip: ./fr940125.gz: No such file or directory
gzip: ./fr940125.0z: unknown suffix -- ignored
gzip: ./fr940106.gz: No such file or directory
gzip: ./fr940106.0z: unknown suffix -- ignored

I have many directories with files like these.

If I can get a script to do one directory, is it possible to do it recursively down through the directories?

  • When you say 'all at once', do you mean that you want the operation to be performed in parallel, using all cores of a multi-core machine? There does exist a program 'parallel' for that. – user1404316 Dec 11 '18 at 5:44

It looks like you have two problems:

1: Your ${1%.*} results in the basename of the files (e.g. fr940125), the uncompress therefore tries to add the default suffix .gz, for the combined new file name it tries, no file does exist.

2: you give a second parameter to uncompress, which is the correct file name of the archive, but uncompress does not know what to do with the file ending. Try to give the parameters '-S .0z' as argument.

The following command would maybe the right one, to recursively extract all .0z files in the current and all sub directories:

find -name '*.0z' -exec sh -c 'uncompress  -S .0z "$1"' _ {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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