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,619 results
!date
2009-03-02 14:55:56
User: raphink
Tags: man
9

Launch a command from within a manpage, vim style. This is rather trivial, but can be very useful to try out the functions described in a manpage without actually quitting it (or switching to another console/screen/...).

rm file{1..10}
2009-03-02 14:42:05
User: atoponce
Functions: rm
3

Rather than typing out all 10 files, you can use brace expansion to do the trick for you. This is useful for backup files, numbered files, or any files with a repeating pattern. Gives more control than 'rm file*' as I might want to keep others around.

yum localinstall /path/to/package.rpm
2009-03-02 14:32:23
User: atoponce
6

When downloading RPMs from the Internet, you don't have to 'rpm -i' or 'rpm -U' to install the package. Especially, if the package has dependencies. If you have YUM setup to access an RPM repository, this command will install the downloaded package, then any dependencies through YUM that it relies on. Very handy on RPM-based systems.

tail -n 0 -f /var/log/messages
2009-03-02 14:21:18
User: atoponce
Functions: tail
3

In this case, I'm keeping an eye on /var/log/messages, but of course any file will do. When I'm following a file, I generally don't want to see anything other than what has been added due to the command or service I've executed. This keeps everything clean and tidy for troubleshooting.

tail -f file1 (file2 .. fileN)
2009-03-02 11:13:42
User: hberth
Functions: tail
Tags: bash Ubuntu
3

Useful to e.g. keep an eye on several logfiles.

tail -n 15 /var/log/yum.log | tac
2009-03-02 08:56:04
User: alcik
Functions: tail
Tags: yum tail
0

It displays, last 15 yum operations (in last operation as first row order) with its dates. Change 15 to any number of operations you need to display or remove "| tac" to see it in reverse order (last operation as last row)

vlc $(curl -s http://twitter.com/statuses/user_timeline/18855500.rss|grep play|sed -ne '/<title>/s/^.*\(http.*\)<\/title/\1/gp'|awk '{print $1}')
2009-03-02 05:36:19
User: tomwsmf
Tags: twitter
-1

This will play the audio goodness posted up on PlayTweets via twitter right form the ever loving cmdline. You do not even need a twitter account. I hashed this out in a bit of a hurray as the kids need to get to sleep....I will be adding a loop based feature that will play new items as they come in...after what your are listening to is over.

http://twitter.com/playTweets for more info on playtweets

sar -u 2 5
2009-03-02 04:54:37
User: rockon
2

Generated the CPU utilization stats with 5 lines /every 2 seconds.

Needs sysstat package to be installed prior to use sar.

lsof +p xxxx
cp /some/path/to/myfile{,.back}
2009-03-02 04:41:18
User: rockon
Functions: cp
1

Copy the file with the given .extension at the source file's location. Eliminates the typing of long paths again and again.

:%s/old/new/g
2009-03-02 03:01:13
User: leonza99
Tags: vim
2

Replace all ocurrences in the file.

The g option is to replace more than one occurrence in the same line. Whitout the g option, it only replace the first occurrence in the line.

mv filename.{old,new}
find . -type f | while read file; do cp $file ${file}.bak; done
2009-03-01 23:42:49
User: atoponce
Functions: cp find read
1

This is a simple case of recursing through all directories, adding the '.bak' extension to every file. Of course, the 'cp $file $file.bak' could be any code you need to apply to your recursion, including tests, other functions, creating variables, doing math, etc. Simple and clean recursion.

sudo find / -mmin 60 -type f
2009-03-01 23:03:31
User: atoponce
Functions: find sudo
28

Useful mainly for debugging or troubleshooting an application or system, such as X11, Apache, Bind, DHCP and others. Another useful switch that can be combined with -mmin, -mtime and so forth is -daystart. For example, to find files that were modified in the /etc directory only yesterday:

sudo find /etc -daystart -mtime 1 -type f
nc -l -p 2000 -c "nc example.org 3000"
2009-03-01 21:28:39
User: prayer
Tags: Network netcat
23

Redirect the local port 2000 to the remote port 3000. The same but UDP:

nc -u -l -p 2000 -c "nc -u example.org 3000"

It may be used to "convert" TCP client to UDP server (or viceversa):

nc -l -p 2000 -c "nc -u example.org 3000"
less -r <some file>
2009-03-01 21:19:53
User: prayer
Functions: less
Tags: less
2

It allows customizing by means of lesspipe. You need to write a ~/.lessfilter script and put this into your ~/.bashrc:

eval $(lesspipe)

export LESS=-r

elinks http://partmaps.org/era/unix/award.html
2009-03-01 18:59:55
User: sud0er
0

Everyone on CLIFU needs to check this site out. Learn how to accomplish what you've been doing faster and more efficiently.

sudo mount -o remount,rw /
2009-03-01 13:36:05
User: blindgaenger
Functions: mount sudo
Tags: mount remount rw
3

Saved my day, when my harddrive got stuck in read-only mode.

ethtool -S eth0
bzgrep -i "pattern" pattern.bz2
2009-03-01 10:21:26
User: rockon
Functions: bzgrep
0

Search the pattern in bzip2 compressed file with out having to unzip.

pinky -l <username>
2009-03-01 10:17:08
User: rockon
Functions: pinky
2

Gives information about user's home directory and real name and shell user is having.

hdparm -i[I] /dev/sda
2009-03-01 10:00:28
User: rockon
Functions: hdparm
9

Get the hard disk information with out shutting down and opening the system.

It gives information on model no., serial no., cylinders/heads/sectors, and the supported features of the hard disk.

lsb-release -a
2009-03-01 09:42:52
User: rockon
0

To know the OS distro and version, release.

Is same like /etc/redhat-release

join file1.txt file2.txt > file3.txt