xargs always confuses me

I have always had the hardest time working with xargs.  I usually end up with a bash foreach loop and some backticks instead.  But it really is cleaner to be able to specify a pipe from the generating command.

I had a situation recently where I had added some code to a PERL script that I was trying to understand.  I added some File::Temp code to dump incoming variables and the current environment.  I just used /tmp as my template directory since it was always guaranteed to be there and I didn't want to have even more code to create and maintain a new sub-directory.  Wow, that is lazy.  Anyway, I ended up with a bunch of /tmp/?????????? files, so I needed a quick way to grab all my files from temp and move them to a sub-directory for review.  xargs was the perfect solution here, AND (drum roll) I actually got it to do what I needed it to do:

cd /tmp/1
mkdir /tmp/1
fgrep -l dudeatwork.cgi ?????????? | xargs -I {} mv {} 1
which looks at all the files with 10 character names, looks for my generating cgi filename and then moves that file to the sub-directory.  Yeah, so it is unix 010, but I'm happy.

Comments

Popular posts from this blog

Xubuntu Home Server on Dell XPS 13 9370

Cygwin + syslog-ng

Installing Fedora 21 on a (late 2014) Mac Mini