What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands by mhs from sorted by
Terminal - Commands by mhs - 29 results
NSPR_LOG_MODULES=nsHostResolver:5 NSPR_LOG_FILE=/tmp/log.txt firefox
dnstop -l 3 enp1s0f0
i=in.swf; dump-gnash -1 -j 1280 -k 720 -D "${i%.*}".[email protected] -A "${i%.*}".wav "${i}"
2015-05-06 23:52:39
User: mhs

This will dump a raw BGRA pixel stream and WAV which must then be converted to video:

ffmpeg -f rawvideo -c:v rawvideo -s 1280x720 -r 12 -pix_fmt bgra -i "${i%.*}".bgra -c:v libx264 -preset veryslow -qp 0 -movflags +faststart -i "${i%.*}".wav -c:a libfdk_aac -b:a 384k "${i%.*}".mp4 ; rm "${i%.*}".bgra "${i%.*}".wav

Our example generates an x264/720p/12fps/AAC best-quality MP4.

To get dump-gnash, first install the build-dependencies for gnash (this step is OS-specific). Then:

git clone http://git.savannah.gnu.org/r/gnash.git ; cd gnash ; ./autogen.sh ; ./configure --enable-renderer=agg --enable-gui=dump --disable-menus --enable-media=ffmpeg --disable-jemalloc ; make
udevadm info -q all -n /dev/sdc | grep ID_PATH | cut -d'-' -f 2 | xargs -n 1 lspci -s
2015-01-27 15:34:02
User: mhs
Functions: cut grep info lspci xargs
Tags: lspci udevadm

Useful for big systems with lots of cards.

(Update: does not work with USB disks)

lstopo -p -v --whole-system --whole-io output.svg
dmidecode --type 9 |egrep 'Bus Address|Designation'
2015-01-27 15:13:59
User: mhs
Functions: egrep
Tags: dmidecode

Recent hardware may or may not enumerate *both of* these values

aptitude --purge remove ~i^foo ~i^bar
2015-01-27 15:00:48
User: mhs
Tags: aptitude

Could be dangerous, if you have many packages all beginning with 'foo' or 'bar'. This will easily remove them all from your system.

xset b 50 1700 10
[ ! -d /squashed/usr ] && mkdir -p /squashed/usr/{ro,rw} ; mksquashfs /usr /squashed/usr/usr.sfs.new -b 65536 ; mv /squashed/usr/usr.sfs.new /squashed/usr/usr.sfs ; reboot
2014-05-10 06:01:06
User: mhs
Functions: mkdir mv

Periodically run the one-liner above if/when there are significant changes to the files in /usr/

= Before rebooting, add following to /etc/fstab : =

/squashed/usr/usr.sfs /squashed/usr/ro squashfs loop,ro 0 0 usr /usr aufs udba=reval,br:/squashed/usr/rw:/squashed/usr/ro 0 0

