Useful one-liners

If you have a couple dozen DSCxxxx.jpg photos that you need to be renamed sequentially (or any file for that matter), like I often do, this’ll do..
(change $c.jpg to whatever extension the files should end in, you can also apply arguments to ls -1 as necessary.)

f=$(ls -1); c=0; for i in $f; do mv $i $c.jpg; c=$(echo $c + 1 | bc); done

Strip large chunks of pesky comments from dist-default sample config files:

cat httpd.conf | perl -e 'while($a=<STDIN>){if($a !~ /^\s*#/){if($a ne "\n"){print $a;}}}' >httpd.conf.nocomments

Post Revisions:

Leave a comment

You must be logged in to post a comment.