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 - 12,022 results
echo "some cool message from terminal" | mail -s "test" email@address.com
unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset
0

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

eject -T [cdrom_device]
2009-02-25 23:53:03
User: raphink
Functions: eject
Tags: device
0

Opens or closes the cdrom device.

echo 254.003.032.3 | grep -P '^((25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])\.){3}(25[0-4]|2[0-4]\d|[01]?[\d]?[1-9])$'
2009-09-17 12:59:44
User: foob4r
Functions: echo grep
0

This obey that you don't match any broadcast or network addresses and stay between 1.1.1.1 - 254.254.254.254

cat /proc/version
openssl rand 6 -base64
2011-10-05 14:24:41
User: Le_Jax
0

just change 6 to 9 or 12 or more (multiple of 3) to have bigger password

/usr/bin/snmpwalk -v 1 -c public 10.0.0.22 1.3.6.1.4.1.789.1.21.1.2.1.25.1| awk -F : '{print "netapp temp:" $4 }'
2011-11-10 01:04:00
User: ndhail
Functions: awk
Tags: awk snmp netapp
0

if you can use this depends on which netapp you have, this netapp is an FAS2020

sed -i 6,66d <filename>
2012-02-04 02:29:40
User: icsamples
Functions: sed
Tags: bash sed
0

Delete range of lines. Ex: Line 6 through 66 in .

du -s $(ls -l | grep '^d' | awk '{print $9}') | sort -nr
tar zcpvf backup.tgz $(find $HOME -maxdepth 1 -name '.*' -and -not -name '.')
2012-05-01 17:48:24
User: DavidAlfonso
Functions: find tar
Tags: backup
0

This will make a backup of all hidden files and folders in the home folder.

hashkey=`echo -ne <your-secret> | xxd -p`; openssl rc4 -e -nosalt -nopad -K $hashkey -in myfile.txt -out myfile.enc.txt
2012-10-31 12:17:44
User: vishnu81
Tags: openssl rc4
0

At times you will need to safeguard your files. Use OpenSSL's native rc4 encryption to do so.

'nopad' removes padding and 'nosalt' removes random salt being added to the file.

for i in `ls` ; do cd $i ; pwd; for f in `ls *.rar` ; do unrar e $f ; done ; cd .. ; done
2013-03-06 19:23:58
User: Avelinux
Functions: cd
0

In order to unrar several files in different subfolders, you just need to launch this command in your parent folder in order to have your files ready for manipulation and already extracted;

I did not put anything to delete the original rar files

mplayer -dumpstream -dumpfile stream_video_name url
2013-12-13 18:28:16
User: pascalfares
0

1. Copy the url of the streaming video mms://etc... or http://...

2. Open up a terminal.

3. the command

4. Wait for the stream dump.

composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png
2009-02-15 19:53:45
User: jimmac
Functions: sed
0

Use graphicsmagick or imagemagick to composite a RGBA image over a flat white background and discard the alpha channel.

egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
2009-08-14 07:31:00
User: peshay
Functions: awk egrep
0

You can use that to create a excludefile for nmap, to find hosts, with no DHCP lease in your DHCP range.

blockdev --getsize64 /dev/sd[ab]
2011-01-08 11:25:54
User: bbelt16ag
Tags: blockdev
0

Compare the disk space for the new and old drive

FILE=$(tempfile 2>/dev/null || echo .$RANDOM)
2011-08-31 10:39:11
User: s123iva
Functions: echo
Tags: dash notify
0

enter our information on the content file.

cat table-mv.txt | perl -pe 's{([^;]+);([^;]+)}{tbl$1/tbl$2}' | perl -pe 's{(\S+)}{perl -i -pe #s/$1/g# xxx.sql}' | tr "#" "\'" | bash
2011-10-05 15:55:34
User: hute37
Functions: cat perl tr
0

with a semicolon text file map, apply multiple replace to a single file

sudo echo "package url" >> /etc/apt/sources.list
2012-05-01 21:32:51
User: Gunni
Functions: echo sudo
0

">>" appends to the file

">" replaces the entire file

make sure to use ">>"

cat item_list | xargs -n1 -P<n> process_item
find . -name ".DS_Store" -print0 | xargs -0 rm -rf
tar --exclude-from=$excludefile -zcvp "$source" | openssl aes-128-cbc -salt -out $targetfile -k $key
2013-12-13 19:35:20
User: klausman
Functions: tar
0

Create compressed, encrypted backup from $source to $targetfile with password $key and exclude-file $excludefile

/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk '{print $12}' | sort | uniq -c | sort -rn | head
2014-03-12 12:31:34
User: copocaneta
Functions: awk grep sort uniq
0

Easiest way to obtain the busiest website list (sorted by number of process running).

ssh -D 8080 -f -N srv1
2014-06-25 12:46:44
User: fr00tyl00p
Functions: ssh
0

Provides a SOCKS5 proxy on localhost port 8080 which will tunnel all connections through srv1 and run in the background.

<command> | curl -F 'clbin=<-' https://clbin.com
2014-10-21 13:02:18
User: colemar
0

Define alias for convenience:

alias clbin='curl -v -F "clbin=<-" https://clbin.com'

Paste man page:

man bash | clbin

Paste image:

curl -F 'clbin=@filename.jpg' https://clbin.com