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,929 results
watch 'iptables -vL'
2009-03-20 14:49:12
User: alanr723
Functions: watch
3

Watch the number of packets/bytes coming through the firewall. Useful in setting up new iptables rules or chains. Use this output to reorder rules for efficiency.

stty -F "/dev/ttyUSB0" 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke time 5 min 1 line 0
2009-03-20 14:48:32
User: Alanceil
Functions: stty time
1

I had a hard time in finding the correct settings to get reasonable output from a coin selector which sends its data over a serial line. In the end, minicom came to the rescue and pointed me on the right track.

So, if you need to do something similar, these settings may help you.

Replace ttyUSB0 with your device file, 9600 with your baud rate, 5 with your read timeout (10ths of a second), and 1 with the minimum numbers of characters you want to read.

You can then open the device file like you are used to do, example:

DATA="`xxd -ps -l 5 \"$DEV\"`"
sed /BEGIN/,/END/s/xxx/yyy/g input.txt
2009-03-20 14:34:32
User: kayowas
Functions: sed
0

Replace the words between BEGIN and END.

mount | column -t
2009-03-20 14:18:56
User: thechile
Functions: column mount
244

Particularly useful if you're mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting.

nawk '{line[NR]=$0} END{for (; NR>=1; NR--){print line[NR]}}' FILENAME
echo ${file##*/}
ntpdate ntp.ubuntu.com pool.ntp.org
ls -l | sort -nk5
'ALT+.' or '<ESC> .'
2009-03-20 11:36:04
User: atoponce
259

When typing out long arguments, such as:

cp file.txt /var/www/wp-content/uploads/2009/03/

You can put that argument on your command line by holding down the ALT key and pressing the period '.' or by pressing <ESC> then the period '.'. For example:

cd 'ALT+.'

would put '/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing 'ALT+.' to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.

ropened='p4 opened | awk -F# "{print \$1}" | p4 -x - revert'
alias opened='p4 opened | awk -F# "{print \$1}"'
2009-03-20 11:06:41
User: Alexander
Functions: alias awk
Tags: p4 SCM Perforce
0

Just type 'opened' and get all files currently opened for edit.

date --date=yesterday
alias pst='pstree -Alpha'
2009-03-20 10:53:37
User: Alexander
Functions: alias
Tags: Linux
0

By 'pst' you can print out process tree with all details about all processes (including a command line, PID, and the current process you are running in).

By 'pst username' you can get an information about processes belonging to the particular user 'username'.

alias ..='cd ..'
2009-03-20 09:57:28
User: eimantas
Functions: alias
Tags: bash unix shell cd
9

Alias two dots to move to parent directory. Put it into your .bashrc or .profile file.

$mkdir mydir -> mv !$ yourdir -> $cd !$
if [ "${vote}" = "down" ]; then echo leave comment; fi
2009-03-20 00:31:13
Functions: echo
-10

I think it would be wise if anyone voting down left a comment indicating the reason for that action. Don't keep it to yourself. Thanks.

cmp -l file1.bin file2.bin | wc -l
( IFS=:; for p in $PATH; do echo $p; done )
2009-03-19 22:45:47
User: haivu
Functions: echo
Tags: bash
3

The output of "echo $PATH" is hard to read, this is much easier. The parentheses ensure that the change to the input field separator (IFS) only happens the the sub shell and not affecting the current shell.

PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST
2009-03-19 17:20:28
Functions: ls mpg123
-1

On my music directory, I create variable that contains all mp3s files, then I play them with mpg123. -C options enable terminal control key, s for stop, p for pause, f for forward to next song.

echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers
2009-03-19 13:23:43
User: refrax
Functions: echo
-14

I am new to linux, and I was trying to figure out why I could not sudo with my username in Fedora 10. This command, when run as root, will add a line to the sudoers file allowing the loginname supplied to sudo. The above line will require a password when you sudo, if you wish to sudo without password, use:

echo 'loginname ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

instead. you have to run this command as su, and this is just an easier way of using visudo, just adds it right from the terminal.

# wc -l /var/log/security/writable.today
2009-03-19 12:25:52
User: mpb
Functions: wc
0

Mandriva Linux includes a security tool called "msec" (configurable via "draksec").

One of the many things it regularily checks for is world writeable files.

If any are found, it writes the list to /var/log/security/writable.today.

"wc -l" simply counts the number of lines in the file.

This number should be low.

Browse through /var/log/security/writable.today and consider if any of those files *need* to be world-writeable (and if not, modify the permissions. eg: "chmod o-w $file").

A large number of world-writeable files may indicate that umask is not correctly set in /etc/profile (or ${HOME}/.bash_profile) but could also indicate poor security configuration or even malicious activity.

history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
vi ~/journal/$(date +%F)
2009-03-18 23:31:13
User: ar
Functions: date vi
1

prerequisite:

mkdir ~/journal
export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
2009-03-18 22:05:48
User: kamiller
Functions: export
Tags: color prompt
5

It colors the machine name and current directory different colors for easy viewing.