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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,333 results
ls /EMRCV5/
rsync --recursive --info=progress2 <src> <dst>
2014-10-21 22:19:44
User: koter84
Functions: rsync
Tags: rsync progress
0

update the output of rsync after completing a file but don't create newlines, just overwrite the last line, this looks a lot better in scripts where you do want to see a progress-indicator, but not the lengthy logs

this option is available since rsync 3.1.0

using 3 thread to download some big file
touch -acm yyyymmddhhMM.ss [file]
2009-02-05 21:07:09
User: wwest4
Functions: touch
0

...changes modify time and access time. also:

touch -r [file1] [file2] # make file2 timestamp match file1

man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg'
2009-06-25 23:51:35
Functions: fetchmail man perl
0

Using perl, here, we grep the man page of fetchmail to find the paragraph starting with '-k | --keep' and ending before the paragraph starting with '-K | --nokeep'

awk '{print substr($0, index($0,$N))}'
2009-08-31 19:47:10
User: mstoecker
Functions: awk
0

This command will print all fields from the given input to the end of each line, starting with the Nth field.

texmacs --delete-font-cache
2010-03-14 13:30:54
User: eastwind
0

after installing new fonts ( tfm , pfb , cjk , truetype ... ) manually in your ~/.Texmacs/fonts , it doesn't always reload it properly , just refresh it by delete the old cache fonts

in sample output , I just installed TrueType Chinese CJK fireflysung fonts supports

du -hs /path/to/target
bind '"\C-h": "\`fc\ \-s\`"'
2010-08-16 17:58:16
User: rthemocap
0

This is similar to using `!!` or

In bash 4.1 it seems you can bind directly to a shell command, but I'm not running that version.

sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
2011-03-20 20:33:35
User: ibnarrashid
Functions: sudo
0

Requires 'reflector' package from official repository. '5' in the example is the number of mirrors you want in the mirrorlist, could be other numbers of course.

seq 1 1000000 | while read i; do echo -en "\r$i"; done
SUBNET="192.168.41" ; diff -y <(nmap -sP -n ${SUBNET}.0/24 | grep ${SUBNET}. | awk '{print $5}' | sort -t"." -k4 -n) <(for i in $(seq 1 254); do echo ${SUBNET}.$i; done)
2012-08-28 09:11:18
User: michel_p
Functions: awk diff echo grep seq sort
0

The command will make it easy to determine free IP ranges in a crowded sub-net.

machinfo | grep -i memory
2013-03-07 16:22:49
User: giorger
Functions: grep
0

Get the amount of physical memory in an HP-UX v11 OS when following are NOT available:

- root account

- no privileges in /proc

- no privileges in /dev/mem

for i in `pidof java`; do echo $i; ll /proc/$i; done;
2013-04-26 08:01:21
User: cuizhaohua
Functions: echo
0

list all java process info.

FOR /F "delims==" %%A IN ('type ips.txt') DO wmic /Node:%%A wmic /user:username /password:yourpassword /FAILFAST:ON process where "name like '%.exe'" call getowner
2014-06-26 01:53:29
User: operat0r
Tags: wmic hacking
0

This is used during pentest to quickly poll all the processes running on a set of systems you have common credentials for the /FAILFAST:ON speeds up the scans.

wait 536; anywait 536; anywaitd 537; anywaitp 5562 5563 5564
2014-10-22 06:31:47
User: colemar
Functions: wait
0

Silent:

anywait () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; done; done }

Prints dots:

anywaitd () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; echo -n '.'; done; done }

Prints process ids:

anywaitp () { for pid in "$@"; do while kill -0 "$pid" >/dev/null 2>&1; do sleep 0.5; echo -n $pid' '; done; echo; done }

You cannot anywait for other users processes.

mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e "use psa; select accounts.password from accounts INNER JOIN sys_users ON accounts.id=sys_users.account_id WHERE sys_users.login='xxxx';"
2009-02-18 17:26:41
User: darkon1365
0

This will print to the screen password for the user specified in "sys_users.login='xxxx';. This is for Plesk servers only.

mksnap_ffs /var /var/.snap/snap_var_`date "+%Y-%m-%d"` ; mdconfig -a -t vnode -f /var/.snap/snap_var_`date "+%Y-%m-%d"` -u 1; mount -r /dev/md1 /mnt
2010-09-18 11:37:03
User: bugmenot
Functions: mount
0

(FreeBSD)

Once you've made the snapshot you can resume any stopped services and then back up the file system (using the snapshot) without having to worry about changed files.

When finished, the snapshot can be removed :

umount /mnt

mdconfig -d -u 1

rm /var/.snap/snap_var_`date "+%Y-%m-%d"`

println() {echo -n -e "\e[038;05;${2:-255}m";printf "%$(tput cols)s"|sed "s/ /${1:-=}/g"}
2011-01-09 18:08:18
User: joedhon
Functions: printf sed
Tags: sed tput printf
0

function for .bash_aliases that prints a line of the character of your choice in the color of your choice across the terminal.

Default character is "=", default color is white.

pacman -Ql gvim
2011-03-20 20:39:07
User: ibnarrashid
0

Shows the files which the package, for example gvim, installed on your system.

getent passwd $(whoami) | echo "$(perl -ne '/^([^:]+):[^:]+:[^:]+:[^:]+:([^ ]+) ?([^,]+)?,([^,]*),([^,]*),([^:,]*),?([^:,]*)/ and printf "MECARD:N:$3,$2;ADR:$5;TEL:$4;TEL:$6;EMAIL:$1@"')$HOSTNAME;;" | qrencode -o myqr.png
2011-07-25 12:59:57
User: Strawp
Functions: echo getent passwd
Tags: perl qr qrencode
0

If your contact information was entered when your user account was created (it gets added to /etc/passwd) then this gets that info and creates a QR code for you automatically

echo $(cat /usr/share/dict/words |grep -v "'"|shuf -n4)
2011-08-31 12:48:14
User: d1v3rdown
Functions: cat echo grep
Tags: cat echo grep shuf
0

Fast and excludes words with apostrophes. For ubuntu, you can use wamerican or wbritish dictionaries, installable through aptitude.

cut -d: -f1 /etc/passwd | sort
for w in $(tr 'A-Z ,."()?!;:' 'a-z\n' < sample.txt); do echo ${#w} $w; done | sort -u | sort -n
2012-03-15 14:14:11
User: flatcap
Functions: echo sort tr
Tags: bash sort tr
0

Take a file and ,."()?!;: give a list of all the words in order of increasing length.

First of all use tr to map all alphabetic characters to lower case and also strip out any puntuation.

A-Z become a-z

,."()?!;: all become \n (newline)

I've ignored - (hyphen) and ' (apostrophe) because they occur in words.

Next use bash to print the length ${#w} and the word

Finally sort the list numerically (sort -n) and remove any duplicates (sort -u).

Note: sort -nu performs strangely on this list. It outputs one word per length.

curl ip.tyk.nu