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.

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 tagged kernel from sorted by
Terminal - Commands tagged kernel - 31 results
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
sudo sh -c 'echo 1 > /proc/sys/kernel/dmesg_restrict'
2015-03-13 20:54:45
User: Blacksimon
Functions: sh sudo

Linux offers an interesting option to restrict the use of dmesg. It is available via /proc/sys/kernel/dmesg_restrict.

You can check the status with:

cat /proc/sys/kernel/dmesg_restrict

Alternatively you can use sysctl:

sudo sysctl -w kernel.dmesg_restrict=1

To make your change persistent across reboot, edit a fille in /etc/sysctl.d/.

sysctl --system
2015-01-29 07:56:36
User: tankywoo
Functions: sysctl

Use `sysctl -p` without argument will only load /etc/sysctl.conf, but user configs always put in /etc/sysctl.d/*.conf, `sysctl --system` will load all the config files

echo 1 > /proc/sys/sunrpc/nfs_debug
2014-08-12 14:40:55
User: harpo
Functions: echo

echo 1 > /proc/sys/sunrpc/nfs_debug && tail -f /var/log/messages

to debug NFS issues.

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
curl -s -k https://www.kernel.org/feeds/kdist.xml | sed -n -e 's@.*<guid>\(.*\)</guid>.*@\1@p' | 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

echo c > /proc/sysrq-trigger
2013-05-07 19:41:40
User: fangfufu
Functions: echo
Tags: kernel

Well, this is quite useful for testing if your hardware watchdog is working properly.

lsmod | grep -io MODULENAME| xargs modinfo | grep -iw version
2013-03-18 07:52:14
User: adriano
Functions: grep lsmod modinfo xargs
Tags: kernel modules

Returns the version of the kernel module specified as "MODULENAME", when available.

/sbin/sysctl -p
2013-02-14 12:48:26
User: Risthel

Reload all defined kernel variables from /etc/sysctl.conf(if no parameter after -p is given) without the old myth "Ah, you'll need to reboot to apply those variables"...

uname -m # display machine "hardware name"
2013-01-04 11:46:43
User: mpb
Functions: uname

Display the machine "hardware name" 32 or 64 bit.

"x86_64" is shown on 64 bit machines

"i686" is typically shown on 32 bit machines (although, you might also see "i386" or "i586" on older Linuxen).

On other "unix-like" systems, other hardware names will be displayed.

For example, on AIX, "uname -m" gives the "machine sequence number".

For whatever reason, IBM decided that "uname -M" would give the machine type and model.

(ref: http://www.ibm.com/developerworks/aix/library/au-aix-systemid.html )

On Sun Solaris, "uname -m" can be used to determine the chip type and "isainfo -v" will reveal

if the kernel is 64 or 32 bit.

(ref: http://www.ibiblio.org/pub/packages/solaris/sparc/html/32.and.64.bit.packages.html )

A more reliable way to determine "64-bit ness" across different Unix type systems is to compile the following simple C program:

cat <<eeooff > bits.c


* program bits.c

* purpose Display "32" or "64" according to machine type

* written January 2013

* reference http://www.unix.org/whitepapers/64bit.html


/* hmm, curious that angle-brackets removed by commandlinefu.com data input processing? */

#include "/usr/include/stdio.h"

long lv = 0xFFFFFFFF;

main ( ) {

printf("%2d\n",(lv < 0)?32:64);



Compile and run thusly: cc -o bits bits.c; ./bits

isainfo -v
2013-01-04 03:07:28
User: halcyonblue

This is likely only valid on Solaris based systems. Unfortunately a lot of the more universal techniques for determining if a system is 32bit or 64bit on x86 solaris fail to give much more information than "i86pc"

getconf LONG_BIT
2012-12-12 23:51:51
User: varghjarta
Functions: getconf

Needed a quick way to see if my server distro that I setup years ago was running 32bit or not, since with time I had forgotten.

Note: does not check _hardware_ e.g. /proc/cpuinfo but rather the kernel installed

modprobe --show-depends module_name
2012-08-17 16:54:52
User: miguelcnf
Functions: modprobe

Use modprobe to list all the dependencies of a certain kernel module. Handy when debugging system issues.

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-08-15 10:02:12
User: mtron
Functions: awk sed sudo

Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.

curl 'https://www.kernel.org/kdist/finger_banner'
2012-03-04 21:10:19
User: Testuser_01

Gets the (previously obtainable with:

finger @kernel.org

) info of the latest linux kernel versions available.

sudo dpkg -i `ls -tr *.deb | tail -n4`
2011-10-09 14:20:11
User: _john
Functions: sudo tail

after kernel build with make deb-pkg, I like to install the 4 newest packages that exist in the directory. Beware: might be fewer for you....

apt-get remove $(dpkg -l | awk "/^ii linux-(image|headers)/ && ! /`uname -r`/ {print \$2}")
2011-10-09 13:58:47
User: _john
Functions: apt awk

since awk was already there one can use it instead of the 2 greps. might not be faster, but fast enough

echo "root=/dev/sda7" > /proc/param.conf
2011-09-27 18:06:53
User: totti
Functions: echo

Then exit from the shell.


some time need to exit twice

exit exit

Now the OS will boot with the new parameters.

grep -2riP '\b(fuck|shit|bitch|tits|ass\b)' /usr/src/linux/
zgrep CONFIG_MAGIC_SYSRQ /proc/config.gz
sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{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)}')
2011-04-25 05:19:57
User: Bonster
Functions: awk sed sudo

Same as 7272 but that one was too dangerous

so i added -P to prompt users to continue or cancel

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

aptitude remove $(dpkg -l|awk '/^ii linux-image-2/{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)}')
2010-12-11 11:38:15
User: __
Functions: awk sed

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

I'm bummed that this took 228 characters. I'd like to see a simpler version.

echo 0 > /proc/sys/kernel/randomize_va_space
2010-07-11 16:42:42
User: gunslinger_
Functions: echo
Tags: kernel

Disable randomisation address

aptitude remove ?and(~i~nlinux-(im|he) ?not(~n`uname -r`))
2010-06-11 22:57:09
User: dbbolton

A little aptitude magic. Note: this will remove images AND headers. If you just want to remove images: aptitude remove ?and(~i~nlinux-im ?not(~n`uname -r`))

I used this in zsh without any problems. I'm not sure how other shells will interpret some of the special characters used in the aptitude search terms. Use -s to simulate.