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 using df from sorted by
Terminal - Commands using df - 38 results
echo "DISK:";df -Pl | grep -v "Filesystem" | awk '{print $5,$6}' ; echo "MEM:" ; free -mto | awk '{ print $1,$2,$3,$4 }'; echo "CPU:"; top -b -d1 -n1 | grep Cpu | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}';echo "LOAD:"; cat /proc/loadavg
2014-09-29 12:43:52
User: injez
Functions: awk cat df echo free grep top

Monitoring system in one line :

DISK : disk space

MEM: memory ( mem , swap, Total)

CPU : all information about cpu activity

LOAD : load average

getlunid() { lv=$(df -P $1|grep "^/dev/"|awk '{print $1}'|awk -F/ '{print $3}'); hd=$(lslv -l $lv|tail -1|awk '{print $1}');id=$(odmget -q "name like $hd AND attribute=unique_id" CuAt|grep "value ="|awk -F= '{print $2}'|tr -d '"');echo $id;}
2014-04-20 18:43:21
User: bigstupid
Functions: awk df echo grep tail tr
Tags: aix lvm SAN odm

For a given filesystem return the LUN ID. Command assumes 1:1 relationship between fs:lv:hdisk:lun which may not be the case in all environments.

(mountpoint -q "/media/mpdr1" && df /media/mpdr1/* > /dev/null 2>&1) || ((sudo umount "/media/mpdr1" > /dev/null 2>&1 || true) && (sudo mkdir "/media/mpdr1" > /dev/null 2>&1 || true) && sudo mount "/dev/sdd1" "/media/mpdr1")
2014-04-12 11:23:21
User: tweet78
Functions: df mkdir mount sudo umount

In my example, the mount point is /media/mpdr1 and the FS is /dev/sdd1

/mountpoint-path = /media/mpdr1


Why this command ?

Well, in fact, with some external devices I used to face some issues : during data transfer from the device to the internal drive, some errors occurred and the device was unmounted and remounted again in a different folder.

In such situations, the command mountpoint gave a positive result even if the FS wasn't properly mounted, that's why I added the df part.

And if the device is not properly mounted, the command tries to unmount, to create the folder (if it exists already it will also work) and finally mount the FS on the given mount point.

echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-") | sudo tee /sys/bus/usb/drivers/usb/unbind
2014-04-06 12:06:29
User: tweet78
Functions: awk cut df echo grep head sudo tail tee tr

You have an external USB drive or key.

Apply this command (using the file path of anything on your device) and it will simulate the unplug of this device.

If you just want the port, just type :

echo $(sudo lshw -businfo | grep -B 1 -m 1 $(df "/path/to/file" | tail -1 | awk '{print $1}' | cut -c 6-8) | head -n 1 | awk '{print $1}' | cut -c 5- | tr ":" "-")

df -h --total | awk 'NR==1; END{print}'
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.

sudo tune2fs -l $(df -h / |(read; awk '{print $1; exit}')) | grep -i created
2013-08-08 15:18:09
User: thechile
Functions: awk df grep sudo tune2fs

..not guaranteed to always be accurate but fun to see how old you Linux installation is based on the root partitions file system creation date.

dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
df | awk '{if ($2!=dspace) print "different"; dspace=$2;}'
df -H | grep -vE '^Filesystem|tmpfs|cdrom|none' | awk '{ print $5 " " $1 }'
tune2fs -l $(df -P / | awk 'NR==2 {print $1}') | sed -n 's/^.*created: *//p'
2012-05-31 12:12:35
User: forcefsck
Functions: awk df sed tune2fs

Find out the earliest installation time of a linux system by getting the / filesystem creation time. This example is only valid the os is installed on an ext2/3/4 filesystem.

# umount /media/filesystem; e2fsck -f /dev/device ; resize2fs -p /dev/device 200G #actual newsize#;lvreduce --size 200G /dev/device; mount /media/filesystem; df -h /media/filesystem
2011-09-14 08:52:02
User: bbelt16ag

Just the commands for the lvreduce I keep forgetting.

df -PH|column -t
df -P | column -t
2011-04-09 13:12:46
User: fossilet
Functions: column df

-P uses the POSIX output format, which makes information on each file system always printed on exactly one line. "column -t" makes a table from the input.

nohup df -k | sort -rn 12
df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)
2011-03-16 14:25:45
User: purpleturtle
Functions: df echo grep read sort
Tags: sort headers df

Show disk space info, grepping out the uninteresting ones beginning with ^none while we're at it.

The main point of this submission is the way it maintains the header row with the command grouping, by removing it from the pipeline before it gets fed into the sort command. (I'm surprised sort doesn't have an option to skip a header row, actually..)

It took me a while to work out how to do this, I thought of it as I was drifting off to sleep last night!

df /media/mountpoint |egrep -o '^[/a-z0-9]*'
2011-01-24 21:14:55
User: DaveQB
Functions: df egrep
Tags: grep,df

Shorter way to find the device for a given mountpoint

df | grep -w '/media/armadillo' | cut -d " " -f 1
df | grep -w '/media/mountpoint' | cut -d " " -f 1
2011-01-21 05:38:05
User: ntropia
Functions: cut df grep

Identical output but a different way without having to shoot with the Awk cannon :)

df -P | awk '$6=="/media/KINGSTON" {print $1}'
2011-01-21 00:32:00
User: linuts
Functions: awk df

No need for grep | awk. -P on df will force the mount point to be on the same line as the device

df | grep -w /media/KINGSTON | awk {'print $1'}
2011-01-20 09:07:19
Functions: awk df grep

most usefull when creating batch scripts using several usb drives and some commands like mkntfs needs a device name

the -w option for grep is here to filter lines when you have multiple drives with the same volume label. Without this option, the grep command will return




df -i <partition>
2010-12-12 03:34:57
User: bzaman
Functions: df

tune2fs also provides the same information . But the information does not give the current usage , it gives the information when the file system was last mounted.


while (true); do clear; uname -n; echo ""; df -h /; echo ""; tail -5 /var/log/auth.log; echo ""; vmstat 1 5; sleep 15; done
2010-08-23 04:37:58
User: roknir
Functions: df echo sleep tail uname vmstat

You can use this one-liner for a quick and dirty (more customizable) alternative to the watch command. The keys to making this work: everything exists in an infinite loop; the loop starts with a clear; the loop ends with a sleep. Enter whatever you'd like to keep an eye on in the middle.

tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
df -l | grep -e "9.%" -e "100%"
2010-04-26 17:57:54
User: dooblem
Functions: df grep

Reports all local partitions having more than 90% usage.

Just add it in a crontab and you'll get a mail when a disk is full.

(sending mail to the root user must work for that)