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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



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!

Top Tags



Commands using awk from sorted by
Terminal - Commands using awk - 1,216 results
dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge
phpunit --log-json php://stdout | awk '$NF ~ '/,/' && $1 ~ /"(test|time)"/' | cut -d: -f2- | sed "N;s/\n/--/" | sed "s/,//"| awk 'BEGIN{FS="--"}; {print $2 $1}' | sort -r | head -n 5
diff <(cat /etc/fstab | grep vol | grep -v "^#" | awk '{print $1}') <(df -h | grep vol)
2014-01-23 15:18:08
User: Koobiac
Functions: awk cat df diff grep
Tags: diff fstab df

With this command, you can check the difference between the volumes mounted and the volume in /etc/fstab.

while [ 1 ] ;do ps aux|awk '{if ($8 ~ "D") print }'; sleep 1 ;done
nvidia-settings -q gpucoretemp -t | awk '{s+=$1}END{print s/NR}' RS=" "
find . -name "pattern" -type f -printf "%s\n" | awk '{total += $1} END {print total}'
2014-01-16 01:16:18
User: pdxdoughnut
Functions: awk find

Using find's internal stat to get the file size is about 50 times faster than using -exec stat.

find . -name "pattern" -exec stat -c%s {} \; | awk '{total += $1} END {print total}'
2014-01-15 11:07:09
User: Koobiac
Functions: awk find stat

Find files and calculate size with stat of result in shell

CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}
2013-12-30 07:47:41
User: lowjax
Functions: awk echo return sed

Pass the files path to finfo(), can be unix path, dos path, relative or absolute. The file is converted into an absolute nix path, then checked to see if it is in-fact a regular/existing file. Then converted into an absolute windows path and sent to "wmic". Then magic, you have windows file details right in the terminal. Uses: cygwin, cygpath, sed, and awk. Needs Windows WMI "wmic.exe" to be operational. The output is corrected for easy...

finfo notepad.exe finfo "C:\windows\system32\notepad.exe" finfo /cygdrive/c/Windows/System32/notepad.exe finfo "/cygdrive/c/Program Files/notepad.exe" finfo ../notepad.exe
curl -s -k https://www.kernel.org/feeds/kdist.xml | sed -n -e 's@.*<guid>\(.*\)</guid>.*@\[email protected]' | grep 'stable' | head -1 | awk -F , '{print $3}'
2013-12-17 23:59:27
User: Wafelijzer
Functions: awk grep head sed
Tags: kernel

Fetches latest stable release version from first entry between tags

netstat -np --inet|awk '/firefox/{split($5,a,":");z[a[1]]++} END{for(i in z){system("whois " i)}}'|less
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

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

awk 'NR%3==1{x="F"++i;}{print > x}' file3
convert image.jpg -resize 1x1 txt: | tail -1 | awk '{gsub(/[,\)]/," "); print $3+$4+$5}'
2013-12-11 09:13:00
User: sucotronic
Functions: awk tail

You can get the mean value for the colours in an image. Then you can determine, in general, how dark or bright is the image and run some other actions based on that. I'll recommend to readjust the brightness of the images using +sigmoidal-contrast option of imagemagick convert command.

xdpyinfo | grep dimensions | awk '{print $2}'
xrandr | grep \* | awk '{print $1}'
mv /etc/fstab /etc/fstab.old && mount | awk '{print $1, $3, $5, $6}'| sed s/\(//g|sed s/\)/' 0 0'/g >> /etc/fstab
ls -al | awk '/^-rwx/ {print $9}'
for line in `ps aux | grep <string> | awk '{print $2}'`; do sudo kill $line; done;
2013-11-24 00:02:16
User: mjbrune
Functions: awk grep kill sudo

Kills all processes with a certain string. This was done to kill all ssh sessions openned by zenoss which look like: usr/bin/ssh /opt/zenoss/bin/zenmodeler

export KEEP_KERNEL=2; dpkg -l 'linux-image*' | awk '/^ii/ { print $2 }' | grep "[0-9]" | awk 'BEGIN{i=1}{print i++, $0}' | grep `uname -r` -B99 | sort -r | tail -n+$(($KEEP_KERNEL+2)) | awk '{print $2}'| xargs apt-get -y purge
dpkg -l | grep ^ri | awk '{print $2 " install"}' | sudo dpkg --set-selections
2013-11-23 06:41:18
User: ajmccluskey
Functions: awk grep sudo

If you run dpkg --clear-selections or have otherwise selected installed packages for deinstall, but want to undo it, run this. It will set all installed packages back to installed status so that they won't be removed by commands like "dpkg -Pa"

wget "us.download.nvidia.com$(wget -qO- "$(wget -qO- "nvidia.com/Download/processFind.aspx?psid=95&pfid=695&osid=19&lid=1&lang=en-us"|awk '/driverResults.aspx/ {print $4}'|cut -d "'" -f2|head -n 1)"|awk '/url=/ {print $2}'|cut -d '=' -f3|cut -d '&' -f1)"
2013-11-21 03:04:59
User: lowjax
Functions: awk cut head wget

Download latest NVIDIA Geforce x64 Windows7-8 driver from Nvidia's website. Pulls the latest download version (which includes beta). This is the "English" version. The following command includes a 'sed' line to replace "english" with "international" if needed. You can also replace the starting subdomain with "eu." "uk." and others. Enjoy this one liner! 1 character under the max :)

wget "us.download.nvidia.com$(wget -qO- "$(wget -qO- "nvidia.com/Download/processFind.aspx?psid=95&pfid=695&osid=19&lid=1&lang=en-us" | awk '/driverResults.aspx/ {print $4}' | cut -d "'" -f2 | head -n 1)" | awk '/url=/ {print $2}' | sed -e "s/english/international/" | cut -d '=' -f3 | cut -d '&' -f1)"
ps -u marcanuy -o pid,rss,command | awk '{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}'
2013-11-20 01:21:59
User: marcanuy
Functions: awk ps

Add up the amount of memory your processes are using and display the total. Replace marcanuy with your desired username.

grep -l --include '*.rb' --include '*.rake' '^[^#]*[^a-zA-Z0-9[:punct:][:space:]]' -R . | xargs -L1 awk '!/encoding/ && NR < 2 { print FILENAME }'
du -k ~/* | awk '$1 > 50000' | sort -nr