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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





All commands from sorted by
Terminal - All commands - 12,273 results
LC_ALL=fr_FR luit ssh root@remote_machine_ip
jhead -autorot *.jpg
watch -n 5 -d cat /proc/mdstat
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
2009-03-03 20:10:19
User: netfortius
Functions: grep sed
Tags: perl sed

recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found


grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'
xset dpms force standby
urpmf lib/blah
2009-03-03 16:21:52
User: ender_x
Tags: mandriva urpmi

Look for an rpm that supplies a specific file that you don't yet have installed.

extremely useful when you need something and don't know where it is.. or what its called.

note: uses grep like syntax.

for i in *.html ; do mv $i ${i%.html}.htm ; done
emacs +400 code.py
2009-03-03 14:30:19
User: prayer
Functions: emacs
Tags: emacs

You may also use +line:column syntax.

zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
2009-03-03 13:45:56
User: dbart
Functions: awk sort uniq zgrep

This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system.

gunzip -c /var/log/auth.log.*.gz | cat - /var/log/auth.log /var/log/auth.log.0 | grep "Invalid user" | awk '{print $8;}' | sort | uniq -c | less
vlc --one-instance --playlist-enqueue -q $(while read netcast; do wget -q $netcast -O - |grep enclosure | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p'|head -n1; done <netcast.txt)
2009-03-03 04:26:01
User: tomwsmf
Functions: read sed tr wget

This is a quick line to stream in the latest offerings of your favorite netcasts/podcasts. You will need to have a file named netcast.txt in the directory you run this from. This file should have one and only one of your netcast's/podcst's url per line.

When run the line grabs the offering on the top of the netcast/podcast stack and end it over , quietly, to vlc.

Since I move around computers during the day I wanted an easy way to listen to my daily dose of news and such without having to worry about downloading to whatever machine I am on. This is just a quick grab and stream of whats current.

Future plans... have the list of netcasts be read from the web. possibly an rss or such. I use greader so there might be a way to use it as the source so as not to have to muck with multiple lists

find / -name "*.jpg" -print -exec rdjpgcom '{}' ';'
2009-03-03 02:13:44
User: Williebee
Functions: find

Finds comments in jpg files, but I can't figure out how to exclude (in output) files without comments.

sed -i 8d ~/.ssh/known_hosts
2009-03-02 23:58:45
User: leonza99
Tags: vim

This command delete all the empty lines (include the lines with space) from a file.

g = global command

\S = non-whitespace character; !\S the opposite

d = delete a range

less +G <filename>
2009-03-02 23:34:21
User: leper421
Functions: less

The same as typing 'less filename' then 'G' or '>' or the END key. Comes in handy with shell scripts or aliases:

alias weblog='less +G /var/log/httpd/access_log'

alias errlog='less +G /var/log/httpd/error_log'

ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$"
2009-03-02 23:15:13
User: leprasmurf
Functions: ifconfig

Needed to get the Mac of various devices on a solaris box, but didn't have root. This command used awk to display the Network device, the IP, and the MAC a line at a time.

:set ic
ssh -T user@host /bin/bash -i
2009-03-02 21:39:30
User: Bender
Functions: ssh

opens a "hidden" remote shell (login will not appear in "last" for example).

This is not really hidden, because the login will be shown in auth.log and the process is visible anyways.

ssh -T = Disable pseudo-tty allocation.

bash -i = interactive shell

awk -F "=| "
2009-03-02 21:09:51
User: Bender
Functions: awk cat file

You can use multiple field separators by separating them with | (=or).

This may be helpful when you want to split a string by two separators for example.

#echo "one=two three" | awk -F "=| " {'print $1, $3'}

one three

alias vb='vim ~/.bashrc; source ~/.bashrc'
2009-03-02 21:01:49
User: haivu
Functions: alias col groff man

Place the line above in your ~/.bahsrc file. Now every time you issue the 'vb' command, you invoke the vim editor to edit it, then source it so the changes take effect immediately.


* This mechanism is not working well if your .bashrc contains commands that should not be sourced more than once.

* This trick also work for your csh or tclsh users: place the following line in your ~/.cshrc file:

alias vc 'vim ~/.cshrc; source ~/.cshrc

Thank you adzap for pointing out the missing quote

:n,m w newfile.txt
2009-03-02 19:40:34
User: milmazz
Tags: vim perl

On command mode in Vim you can save parts of the current buffer in another file.

* The 'n' value represents the first line of the new file.

* The 'm' value represents the last line of the new file.

* newfile.txt is the newfile.

The results are similar to this command in perl:

perl -ne 'print if n..m' in.sql > out.sql
2009-03-02 19:03:07
User: Pistos

Immediately after installing things into your PATH (e.g. under /usr/bin), currently open shells cannot find them ("zsh: command not found"). Use rehash to get the shell to rescan available executables.

sudo find / -type f \( -perm /4000 -a -user root \) -ls -o \( -perm /2000 -a -group root \) -ls
2009-03-02 18:48:17
User: atoponce
Functions: find sudo

Discovering all executables on your system that can be run as another user, especially root, is critical for system security. The above command will find those files with have SUID or SGID bits set and are owned by the root user or group.

du -cs * .[^\.]* | sort -n
2009-03-02 18:43:48
User: cemsbr
Functions: du sort

Very useful when you need disk space. It calculates the disk usage of all files and dirs (descending them) located at the current directory (including hidden ones). Then sort puts them in order.

cat /dev/zero > /dev/null &
2009-03-02 18:18:52
User: gustavold
Functions: cat

Just waste some resources in a philosophical way