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,130 results
for lib in `readelf -d /usr/bin/abiword | grep NEEDED | cut -f2 -d[ | cut -f1 -d]`; do [ -e /usr/lib/$lib ] && j=/usr/lib/$lib || j=`locate -l 1 $lib`; readlink -f $j ; done
pidof httpd | wc -w
2011-02-24 16:46:46
User: eneko
Functions: pidof wc
Tags: httpd
-1

Returns the number of running httpd processes

pgrep -c 'httpd|apache2'
2011-02-24 18:03:00
Tags: httpd
-1

this version is going to work on redhat/centos/suse AND ubuntu/debian systems

echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr
-1

Also shows files as they are found. Only works from a tty.

sudo netstat -tulpn | grep :8080
find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \;
for kern in $(grep "initrd " /boot/grub/grub.conf|grep -v ^#|cut -f 2- -d-|sed -e 's/\.img//g'); do mkinitrd -v -f /boot/initrd-$kern.img $kern; done
free -m | awk '/Mem/ {print $4}'
egrep -i " connected|card detect|primary dev" /var/log/Xorg.0.log
2011-02-24 18:04:04
User: axelabs
Functions: egrep
Tags: video egrep xorg
-1

The above one liner can be used to determine what card/driver is Xorg currently using. For additional information, see http://goo.gl/mDnWu

apachectl fullstatus
ping -b <broadcast address>
2012-05-21 16:55:33
User: OutputLogic
Functions: ping
Tags: ping broadcast
-1

A simple way to find all machines on a network subnet is pinging a broadcast address (-b flag). First run ifconfig ifconfig. Then use "Bcast" address and '-b' flag in ping

touch -t 197001010000 ./tmp && find . -newer ./tmp && rm -f ./tmp
2014-11-18 00:29:26
User: sergeylukin
Functions: find rm touch
-1

Sometimes you just want to operate on files that were created after specific date. This command consists of 3 commands:

- Create a dummy file with the custom date

- Find all files with "creation time" further than our custom date by using `-newer` find option. Add your crazy stuff here, like moving, deleting, printing, etc.

- Remove the dummy file

xe vm-list
2010-09-28 18:22:03
User: layer8
-1

Citrix XenServer 5.6, can be piped to grep for more interesting output

lsof -Pnl +M -i6 | grep 8080
ps -eo args,%cpu | grep -m1 PROCESS | tr 'a-z-' ' ' | awk '{print $1}'
echo $((1+2+3+4))
2>/dev/null dd if=/dev/urandom bs=1 count=6 | od -t x1 |sed '2d;s/^0\+ //;s/ /:/g'
find /path/to/dir -type f -exec grep \-H "search term" {} \;
2009-01-26 16:32:14
User: root
Functions: find grep
-1

Simple use of find and grep to recursively search a directory for files that contain a certain term.

xe vm-copy vm="ABCServer" sr-uuid=24565487-accf-55ed-54da54993ade784a new-name-label="Copy of ABCServer" new-name-description="New Description"
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
2012-04-02 10:53:40
User: mtron
Functions: awk sed sudo
-1

small update for this command to work with linux kernels 3.x

watch --interval 1 ls -lah
2013-10-16 10:41:15
User: c0r3dump3d
Functions: ls watch
-1

Use this command if you want to control the size of the files in human readable, every one second.

sed 's/^[ \t]*//' < <file> > <file>.out; mv <file>.out <file>
pkill -9 -u username php5-fcgi
2011-08-09 22:14:21
User: hpavc
-1

Similar commands, same origin.

pgrep [-cflvx] [-d delimiter] [-n|-o] [-P ppid,...] [-g pgrp,...] [-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...] [-t term,...] [pattern]

pkill [-signal] [-fvx] [-n|-o] [-P ppid,...] [-g pgrp,...] [-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...] [-t term,...] [pattern]

sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/
sed G
2009-05-02 12:11:40
Functions: sed
-1

G option cause a file to be spacing line by line.