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,181 results
(crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
2009-09-30 18:13:38
User: syssyphus
Functions: crontab dmesg echo

this is helpful because dmesg is where i/o errors, etc are logged to... you will also be able to see when the system reboots or someone attaches a thumb drive, etc.

don't forget to set yourself up in /etc/aliases to get roots email.

clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq 0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;}
2009-09-30 16:43:08
User: suhasgupta
Functions: c++ wget

Usage: clfavs username password num_favourite_commands file_in_which_to_backup

echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
avimerge -o output.avi -i file1.avi file2.avi file3.avi
strings /boot/kernel-file | grep 2.6
2009-09-30 06:21:40
Functions: grep strings

recently some in the #linux shared this. to find out the kernel version name from the binary without using uname

tune2fs -j /dev/sdX
kill -9 <replace this with pid you want to kill>
trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG
2009-09-29 21:09:21
User: Vereb
Functions: trap
Tags: trap

You can set the previous bash command as the terminal title by this command.


-trap assigns a command to execute at a given bash signal.

-in the $BASH_COMMAND you find the last command

-you can set the terminal title with the escape sequence: \e]0;this is the title\007

-to let the echo care about the backslashes give the -e to it

Since trap is a built in bash command you find more informatin in 'man bash'for more

Source: http://www.davidpashley.com/articles/xterm-titles-with-bash.html

check the sample output below, the command was too long :(
2009-09-29 19:30:10
User: pykler
Functions: command
Tags: color

Same as the cool matrix style command ( http://www.commandlinefu.com/commands/view/3652/matrix-style ), except replacing the printed character with randomness. The command mentioned is much faster and thus more true to the matrix. However, mine can be optimized, but I wasted ... i mean spent enough time on it already

host <domain> <nameserver name>
2009-09-29 18:58:28
User: DoGik
Functions: host

Its very useful when you do not have control over name servers and need to check DNS configuration directly, right after change. You will not need to wait for DNS propagation to verify if all records were configured properly by vendors of name servers.

rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
2009-09-29 16:39:57
User: Karakh
Functions: rename

Replace 'SHOWNAME' with the name of the TV show.

Add -n to test the command without renaming files.

Check the 'sample output'.

ls -A
ls .??*
2009-09-29 14:40:37
User: Paula
Functions: ls

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

ls .[!.]*
2009-09-29 13:50:13
User: danam
Functions: ls

Although rm is protected against it, there are many commands that would wreak havoc on entering the obvious ".*" to address "dot-files". This sweet little expression excludes the dirs "." and ".." that cause the problems.

s=124890; array=($(echo $s | sed 's/./& /g')); echo ${array[@]}; echo ${!array[@]}
2009-09-29 12:30:04
User: tatsu
Functions: echo sed

Convert string to array using echo and sed =)

[ `date --date='next day' +'%B'` == `date +'%B'` ] || echo 'end of month'
s="124890";for i in $(seq 0 1 $((${#s}-1))); do arr[$i]=${s:$i:1}; done
# for i in $(seq 1 25); do dd if=/dev/urandom of=<your disk> bs=1M ; done
2009-09-29 07:12:34
User: danam
Functions: dd seq
Tags: dangerous

Intentional hash in the beginning. May run a looong time. Wipes your data for real. Was meant to be /dev/urandom - I mistyped it. :-)

dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient
2009-09-28 22:07:31
User: syssyphus
Functions: hostname rm sed
Tags: privacy

this string of commands will release your dhcp address, change your mac address, generate a new random hostname and then get a new dhcp lease.

command -geometry 120x30+1280+0
2009-09-28 20:01:32
User: random_bob
Functions: command
Tags: geometry

open an application to wherever you like on your current display. the first set of #'s (120x30) denotes size of window opened in, and the second set (+1280+0) identifies the location. Either set can be used alone, or with the other. Also, opening gnome-terminal with this option requires it to be "--geometry" for some reason.

PERMA () { echo "$@" >> ~/.bashrc; }
2009-09-28 16:03:24
User: zlemini
Functions: echo

Simple function to permanently add an alias to your profile.

Tested on bash and Ksh, bash version above.

Here is the ksh version: PERMA () { print "$@" >> ~/.profile; }

Sample usage:

PERMA alias la='ls -a'

dig -x
2009-09-28 15:13:34
User: postrational
Functions: dig

Performs a reverse DNS lookup, variants include:



su -- user
2009-09-28 04:23:43
User: matthewdavis
Functions: su
Tags: bash root su

I've used this a number of times troubleshooting user permissions. Instead of just 'su - user' you can throw another hyphen and stay in the original directory.

gitstart () { if ! [[ -d "$@" ]]; then mkdir -p "$@" && cd "$@" && git init; else cd "$@" && git init; fi }