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.

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



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

Commands tagged Linux from sorted by
Terminal - Commands tagged Linux - 240 results
dmidecode -s system-serial-number
2012-05-25 17:03:37
User: SEJeff

This returns the hardware serial number. Dell calls this the "Service Tag" and it can be used to retrieve warranty information or used for RMA / repairs.

awk '{if ($NF ~ "^[a-zA-Z].*[0-9]$" && $NF !~ "c[0-9]+d[0-9]+$" && $NF !~ "^loop.*") print "/dev/"$NF}' /proc/partitions
awk '{if ($NF ~ "^[a-zA-Z].*[a-zA-Z]$" && $NF !~ "name" || $NF ~ "c[0-9]+d[0-9]+$") print "/dev/"$NF}' /proc/partitions
ps aux | awk '{if ($8 ~ "D") print $0}'
2012-05-25 16:53:57
User: SEJeff
Functions: awk ps

Lots of fun to run on nfs clients when the server or network connection is having issues

ifconfig eth0 allmulti
2012-05-25 16:43:41
User: SEJeff
Functions: ifconfig

Disabling an interface's multicast filter is like disabling IGMP snooping on a switch. It is useful for testing and troubleshooting.

kill -9 -$(ps x -o "%c %r" | awk '/svscan/{print $2}')
2012-05-25 16:39:02
User: SEJeff
Functions: awk kill ps

Daemontools[1] won't always properly reap it's children. Sometimes when you need to kill the main svscan process, you want to also clean up all of it's children. The way to do that is to send a signal to the entire process group. It is a bit tricky

[1] http://cr.yp.to/daemontools.html

find /proc/sys/vm -maxdepth 1 -type f | while read i ; do printf "%-35s\t%s\n" "$i" "$(<$i)" ; done | sort -t/ -k4
2012-05-25 16:34:16
User: SEJeff
Functions: find printf read sort

Sometimes you want to see all of the systcls for a given $thing. I happened to need to easily look at all of the vm sysctls between two boxes and compare them. This is what I came up with.

lsof +c 15 | awk '{print $1}' | sort | uniq -c | sort -rn | head
fdisk -l /dev/sda | grep -E sda[0-9]+ | sed s/*// | awk '{printf ("%s %f ",$1,$2/512); if($2%512){ print "BAD" }else {print "Good"} }' | column -t
2012-05-18 08:34:36
Functions: awk column fdisk grep sed

To get most of you HDD/SSD driver you need to make sure you partition are aligned, if not the speed penalty can be up to 50% slower!

this simple one liner will check to see if each partition start sector is divided by 512

you need to change sda with your driver

if you find the one of your partitions is not aligned use gparted to move the start sector of the partition to be divided of 512

2012-04-15 16:42:32
User: moollaza

"What it actually shows is going to be dependent on the commands you've previously entered.

When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it).

If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental.

Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

find ./src -type d -name "Entity" | xargs ls -A | cut -d . -f1 | sed 's_^_app/console doctrine:generate:entities YourOwnBundleName:_'
2012-04-11 21:28:02
User: renoirb
Functions: cut find ls sed xargs

When I do a major change in my entities, I want to find a way to find all my Entities names and create the commande for me.

So instead of doing ls src/Your/OwnBundle... and then do it manually, this helps a lot.

echo "0,,L" | sfdisk /dev/sdX
2012-04-09 18:36:24
User: twobitsprite
Functions: echo

Creates a single primary partition starting at sector 0 and extending to the end of the disk. Use with care.

echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sdX
grep "cpu " /proc/stat | awk -F ' ' '{total = $2 + $3 + $4 + $5} END {print "idle \t used\n" $5*100/total "% " $2*100/total "%"}'
2012-01-21 04:12:50
User: Goez
Functions: awk grep

This command displays the CPU idle + used time using stats from /proc/stat.

for FILE in `ls -1`; do if [ -L "$FILE" ]; then cp $(readlink "$FILE") ${FILE}_rf; rm -f $FILE; mv ${FILE}_rf "$FILE"; fi; done
iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; for table in `cat /proc/net/ip_tables_names`; do iptables -t $table -F; iptables -t $table -Z; iptables -t $table -X; done
2011-12-15 18:19:34
User: dash
Functions: iptables
Tags: Linux iptables

If you changed the default policy on any chain other than filter table chain's, this won't be enough.

apt-config dump
2011-12-13 19:11:02
User: LinuxMan
Functions: apt

Shows all configurations to apt and dpkg, rarely changed, you probably still have the default configuration. Go ahead and explore your configuration if you dare, perhaps change your apt-cache directory, Dir::Cache "var/cache/apt/"; or the names of the log files.

sudo ps aux --sort:rss | awk '{print $2"\t"$11": "$6/1024" MB"}' | column -t | less
ifconfig | awk '/inet / {sub(/addr:/, "", $2); print $2}'
human_filesize() { awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '}
2011-12-02 18:21:20
User: ArtBIT
Functions: awk printf

Converts a number of bytes provided as input, to a human readable number.

watch -tn1 'figlet -f slant `date +%T` | cowsay -n -f telebears'
2011-11-25 14:35:01
Functions: watch
Tags: Linux

You need to have figlet(for font) and cowsay installed.

Just copy n paste this command and you can see.....

figlet -f $(ls /usr/share/figlet/fonts/*.flf | shuf -n1) namakukingkong | cowsay -n -f $(ls /usr/share/cows/ | shuf -n1)
2011-11-25 13:54:06
Functions: ls
Tags: Linux

You need to have figlet(for font) and cowsay installed then add it to your .bashrc file.You can see it every time after start a new session.

for x in *.mp3; do y=`echo $x | sed 's/...\(.*\)/\1/' | sed 's/.mp3//ig'`; id3v2 --TIT2 "$y" "$x"; done
2011-11-17 18:57:09
User: robotmachine
Functions: sed
Tags: bash Linux mp3 id3

Assumes that the files are named as such: 01-Filename.mp3

If your files are named differently, change the number of periods in the sed 's/...\(.*\)/\1' bit to match the numbers of characters you need to cut off the front of the file.

Note: This only writes the titles.

x="1" && z="`ls -l * | wc -l`"; for y in *.mp3; do `id3v2 --TRCK "$x/$z" "$y"`; x=$[$x+1]; done
2011-11-17 18:52:59
User: robotmachine
Tags: Linux mp3 id3

Assumes that the files are named in numerical order (ie. 01 Filename.mp3). It will set the track number as tracknumber/totaltracks (ie. 1/14). This will write both ID3v1 and ID3v2 tags.

Note: This only writes the track numbers.

for line in `cat $file`; do firefox -new-tab "$line" & 2>/dev/null; sleep 1; done
2011-11-12 13:47:24
User: hamsolo474
Functions: sleep

this will open a new tab in firefox for every line in a file

the sleep is removable but i found that if you have a large list of urls 50+, and no sleep, it will try to open all the urls at once and this will cause them all to load a lot slower, also depending on the ram of your system sleep gives you a chance to close the tabs before they overload your ram, removing & >2/dev/null will yield unpredictable results.