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,620 results
detox -r -s utf_8 /path/to/old/win/files/dir
2009-03-16 07:50:36
User: renich
Tags: ut
16

This command is a powerful "detoxifier" that eliminates special chars, spaces and all those little chars we don't like. It support several "sequences" so be sure to check your /usr/local/etc/detoxrc while at it... and maybe define your own

cat count.txt | awk '{ sum+=$1} END {print sum}'
2009-03-16 00:22:13
User: duxklr
Functions: awk cat
Tags: awk
16

Takes a input file (count.txt) that looks like:

1

2

3

4

5

It will add/sum the first column of numbers.

less textfile.gz
2009-03-15 23:51:17
User: allbad
Functions: less
-4

There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.

openssl pkcs12 -export -in /dir/CERTIFICATE.pem -inkey /dir/KEY.pem -certfile /dir/CA-cert.pem -name "certName" -out /dir/certName.p12
less file.tar.gz
2009-03-15 23:00:05
User: allbad
Functions: less
-1

This will print out the files and directories in a gzipped tarball.

rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
2009-03-15 22:18:17
User: mpb
Functions: head nl rpm sort
2

Low on disk space? Check the largest installed RPMs for delete canditates.

ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
2009-03-15 18:42:43
User: mpb
Functions: awk grep ls rename sh
2

This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.

echo "encryptedpassword"|openssl passwd -1 -stdin
for name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done
2009-03-15 12:02:39
User: atoponce
Functions: chage echo passwd useradd
6

This command is a bit Linux specific, as --stdin doesn't exist for passwd on many Unix machines. Further, useradd is high level in most distributions and Unix derivatives except for the Debian family of distros, where adduser would be more appropriate. The last bit, with chage, will force the user to change their password on new login.

gcal -K -q GB_EN 2009 # display holidays in UK/England for 2009 (with week numbers)
2009-03-15 10:19:52
User: mpb
5

NB when you run this gcal command in your shell, holidays are highlighted

but this highlighting does not show in the sample output (above).

To find full details on gcal options: gcal --long-help | less

Example for United States, Pennsylvania:

gcal -K -q US_PA 2009 # display holidays in USA/Pennsylvania for 2009 (with week numbers)

Example for Hong Kong:

gcal -K -q HK 2009 # display holidays in Hong Kong for 2009 (with week numbers)

sort file1.txt | uniq > file2.txt
visudo
2009-03-14 03:39:32
User: atoponce
1

'visudo' is installed by default on most Unix-like systems. If not installed, you can get it from the 'sudo' package. 'visudo' will use the text editor found in your $EDITOR variable, whether it's vi, vim, emacs, nano or gedit. After making changes to the /etc/sudoers file, visudo will check for syntax errors, and notify you of them. This is better than 'vi /etc/sudoers', because of this capability. Rule #1 of system administration- if there is a tool that exists for editing config files, use the tool.

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf `ls *.pdf`
2009-03-13 22:34:14
User: oops66
Functions: gs
12

Merge all pdf files in the directory into one pdf file (the out.pdf file)

ls -l|awk '{print $6,$8}'|sort -d
2009-03-13 19:00:18
User: archlich
Functions: awk ls sort
-4

Can pipe to tail or change the awk for for file size, groups, users, etc.

lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
2009-03-13 13:17:53
User: garylittle
Functions: sleep
2

Lockstat will sample the kernel 977 times per second, and print out the functions that it sees executing on the CPU during the sample. The -s 10 switch tells lockstsat to not only print that function, but also show the call stack (up to 10 deep).

find ~/project -mtime -1 -type f -print | tar jcvf myfiles.tar.bz2 -T -
2009-03-13 13:03:11
User: voyeg3r
Functions: find tar
0

create tar.bz2 package from files "-type f" modificated today "-mtime -1" in ~/project

rsync -avz -e ssh --files-from=<(find -mtime +30 -mtime -60) source dest
2009-03-13 12:58:28
User: voyeg3r
Functions: find rsync ssh
6

rsync from source to dest all between >30

for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && echo "bye, bye" && shutdown -h now
2009-03-13 12:16:35
User: arctarus
Functions: bc echo seq shutdown sleep
-14

command to turn off your computer when you go home and can not wait

ls /home/user | xargs ls -lhR | less
over myscript.sh
2009-03-13 06:13:21
User: haivu
-2

over works like 'more' or 'less', but it pretty print the source code

leave +15
2009-03-13 06:09:52
User: haivu
Tags: PIM
30

If you spend most of your time in front of the terminal, leave is a useful reminder. Leave can have absolute form: leave 1555 reminds you to leave at 3:55PM

ls -A
2009-03-13 05:12:01
User: haivu
Functions: ls
Tags: terminal
0

This command is almost the same as 'ls -a', but it does not display the current dir (.) or parent (..)

find . -name "*.pdf" -print0 | xargs -0 cp -t downloads/
2009-03-13 03:15:27
User: abcde
Functions: cp find xargs
1

-t, --target-directory=DIRECTORY (copy all SOURCE arguments into DIRECTORY).

bash -x SCRIPT
2009-03-13 00:09:07
User: jcalvert
Functions: bash
3

Display commands and their arguments as they are executed. Useful for debugging shell scripts.

lsof | egrep "^COMMAND|deleted"
2009-03-12 23:11:26
User: jyoder
Functions: egrep
2

If your customer deletes a file that is still in use by a process, that space does not get freed up (will not show up in df) until that process either closes the file on its own, or is killed.