3

BACKGROUND

A directory can N-sub directories. Each sub directory contains multiple .rar files to be unzipped.

~/mydi r/Data 1 ~/mydi r/Data2 ... ~/mydi r/DataN

note the space between the 'i' and 'r' as well as the 'a' and '1'

GOAL

From the command line, issue a single command to Unzip.rar files and keep files in the original .rar directory (do not create new directories).

My first thought is to recursively build a list of the .rar files direct the output of:

find home/user /mydi\ r/Data\ 1 | grep .rar

into xargs and unrar:

unrar e -r /home/user/mydi\ r/Data\ 1/myfile.rar

QUESTION

Can xargs correctly process space characters in the directory and file names, without the \ character?

I suspect the space characdters in the directory and .rar filenames are causing errors with:

find /home/user/Desktop/ -name "*Har*.rar" | xargs  -d '\n'  unrar e -r  

because the unrar expects a '\' to precede the space character:

/home/user/mydi\ r/Data\ 1/myfile.rar

The error returned: No files to extract

Any diagnostic questions or suggestions are appreciated.

1 Answer 1

4

This is why GNU find has a -print0 option and GNU xargs has a -0 option: these options cause find to separate filenames with an ASCII NUL character, and cause xargs to look for a NUL character to separate input arguments. This allows you to correctly handle filenames that contain whitespace.

For example:

find /home/user/Desktop -name '*.rar' -print0 | xargs -0 -n1 unrar e -r

We need the -n1 flag to xargs because unrar e expects a single archive on the command line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .