Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,605 results
dd if=/dev/zero of=/dev/sdb bs=446 count=1
2009-06-07 10:29:49
User: dcabanis
Functions: dd
Tags: dd grub boot usb
0

If you don't want your computer to try to boot form a USB stick that used to be used as a boot device (maybe for a live linux distro), you will have to remove the boot loader from your stick other wise the boot will fail each time the device is attached to your PC.

for f in *.jpg; do exif --ifd=0 --tag=0x0110 --set-value="LOMO LC-A" --output=$f $f; exif --ifd=0 --tag=0x010f --set-value="LOMO" --output=$f $f; done }
2009-06-07 09:05:14
User: beanie
6

this takes every jpg in the current directory and changes the exif data for manufactur and model. in my case i change it to LOMO LC-A because my scanner puts his data in there :]

find . -type d -exec chmod 755 {} \;
2009-06-07 08:17:06
User: marssi
Functions: chmod find
Tags: find chmod
1

"find . -type d -print0 | xargs -0 chmod 755"

thanks masterofdisaster

find . -type f -print0|xargs -0 md5sum|sort|perl -ne 'chomp;$ph=$h;($h,$f)=split(/\s+/,$_,2);print "$f"."\x00" if ($h eq $ph)'|xargs -0 rm -v --
2009-06-07 03:14:06
Functions: find perl rm xargs
18

This one-liner will the *delete* without any further confirmation all 100% duplicates but one based on their md5 hash in the current directory tree (i.e including files in its subdirectories).

Good for cleaning up collections of mp3 files or pictures of your dog|cat|kids|wife being present in gazillion incarnations on hd.

md5sum can be substituted with sha1sum without problems.

The actual filename is not taken into account-just the hash is used.

Whatever sort thinks is the first filename is kept.

It is assumed that the filename does not contain 0x00.

As per the good suggestion in the first comment, this one does a hard link instead:

find . -xdev -type f -print0 | xargs -0 md5sum | sort | perl -ne 'chomp; $ph=$h; ($h,$f)=split(/\s+/,$_,2); if ($h ne $ph) { $k = $f; } else { unlink($f); link($k, $f); }'
find -L /path/to/check -type l -delete
2009-06-06 16:07:04
Functions: find
14

If you don't want to delete them, but just want to list them, do

find -L /path -type l

If you want to delete them with confirmation first, do

find -L /path -type l -exec rm -i {} +

Using the -L flag follows symlinks, so the -type l test only returns true if the link can't be followed, or is a symlink to another broken symlink.

ls | curl -F 'sprunge=<-' http://sprunge.us | xclip
2009-06-06 11:35:14
User: tatwright
Functions: ls
16

The URL can then be pasted with a middle click.

This is probably useful when trying to explain problems over instant messaging when you don't have some sort of shared desktop.

ssh -f -N -L 5432:talk.google.com:5222 user@home.network.com
2009-06-05 23:17:21
User: dcabanis
Functions: ssh
Tags: ssh
12

If your firewall or proxy at your location prevents connection to a particular host or port, you can use ssh to tunnel to your home server and do it there instead.

ssf -f -N -L 4321:home.network.com:25 user@home.network.com
2009-06-05 23:12:02
User: dcabanis
Tags: ssh
5

Uses ssh as tunnel tunnel for an other connection.

-f runs ssh in the background -N tell that there is no command to run -L deals with the forwarding aspect where the first number is the local port number, the second is parameter is the name of the server to forward to and the third parameter is the port number on that server. The last part of the command is the usual ssh form consisting of the user name and remote server name

ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
2009-06-05 21:11:17
User: dcabanis
Tags: video X11 ffmpeg
46

Grab X11 input and create an MPEG at 25 fps with the resolution 800x600

ssh $HOST -l$USER cat /REMOTE/FILE | sdiff /LOCAL/FILE -
rsync -e 'ssh -p PORT' user@host:SRC DEST
2009-06-05 16:52:43
Functions: rsync
3

tested on cygwin and Fedora 9 .

good to remember for those jobs where you cannot set a site-specific connect option in your ~/.ssh/config file.

svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
2009-06-05 14:07:28
User: jemptymethod
Functions: awk sort
Tags: svn awk log
4

just change the date following the -r flag, and/or the user name in the user== conditional statement, and substitute yms_web with the name of your module

find ./* -ctime -1 | xargs ls -ltr --color
2009-06-05 13:53:26
User: gnuyoga
Functions: find ls xargs
3

added alias in ~/.bashrc

alias lf='find ./* -ctime -1 | xargs ls -ltr --color'

ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
2009-06-04 20:25:49
User: localGhost
Functions: ifconfig
-3

The command above has been changed due to very good constructive criticism - thanks x 2! This command can be used after acquiring mac's, ip's and hostname's or any of the above from a freshly scanned LAN. User must be root, and remember to change your settings on your network managing software manually (Fedc10 NetworkManager Applet 0.7.1 is mine) instead of 'auto DHCP'. You can also substitute eth0 for wlan0 etc - be good and ENJOY!

enscript -E --color -t "title" -w html --toc -p /PATH/to/output.html /var/log/*log
ntpdate pool.ntp.org && hwclock --systohc && hwclock --adjust
2009-06-04 13:35:14
User: Weboide
Functions: hwclock
Tags: time sync ntp clock
5

Do not run this command if you already have ntpd running!

This needs to run as root, for example with sudo:

sudo ntpdate pool.ntp.org && sudo hwclock --systohc && sudo hwclock --adjust

This command will fetch accurate time from NTP servers and synchronize your system clock, then it will use the system clock to synchronize your hardware clock, and will calculate the time drift.

export http_proxy=<user>:<pass>@<server>:<port> ftp_proxy=<user>:<pass>@<server>:<port>
sudo ifconfig eth0 hw ether 00:01:02:03:04:05
2009-06-04 09:02:35
User: momitov
Functions: ifconfig sudo
6

eth0 = the name of the interface

00:01:02:03:04:05 = the new mac adresse

the same thing for wireless card $ sudo iwconfig eth1 hw ether 00:01:02:03:04:05

recode UTF8..UTF-16LE linux-utf8-file.txt
2009-06-04 08:53:51
User: greppo
0

Convert file from the UTF8 encoding used on Linux (has no "EF BB BF" byte order mark at the start) to the UTF-16 encoding used on Windows (has an "FF FE" byte order mark at the start).

Thanks to commenter: previous iconv command was the obsolete way to do it.

if [ -z $(echo $var | grep [0-9]) ]; then echo "NON NUMERIC"; fi
2009-06-04 07:41:26
User: AnusJenkins
Functions: echo grep
2

use to execute a block of code only if $var is numeric

lshw -html > hardware.html
2009-06-04 07:14:03
User: flart
27

After the command is done, open the html file in a browser

find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"
2009-06-03 22:08:48
User: vincentp
Functions: find grep
11

Finds all corrupted jpeg files in current directory and its subdirectories. Displays the error or warning found.

The jpeginfo is part of the jpeginfo package in debian.

Should you wish to only get corrupted filenames, use cut to extract them :

find ./ -name *jpg -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR" | cut -d " " -f 1
awk '/match/{print NR}' file
sed -n -e '1,/match/p'
URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
2009-06-03 14:26:55
User: sunny256
Functions: diff grep sort
Tags: bash svn
2

Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.