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,492 results
ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9
cat /etc/debian_version
2009-08-05 14:47:05
User: caiosba
Functions: cat
-5

Easy way to find out what Debian version your machine is running

sudo alien --to-deb Your_PackAge.rpm
2009-09-27 13:49:07
User: eastwind
Functions: sudo
-5

convert to debian package file (deb) a redhat package file (rpm) , then you can install it by using dpkg , require alien package ( sudo apt-get install alien first )

for file in `find . -iname "FILENAME"`; do cat $file | sed "s/SEARCH_STRING/REPLACE_STRING/" > $file.tmp; mv $file.tmp $file; done
logs=$(find . -name *.log);for log in $logs; do cat /dev/null > $log;done
2009-03-04 10:05:48
Functions: cat find
-5

This find files of name like *.log and truncates them.

/^~
2012-08-02 21:10:23
User: mpb
-5

When searching in vi, the search string gets highlighted but the highlighting can become a nuisance.

By searching for the very unlikely pattern "^~" the highlighting is effectively switched off.

while true; do wget -r -l1 --no-clobber -A.txt http://911.wikileaks.org/files/index.html; done; cat *.txt | grep pass
ls -l `locate your_search_here`
2009-11-27 05:53:46
User: tjcertified
Functions: ls
-5

This command lists extended information about files, i.e. whether or not it is a true file or link, who owns it, etc. without having to 'ls' from the specific directory. If you know the filename, but not the location, this helps with finding other information about the file. It can be truncated by creating an alias for 'ls -l'. The sample output shows difference in regular locate vs. ls + locate.

sed '${LINE}d' ~/.ssh/known_host
2012-01-16 18:00:12
User: lucasrangit
Functions: sed
-5

When you SSH to a server who's hostname or IP has changed since the last time a connection was recorded in the known_hosts file a warning will be displayed since this indicated a possible DNS spoofing attack. If this is a known change then this command will remove the previous entry and allow the SSH connection. The SSH client will prompt you as if it was the first time connected to the server.

Replace ${LINE} with the line of the offending key in ~known_hosts. 49 in the sample output.

echo "13" | ed /etc/services
2011-09-15 19:37:49
User: muonIT
Functions: echo ed
Tags: goto
-5

Nth line of a file - dirty hack way. I haven't used ed in ages ;-)

echo "<your twit>" | wc -c -
head -n 13 /etc/services | tail -n 1
2011-09-15 19:39:49
User: muonIT
Functions: head tail
Tags: goto
-5

Silly approach, but easy to remember...

ls -1rSA | tail
2009-10-27 15:34:59
User: rbossy
Functions: ls
-5

This will only work on files since ls won't tell the size of a directory contents.

Note that the first switch is the digit one, not the letter ell.

find ./ -mtime -5 | xargs rm -f
alias agi='sudo apt-get install'
cd /example/directory && unzip \*.zip
2009-07-12 21:45:13
User: Paaskehare
Functions: cd
-5

Simple but useful little command to unzip all files in a directory.

tar --exclude='.svn' -c -f /path/to/file.tar /path/to/directory
for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
2009-03-23 23:51:18
User: chinkshady
Functions: ping
-5

Say you need to ping every 5th IP address on your network .. this will give you a way of doing that.

jot can also do counting ... like

jot 4

1

2

3

4

download from http://oreilly.com/catalog/upt2/examples/#jot or fins athena-jot in rpm format

kill %1
ls .??*
2009-09-29 14:40:37
User: Paula
Functions: ls
-5

Works 99.9% of the time; so far never required a more complex expression in manual input.

curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
2009-09-09 23:25:05
User: suxer
Functions: perl
-5

notice what happens when there is more than one unread message in a thread...

also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?

sudo service vpnclient_init start
2010-11-10 20:18:08
User: mariusbutuc
Functions: sudo
Tags: VPN CISCO
-5

Prerequisites:

[1] download the CISCO VPN client for linux: http://tuxx-home.at/archives/2007/09/24/T15_26_49/

[2] apply this ciscpo VPN patch: http://bit.ly/linux_vpn_patch

[*] use command to start client

[*+1] After copying your profile file to /etc/opt/cisco-vpnclient/Profiles, connect using

vpnclient connect TORVPN-TCP
egrep -in "this|that" *.dat
2011-07-06 09:42:26
User: evandrix
Functions: egrep
-5

grep - Search file for character string

Search for one or more strings in one or more files. Examples:-

grep that myfile.txt

Look for the string ``that'' in the file called ``myfile.txt'' and print out each line that matches.

egrep -in "this|that" *.dat

Extended grep search *.dat files for ``this'' or ``that'' case insensitive (-i) and where found print line number (-n) along with the line contents.

find . -name "*~" -exec rm {} \;
2010-02-26 10:54:02
User: ivanatora
Functions: find rm
Tags: vim find
-5

Assuming only VIM has *~ files in your current dir. If you have usefull data in a file named in the *~ pattern, DO NOT RUN this command!

ps aux | awk '/name/ {print $2}'
2009-02-20 21:35:52
User: evil_otto
Functions: awk ps
-5

This finds a process id by name, but without the extra grep that you usually see. Remember, awk can grep too!