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

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,162 results
diff a.txt b.txt | grep -E '^(<|>)' | sed 's:^< \(.*\):<del style="color\:red; text-decoration\: none">- \1</del><br>:' | sed 's:^> \(.*\):<ins style="color\:green; text-decoration\: none">+ \1</ins><br>:'
ps -auxf | sort -nr -k 4 | head -10
pm2 install pm2-webshell
2015-06-11 12:43:49
User: strzel_a
Functions: install
-10

pm2 is a process manager that includes a module system to install powerful and small softwares

tree -a -L 1 --inodes /
tail -f <file>
2015-06-01 16:55:00
User: adrruiz
Functions: tail
-12

In cases when the user is following a log file that rotates then it is advisable to use the -F option as it keeps following the log even when it is recreated, renamed, or removed as part of log rotation.

To interrupt tail while it is monitoring, break-in with Ctrl+C.

less +F <file>
find <path> |xargs grep <pattern>
cat <file>|column -t
awk '{for(i=2;i<=NF;i++) printf("%s%s",$i,(i!=NF)?OFS:ORS)}'
awk '{ $1="";print}'
xxd -p source | fold -w2 | paste -sd' ' | sed "s/A/B/g" | xxd -p -r > destination
2015-05-26 18:29:48
User: hincor
Functions: fold paste sed
Tags: sed xxd fold paste
2

Replace all instances of "A" with "B" in file "source" saved as file "destination".

!! IF A/B is multi-byte, then separate bytes with spaces like so: "s/20\ 0A/00/g".

aplay -c 2 -f S16_LE -r 44100 /dev/urandom
ls -lt --time=atime *.txt
2015-05-21 21:03:44
User: miccaman
Functions: ls
Tags: ls
0

list all txt files order by time, newest first

for f in `ls`; do sed -i '/MATCHING STRING/ { s/ORIGINAL/REPLACEMENT/; }' ${f} ; done
2015-05-21 19:37:42
User: krizzo
Functions: sed
-1

Find and replace specific characters in a single line in multiple files with sed.

for x in {a..d}; do echo -e "n\np\n\n\n\nt\n8e\nw\n" | fdisk /dev/sd"$x"; done
2015-05-21 12:59:48
User: jaimerosario
Functions: echo fdisk
Tags: fdisk for loop
1

So, I'm using a CentOS VM in VirtualBox, and created four new disks in the SCSI controller.

The VM created the folders:

/dev/sda

/dev/sdb

/dev/sdc

/dev/sdd

Using a 'for loop' all disks are partitioned for LVM.

sudo docker rm $(docker ps -a -q); sudo docker rmi $(docker images -q)
2015-05-20 12:34:40
User: lpalgarvio
Functions: ps rm sudo
2

# Delete all containers

docker rm $(docker ps -a -q)

# Delete all images

docker rmi $(docker images -q)

avconv -i FILE.mp4" -f dvd -c:v:0 mpeg2video -s 720x576 -r 25 -g 15 -b:v:0 8000000 -maxrate:v:0 8000000 -minrate:v:0 8000000 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -b:a 192000 -ar 48000 -c:a:0 ac3 -map 0:v -map 0:a FILE.mpeg
2015-05-20 09:55:48
User: alikhalil
0

The command will use avconv to convert any video file in to MPEG2 format which will be added to a DVD project.

for p in $(pgrep -t $(cat /sys/class/tty/tty0/active)); do d=$(awk -v RS='\0' -F= '$1=="DISPLAY" {print $2}' /proc/$p/environ 2>/dev/null); [[ -n $d ]] && break; done; echo $d
2015-05-18 20:01:20
User: geyslan
Functions: awk cat echo
Tags: display xorg
1

It's useful when you cannot access your env (systemd) or the process DISPLAY variable is not set. Perhaps also when you have a multi-head/user configuration.

find /dev/disk/by-id -type l -printf "%l\t%f\n" | cut -b7- | sort
ls -l /dev/disk/by-id |gawk 'match($11, /[a-z]{3}$/) && match($9, /^ata-/) { gsub("../", ""); print $11,"\t",$9 }' |sort
2015-05-18 15:42:33
User: lig0n
Functions: gawk ls
Tags: zfs disk info
2

Scrap everything and use `gawk` to do all the magic, since it's like the future or something.

gawk 'match($11, /[a-z]{3}$/) && match($9, /^ata-/) { gsub("../", ""); print $11,"\t",$9 }'

Yank out only ata- lines that have a drive letter (ignore lines with partitions). Then strip ../../ and print the output.

Yay awk. Be sure to see the alternatives as my initial command is listed there. This one is a revision of the original.

find . -name '._*' -type f -delete
2015-05-16 18:12:50
User: MarcLaf
Functions: find
Tags: mac os x
2

Searches from present dir forward and removes all Mac generated . (dot) files.

tar c folderName | md5
grep MemTotal: /proc/meminfo # display how much memory installed
2015-05-15 09:19:02
User: mpb
Functions: grep
0

This will display the system memory size in kb. If you want to see the value in mb, you can type:

grep MemTotal: /proc/meminfo | awk '{printf("MemTotal: %d MB\n",$2/1024)}'

showip() { nmcli connection show $1|grep ipv4.addresses|awk '{print $2}' ; }
2015-05-13 16:24:28
User: nnsense
Functions: awk grep
1

Sometimes it's useful to output just the ip address. Or some other information, changing the "ipv4.addresses" in command. The power of awk! Show all possible "greps" with

nmcli connection show [yourInterfaceNameHere]
grep page.php /var/log/httpd/access_log|awk '{print $1}'|sort|uniq|perl -e 'while (<STDIN>){chomp; $cmd=`ipset add banned -! -q $_`; }'