No need to delete original /usr/ ! (unless you don't care about recovery). Also AuFS does not work with XFS

sdparm -s SCT=36000 --save /dev/sdb
2013-04-19 13:26:18
User: mhs
Tags: sdparm

So I had this 2TB Seagate external disk/USB enclosure which by default would spin-down its internal drive (it enters a standby mode) after four minutes of inactivity.. Spinning-up the inactive drive was an annoying delay when accessing files and also it severely interfered with NFS.. SCT stands for "Standby Condition Timer".

To completely disable SCT:

sdparm --clear STANDBY -6 /dev/sdb

To return to original (default) SCT settings:

sdparm -D -p 0x1a -6 /dev/sdb

To verify the settings (before and after):

sdparm -a /dev/sdb

No need for vendor-provided MSWIN tools, etc.

prlimit --cpu=10 sort -u hugefile
2013-02-27 15:59:11
User: mhs
Functions: sort
Tags: cpu util-linux

Similar to `cpulimit`, although `prlimit` can be found shipped with recent util-linux.

Example: limit CPU consumption to 10% for a math problem which ordinarily takes up 100% CPU:


bc -l <(echo "1234123412341234^12341234")

See the difference `prlimit` makes:

prlimit --cpu=10 bc -l <(echo "1234123412341234^12341234")

To actually monitor the CPU usage, use `top`, `sar`, etc.. or:

pidstat -C 'bc' -hur -p ALL 1
soffice --headless -convert-to odt:"writer8" somefile.docx
2012-12-27 15:08:38
User: mhs

In this example, the docx gets converted to Open Document .odt format.

For other formats, you'll need to specify the correct filter (Hint: see "Comments" link below for a nice list).

adb pull /dev/graphics/fb0 /dev/stdout | ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 480x800 -i pipe:0 -f image2 -vcodec png screenshot.png
2012-12-26 13:21:18
User: mhs

Works with *rooted* Android devices. 400x800 are the screen dimensions of a typical handheld smartphone.

adb pull /data/data/com.android.providers.contacts/databases/contacts2.db ; sqlite3 -batch <<EOF contacts2.db <CR> .header on <CR> .mode tabs <CR> select * from data; <CR> EOF
2012-12-26 11:35:23
User: mhs
Functions: tabs

Crude, but works. Note for security, /data/ will be inaccessible unless your device has been *rooted*.

On the other hand, if a device has been rooted, its data is now wide open to anyone with a USB cable and the above "one-liner".

`adb` is one of the platform tools in the android SDK.

To get SMS messages:

adb pull /data/data/com.android.providers.telephony/databases/mmssms.db ; sqlite3 -batch <<EOF contacts2.db <CR> .header on <CR> .mode tabs <CR> select * from sms; <CR> EOF
http_proxy= wget --http-user='domain\account' --http-password='###' -p -r -l 8 --no-remove-listing -P . 'http://sp.corp.com/teams/Team/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2fteams%2fTeam%2fShared%20Documents%2fFolder'
2012-12-26 09:03:55
User: mhs
Functions: wget

If you have to deal with MS Sharepoint which is (rarely, let's hope) used in e.g. certain corporate environments).

This uses Cntlm.

For single files, just use cURL -- its NTLM authentication works quite well.

# /etc/cntlm.conf:

# Username account

# Domain domain

# Password ############

# Proxy (IP of the sharepoint site)

# NoProxy *

# Listen 3128

socat unix-connect:/tmp/socket stdio,echo=0,raw
2012-12-19 07:58:09
User: mhs

Create a serial console with "socket (named pipe)" of "/tmp/socket", "from:server, to:virtual machine" in vmware player, etc.. gui. Run the above command after you have booted the guest OS (which should also be configured for serial console).

for i in $(multipath -ll | grep "3PARdata,VV"|awk '{print $1}') ; do parted -a optimal /dev/mapper/$i --script -- mklabel gpt mkpart primary 1 -1 set 1 lvm on ; done
2012-09-12 15:30:36
User: mhs
Functions: awk grep set

`multipath -ll` requires Device Mapper multipath.conf configuration. And of course, replace "3PARdata,VV" with your disk array's SCSI vendor,LUN name.

- GPT partition table allows you to create >2TB partitions

for i in /sys/block/sd* ; do wwn=`/lib/udev/scsi_id -g -s /block/${i##*/}` ; [ "$wwn" != "" ] && echo -e ${i##*/}'\t'$wwn ;done
2012-09-12 14:14:53
User: mhs
Functions: echo

Use `scsi_id` to positively identify which LUNs are which (i.e. compare with the list of LUNs you created on your disk array)

(shown: RHEL5 usage)

Debian usage:

# for i in /dev/sd* ; do wwn=`/lib/udev/scsi_id -g --device $i` ; [ "$wwn" != "" ] && echo -e ${i##*/}'\t'$wwn ;done
blkid -c /dev/null
2012-09-12 13:34:41
User: mhs

`blkid` is an interface to libuuid - it can read Device Mapper, EVMS, LVM, MD, and regular block devices.

-c /dev/null - Do not use cached output from /etc/blkid.tab or /etc/blkid/blkid.tab (RHEL)

-i - Display I/O Limits (aka I/O topology) information (not available in RHEL)

-p - Low-level superblock probing mode (not available in RHEL)

lsof -n -P|grep FlashXX|awk '{ print "/proc/" $2 "/fd/" substr($4, 1, length($4)-1) }'|while read f;do newname=$(exiftool -FileModifyDate -FileType -t -d %Y%m%d%H%M%S $f|cut -f2|tr '\n' '.'|sed 's/\.$//');echo "$f -> $newname";cp $f ~/Vids/$newname;done
2012-02-25 01:49:45
User: mhs
Functions: awk cp cut echo grep read sed tr

Certain Flash video players (e.g. Youtube) write their video streams to disk in /tmp/ , but the files are unlinked. i.e. the player creates the file and then immediately deletes the filename (unlinking files in this way makes it hard to find them, and/or ensures their cleanup if the browser or plugin should crash etc.) But as long as the flash plugin's process runs, a file descriptor remains in its /proc/ hierarchy, from which we (and the player) still have access to the file. The method above worked nicely for me when I had 50 tabs open with Youtube videos and didn't want to have to re-download them all with some tool.

exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_files
2012-02-01 10:54:03
User: mhs
Functions: exec

`your_cmd -erase_all_files` is the real process, but harmless-looking getty appears in the process table.

Never actually had a need to do this, but interesting nonetheless... Tested in bash, dash.

-a $NAME

"pass NAME as the zeroth argument to COMMAND", i.e. customise the name of the process (as commonly seen with `ps`)

lshw -short
echo "${0%/*}"
2011-04-17 12:09:56
User: mhs
Functions: echo

Invoked from within a shell script, this will print the directory in which the script resides. Doesn't depend on external tools, /proc/self/*, etc.. (`echo` is a shell builtin.) To see the *current working* directory of a script, use `pwd`.

mailutil appenddelete '{src.mailsrv1.com:993/imap/norsh/notls/ssl/novalidate-cert/user="username"}INBOX' '{dest.mailsrv2.com:143/imap/norsh/notls/user="username"}INBOX'
2011-02-08 09:37:05
User: mhs
Tags: mailutil IMAP

This one-liner was useful in helping someone I know to get off of MS Exchange. `mailutil` proved to be a much better alternative than `fetchmail` or `getmail` in this case.

It quickly moved all mails to the destination server (a simple Dovecot/Maildir setup), with no need to convert back and forth between mbox/maildir on the user's own system.

for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done
2010-12-29 13:23:48
User: mhs
Functions: ln rm

Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.