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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
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.
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.
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:
In a multiple PostgreSQL server environment knowing the servers version can be important. Note that psql --version returns just the local psql apps version which may not be what you want. This command dumps the PostgreSQL servers version out to one line. You may need to add more command line options to the psql command for your connection environment.
This command will use the fdisk utility to find all block devices on your system, and overwrite them with data from the /dev/urandom non-blocking random number generator.
CAUTION: This will irrevocably erase EVERY SINGLE physical block storage device visible to the fdisk utility, including plugged USB devices, RAID sets, LVM, etc.
Connects to the last adb connection in history.
Useful if localhost is a small machine running BusyBox, which uses a slightly unusual format to set the date. Remotehost can be pretty much any Linux machine, including one running BusyBox. Uses UTC for portability.
-k, --keep-open will keep connection alive, and we could exclude using 'while true'
nc is such a powerful command, it could be used instead of any OS! :p
This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.
Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.
readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.
readom's verbosity gave more interesting output than dd.
On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.
'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.
'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.
'of=./filename.iso' simply means "create filename.iso in the current directory."
'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.
dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.
f='./filename.iso' specifies the output file.
speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.
retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.
use -xcvf to decompress
Useful for transferring large file over a network during operational hours
Useful for testing domain authentication through a Linux server
The "proportional set size" is probably the closest representation of how much active memory a process is using in the Linux virtual memory stack. This number should also closely represent the %mem found in ps(1), htop(1), and other utilities.
This uses mutt to send the file, and doesn't require uuencode etc
An entirely shell-based solution (should work on any bourne-style shell), more portable on relying on the rename command, the exact nature of which varies from distro to distro.
Info about Bluetooth devices.
Compares the md5 checksums of the contents of two directories, outputting the checksum and filename where any files differ. Shows only the file name, not the full path.
Compute the md5 checksums for the contents of two mirrored directories, then sort and diff the results. If everything matches, nothing is returned. Otherwise, any checksums which do not match, or which exist in one tree but not the other, are returned. As you might imagine, the output is useful only if no errors are found, because only the checksums, not filenames, are returned. I hope to address this, or that someone else will!
Optionally, pipe the output into http://sed.sourceforge.net/grabbag/scripts/html2iso.sed
Or: wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '//,//p' | sed -n '/
'/tmp/file 1.txt' '/tmp/file 2.jpg'
for Nautilus script
for Thunar action
If you linking the symlinks itself, but want to link to source files instead of symlinks, use
"`readlink -m "$i"`"
for i in '/tmp/file 1.txt' '/tmp/file 2.jpg'; do ln -s "`readlink -m "$i"`" "$i LINK"; done