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,927 results
curl whatismyip.org
nawk '{line[NR]=$0} END{for (; NR>=1; NR--){print line[NR]}}' FILENAME
sudo dmesg
for i in $(file * | grep broken | cut -d : -f 1); do rm $i; done
scp -P 22 /home/svnlabs.txt root@92.178.0.56:/home/svnlabs.txt
2010-01-22 16:55:25
User: svnlabs
Functions: scp
-6

Upload file to remote server using SCP

telnet zerocarbs.wooters.us
find ~/Desktop/ \( -regex '.*/\..*' \) -print -exec rm -Rf {} \;
watch -n 1 uptime\;myqladmin --user=<user> --password=<password> --verbose processlist
2009-03-21 18:29:28
User: root
Functions: watch
Tags: mysql
-6

Useful for monitoring both MySQL and the server load at the same time.

ps -ef | grep [j]boss | awk '{print $2}'|xargs kill -9
2010-09-30 15:55:41
User: utoxin
Functions: awk grep kill ps xargs
Tags: kill
-6

Removed unneeded grep -v by making the initial grep unable to match itself.

find Documents\ and\ Settings -iregex .+\.doc -or -iregex .+\.xls > office.lst
2010-11-04 17:58:52
User: yababay
Functions: find
-6

This command is useful for archiving or extracting Documents and Settings folder, when working in Linux box with Windows partition (dual boot installation). You have to enter into appropriate directory, of course.

ls -l | grep ^l
2009-04-02 17:47:36
User: haivu
Functions: grep ls
Tags: ls
-6

Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file.

Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.

sed 's/$//'
cat x
useradd -G {group-name} username
sedit() { cp "$*"{,.bk}; which $EDITOR > /dev/null && $EDITOR "$*" || vim "$*"; }
2011-08-16 18:28:22
User: kaedenn
Functions: cp vim which
-6

Some people put spaces in filenames. Others have an $EDITOR environment variable set. This defaults to vim, but you can use whatever you wish: emacs, nano, ed, butterflies, etc.

for a in $(seq 5 8); do cat twit.txt | cut -d " " -f$a | grep "^@" | sort -u; done > followlst.txt
2013-03-29 21:07:09
User: xmuda
Functions: cat cut grep seq sort
-6

Go to "https://twitter.com/search/realtime?q=%23TeamFollowBack&src=hash" and then copy al the text on the page. If you scroll down the page will be bigger. Then put al the text in a text file called twit.txt

If you follow the user there is a high probability the users give you follow back.

To follow all the users you can use an iMacros script.

cat /etc/*issue
FAIL2BAN=`ps ax | grep fail2ban | grep -v grep | awk {'print $1'}` && if [ -n "$FAIL2BAN" ]; then printf "\n[INFO] Fail2Ban is running and the PID is %s\n\n" $FAIL2BAN; else printf "\n [INFO] Fail2Ban is not running\n\n"; fi
2009-02-11 04:36:49
User: fmdlc
Functions: awk grep printf
-6

Check if Fail2Ban is running on the system and alert it with a message in the terminal

pv file1 > file2
2010-02-25 19:18:32
User: ppaschka
-6

Only works on single files, doesn't preserve permissions/timestamps/ownership.

(crontab -e) 00 12 * * * apt-get update (/etc/init.d/cron restart)
alias lh='ls -a | egrep "^\."'
rd /S /Q directory
setenforce 0
2013-04-05 15:38:05
User: techie
Tags: selinux
-6

This will turn off SE Linux

ifconfig |grep broadcast | awk '{print $2}'