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,951 results
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.

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
pacman -Qo /etc/yaourtrc
cat file.csv | perl -pe 'if($. == 1) {@h = split(/;/); $i = 1 ; map { $_ = $i; $i++ } @h; print join(" ;", @h) , "\n"} ; s/(^|;);/$1 ;/g' | column -ts\; | less -S
lynx -dump ip.nu
update-alternatives --config x-www-browser
2012-07-08 20:27:42
User: gwd
0

also use: update-alternatives --config gnome-www-browser

find . -type f | xargs -I% bash -c 'echo -e "\033[31m%\033[0m" && [[ ! `file %` =~ .*binary.* ]] && head "%"'
rpm -qa --queryformat '%{SIZE}\n' | awk '{sum += $1} END {printf("Total size in packages = %4.1f GB\n", sum/1024**3)}'
2013-12-14 20:22:41
User: skytux
Functions: awk rpm
0

It is not the installed size in files, but the size of RPM packages.

aws ec2 describe-instances --query "Reservations[*].Instances[*]" | jq '.[]|.[]|(if .Tags then (.Tags[]|select(.Key == "Name").Value) else empty end)+", " +.InstanceId'
2014-06-26 20:01:12
User: thatinstant
Tags: aws EC2 jq
0

Uses the python-based AWS CLI (https://aws.amazon.com/cli/) and the JSON query tool, JQ (https://stedolan.github.io/jq/)

dmesg
2014-10-22 10:03:56
User: sagarsakre
Functions: dmesg
0

The dmesg will show the kernel it is booting. No more dependency on files

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

svcadm disable gdm
2009-07-25 02:32:46
Functions: disable
0

On Solaris 10 you used dtconfig -d to achieve this. The command will disable X and your system will now boot to a text console.