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.


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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,353 results
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
fuser -kiu / name
2012-08-28 09:48:48
User: jv2112
Functions: fuser
0

kill processes by user . Remove "i" if you don't want to confirm.

complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh /\"/' | sed 's/$/\"/'))" ssh
2012-11-02 15:14:15
User: bojan
0

Type the command. Then just use ssh command with tab to see all your ssh sessions.

You can also put it in your profile.

Thank you Nedzad !

for i in *.flac; do gst-launch filesrc location="$i" ! flacdec ! audioconvert ! lamemp3enc target=quality quality=2 ! id3v2mux ! filesink location="${i%.flac}.mp3"; done
xset dpms force off
awk 'NR%3==1{x="F"++i;}{print > x}' file3
/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk '{print $12 $14}' | sort | uniq -c | sort -rn | head
2014-03-12 13:24:40
User: copocaneta
Functions: awk grep sort uniq
0

List the busiest scripts/files running on a cPanel server with domain showing (column $12).

du -ch `cat test_file.txt`
2014-06-26 08:59:05
User: mase
Functions: du
0

in test_file.txt:

/var/img/1/368/ID_2012MTH03DT15.zip

/var/img/1/368/ID_2012MTH03DT16.zip

/var/img/1/368/ID_2012MTH03DT16N.zip

/var/img/1/368/ID_2012MTH03DT16E.zip

/var/img/1/368/ID_2012MTH03DT17M.zip

/var/img/1/368/ID_2012MTH03DT17N.zip

/var/img/1/368/ID_2012MTH03DT17E.zip

/var/img/1/368/ID_2012MTH03DT18M.zip

/var/img/1/368/ID_2012MTH03DT18N.zip

/var/img/1/368/ID_2012MTH03DT19M.zip

/var/img/1/368/ID_2012MTH03DT19N.zip

/var/img/1/368/ID_2012MTH03DT19E.zip

/var/img/1/368/ID_2012MTH03DT20M.zip

/var/img/1/368/ID_2012MTH03DT20N.zip

/var/img/1/368/ID_2012MTH03DT20E.zip

/var/img/1/368/ID_2012MTH03DT21M.zip

dumpe2fs -h /dev/xvda1 | egrep -i 'mount count|check'
2014-10-22 08:38:43
User: manju712
Functions: dumpe2fs egrep
0

To check the total number of mounts, maximum number of mounts before performing the fsck and last time when the fsck was performed.

find <mydir> -type f -exec rename 's/<string1>/<string2>/g' {} \;
2015-11-19 17:51:13
User: thrifus
Functions: find rename
Tags: find replace
0

This version works on OS X (if you have installed `rename`)

hpacucli controller all show config detail | grep -A 7 Fail | egrep '(Failed|Last|Serial Number|physicaldrive)'
2016-07-20 17:42:40
User: operat0r
Functions: egrep grep
0

This dumps serial numbers of all the drives but HP warranty check does not say they are valid ...

dos2unix dostxt unixtxt
2009-02-05 21:11:43
User: wwest4
0

converts non-ISO dos text files for use on unix systems.

echo "Decode this"| tr [a-zA-Z] $(echo {a..z} {A..Z}|grep -o .|sort -R|tr -d "\n ")
for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done