CentOS 4.1 X86_64
I am trying to collect all my music files and extract them into a new directory flat, (without the hierarchy)
The command works find without the pipe, but do not work with.
1.Why don't the command work after the pipe? 2.How do I remove the hierarchy before extracting?
$ tar -cvf music.tar `find ../ -name '*.mp3' -o -name '*.ogg'` | tar -xvf music.tar
On Sun, 25 Sep 2005 at 5:56pm, Kai wrote
CentOS 4.1 X86_64
I am trying to collect all my music files and extract them into a new directory flat, (without the hierarchy)
The command works find without the pipe, but do not work with.
1.Why don't the command work after the pipe? 2.How do I remove the hierarchy before extracting?
$ tar -cvf music.tar `find ../ -name '*.mp3' -o -name '*.ogg'` | tar -xvf music.tar
Pipes direct the next command to read from stdin, but the '-f' flag to 'tar c' send its output to the named file, not stdout. A better form of the above command would be:
tar cvO `find ../ -name '*.mp3' -o -name '*.ogg'` | tar xf -
The 'O' in the first tar sends its output to stdout, and the 'f -' in the 2nd tells tar to read from stdin.
*However*, that will keep the directory structure. Why not just use cp?
find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp {} .
Joshua Baker-LePain wrote:
On Sun, 25 Sep 2005 at 5:56pm, Kai wrote
$ tar -cvf music.tar `find ../ -name '*.mp3' -o -name '*.ogg'` | tar -xvf music.tar
Pipes direct the next command to read from stdin, but the '-f' flag to 'tar c' send its output to the named file, not stdout. A better form of the above command would be:
tar cvO `find ../ -name '*.mp3' -o -name '*.ogg'` | tar xf -
The 'O' in the first tar sends its output to stdout, and the 'f -' in the 2nd tells tar to read from stdin.
*However*, that will keep the directory structure. Why not just use cp?
find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp {} .
Thank you for explaining, cp would be find, but I don't understand your arguments after the pipe. Please explain..
I have tried to use find ....... -exec cp {}; but cant get anything working using the cp in this type of command.
On Sun, 25 Sep 2005 at 6:52pm, Kai wrote
Joshua Baker-LePain wrote:
*However*, that will keep the directory structure. Why not just use cp?
find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp {} .
Thank you for explaining, cp would be find, but I don't understand your arguments after the pipe. Please explain..
I have tried to use find ....... -exec cp {}; but cant get anything working using the cp in this type of command.
xargs takes whatever comes in stdin and puts in after the commands which follow it. If you give 'xargs' the '-i' flag, it instead takes what comes in on stdin and puts it whereever you put the '{}' (note the location of the ). 'find | xargs' is *much* faster than 'find -exec' b/c you're not spawning a new process for every hit. The '-print0' to find and '-0' to xargs use nulls to delimit each entry rather than whitespace -- this lets the command work on files/directory names with spaces in them.
Joshua Baker-LePain wrote:
On Sun, 25 Sep 2005 at 6:52pm, Kai wrote
Joshua Baker-LePain wrote:
*However*, that will keep the directory structure. Why not just use cp?
find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp {} .
xargs takes whatever comes in stdin and puts in after the commands which follow it. If you give 'xargs' the '-i' flag, it instead takes what comes in on stdin and puts it whereever you put the '{}' (note the location of the ). 'find | xargs' is *much* faster than 'find -exec' b/c you're not spawning a new process for every hit. The '-print0' to find and '-0' to xargs use nulls to delimit each entry rather than whitespace -- this lets the command work on files/directory names with spaces in them.
Thank you soo much, I am very grateful. This has given me headache, really. You solved my problem. I do not fully understand the command: the argument \ standing before {} and the .
This confuses me a little bit because my understanding was that \ closed the command line and there should be nothing after. Also it maid me understand how to use the -exec. Again thank you.
find ../ -name '*.mp3' -o -name '*.ogg' -exec cp {} . ;
On Sun, Sep 25, 2005 at 12:55:32PM -0400, Joshua Baker-LePain wrote:
On Sun, 25 Sep 2005 at 6:52pm, Kai wrote
find ../ -name '*.mp3' -o -name '*.ogg' -print0 | xargs -0 -i cp {} .
^^
Shouldn't here also be a '-print0' ?
Cheers,