3 ms·
tar -xvf infers the filetype from the file; obviating the need for the smart untarring script. edit: Also, another useful thing is <command> | xargs -n1 -I{} <
by tudorachim 17y ago
tar -xvf infers the filetype from the file; obviating the need for the smart untarring script.
edit: Also, another useful thing is <command> | xargs -n1 -I{} <stuff>, which runs stuff once on every element of the output of command, replacing every occurrence of {} with the element. Then you can do something like "ls *.mp4 | xargs -n1 -I{} mv {} `basename {}`.mp3" .
- tyrmored 17y agoI quite like using for loops for that. I use it a lot for batch audio conversion with ffmpeg: for f in *.wma; do ffmpeg -i "$f" "${f/.wma/.mp3}"; done
- Periodic 17y agoI end up using this template for a lot of operations. Where rename really seems applicable is when you want to do complicated renamings such that regular expressions really are appropriate.
- deleted 17y ago[deleted]
- tyrmored 17y agoYeah. I used to love Bash but these days anything that takes more than a couple of lines I just use Perl. Its ubiquity helps a lot.
- skorgu 17y agoHeck if you have a recent gnu xargs you can add -P n and xargs will split the list out n ways and run them in parallel. Sort of like the first step of a poor-man's mapreduce. Reduce, on the other hand, is a pain; a simple > $$.out or similar on the xargs commandline probably won't work, best to wrap it up in a standalone script that does the same thing to guarantee you've got a new pid. Then you get something like: $ cat batch.sh #!/usr/bin/sh do_something_expensive $1 > tmp_$$.out $ find -print0 | xargs -n 1 -0 -I{} -P 4 bash ./batch.sh {} && cat tmp*out > batch.out && rm -rf tmp*out Of course this is huge overkill for nearly all jobs unless you have a good number of CPUs and even then you should probably find a better way if you find yourself doing this twice.
- sjf 17y agoThe program 'unp' will unpack _all_ kinds of archives with one command.