Commands by mulad (10)

  • FreeBSD version of the Linux command mount discimg.iso /cdrom -o loop The "mdconfig" command creates a device and prints the name (typically "md0"). Just append that to "/dev/" and mount. Once unmounted, you can unconfigure the device with mdconfig -d -u 0 using "0" for md0, "1" for md1, etc.


    -1
    mount -t cd9660 /dev/`mdconfig -a -t vnode -f discimg.iso` /cdrom
    mulad · 2009-02-19 06:31:14 5
  • Many sites with Flash video players will download video files to /tmp on Linux, with temporary filenames like "FlashbGTHm4". These will often play in mplayer, totem, or other movie playing software. You must first navigate to a video page, let it start loading, and then pause playback.


    1
    mplayer $(ls -t /tmp/Flash*|head -1)
    mulad · 2009-02-19 04:38:40 8
  • If your CVS server has moved, here's a way to update your CVS Root files throughout your code tree without checking out a new copy of your files.


    0
    find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \;
    mulad · 2009-02-19 04:31:13 6
  • An apt-get wrapper function which will run the command via sudo, but will run it normally if you're only downloading source files. This was a bit of an excuse to show off the framework of cmd && echo true || echo false ...but as you can see, you must be careful about what is in the "true" block to make sure it executes without error, otherwise the "false" block will be executed. To allow the apt-get return code to pass through, you need to use a more normal if/else block: apt-get () { if [ "$1" = source ]; then command apt-get "$@"; else sudo apt-get "$@"; fi }


    1
    apt-get () { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" }
    mulad · 2009-02-19 04:17:24 12
  • These days, most software distributed in tar files will just contain a directory at the top level, but some tar files don't have this and can leave you with a mess of files in the current folder if you blindly execute tar zxvf something.tar.gz This command can help you clean up after such a mistake. However, note that this has the potential to do bad things if someone has been *really* nasty with filenames.


    2
    tar ztf tar-lacking-subdirectory.tar.gz | xargs rm
    mulad · 2009-02-19 00:34:09 11
  • The "vorbiscomment" utility lets you update information such as artist names and song and album tags in an Ogg Vorbis file. You can use this command to fix any mistakes that were made when ripping an album.


    1
    for f in *.ogg; do vorbiscomment -l "$f" | sed 's/peter gabriel/Peter Gabriel/' | vorbiscomment -w "$f"; done
    mulad · 2009-02-18 23:54:01 7
  • Yet another ps grep function, but this one includes the column headings. Show Sample Output


    1
    psg () { ps auxwww | egrep "$1|PID" | grep -v grep }
    mulad · 2009-02-18 23:37:35 6
  • The $[...] block in bash and zsh will let you do math. echo $[6*7] This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point. Show Sample Output


    0
    while true; do read i; echo $[$i]; done
    mulad · 2009-02-18 23:13:09 8
  • Upgraded Debian/Ubuntu/etc. systems may have a number of "orphaned" packages which are just taking up space, which can be found with the "deborphan" command. While you could just do "dpkg --purge $(deborphan)", the act of purging orphans will often create more orphans. This command will get them all in one shot.


    7
    while [ $(deborphan | wc -l) -gt 0 ]; do dpkg --purge $(deborphan); done
    mulad · 2009-02-18 22:31:22 9
  • This will convert filenames from uppercase to lowercase. I find this useful after downloading images from my digital camera. This works for English, but other languages may need something slightly more complex like this: for i in *; do mv "$i" "$(echo $i|tr [:upper:] [:lower:])"; done Also, the quote marks aren't necessary if your filenames don't contain spaces.


    5
    for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; done
    mulad · 2009-02-18 21:29:28 7

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Securely destroy data on given device
Intentional hash in the beginning. May run a looong time. Wipes your data for real. Was meant to be /dev/urandom - I mistyped it. :-)

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

list files recursively by size

Fork Bomb for Windows
Quick and dirty forkbomb for all flavors of windows Do not use in production. Replace start with a command of your choice, this will just open a new command prompt and is pretty tricky to stop once started

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Automagically update grub.conf labels after installing a new kernel
I like to label my grub boot options with the correct kernel version/build. After building and installing a new kernel with "make install" I had to edit my grub.conf by hand. To avoid this, I've decided to write this little command line to: 1. read the version/build part of the filename to which the kernel symlinks point 2. replace the first label lines of grub.conf grub.conf label lines must be in this format: Latest [{name}-{version/build}] Old [{name}-{version/build}] only the {version/build} part is substituted. For instance: title Latest [GNU/Linux-2.6.31-gentoo-r10.201003] would turn to title Latest [GNU/Linux-2.6.32-gentoo-r7.201004]"

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

run a command whenever a file is touched
This is useful if you'd like to see the output of a script while you edit it. Each time you save the file the command is executed. I thought for sure something like this already exists - and it probably does. I'm on an older system and tend to be missing some useful things. Examples: $ ontouchdo yourscript 'clear; yourscript somefiletoparse' Edit yourscript in a separate window and see new results each time you save. $ ontouchdo crufty.html 'clear; xmllint --noout crufty.html 2>&1 | head' Keep editing krufty.html until the xmllint window is empty. Note: Mac/bsd users should use stat -f%m. If you don't have stat, you can use perl -e '$f=shift; @s=stat($f); print "$s[9]\n";' $1

Pass TAB as field separator to sort, join, cut, etc.
Use this BASH trick to create a variable containing the TAB character and pass it as the argument to sort, join, cut and other commands which don't understand the \t notation. $ sort -t $'\t' ... $ join -t $'\t' ... $ cut -d $'\t' ...


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: