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 tagged file from sorted by
Terminal - Commands tagged file - 75 results
cat <file> > /dev/null
2011-11-12 15:45:27
User: totti
Functions: cat
Tags: ram file cache

Best result when file size less than half of RAM size

stat --format "%s" <file>
read -d ""
2011-10-25 18:44:11
User: totti
Functions: read

Handle any bad named file which contains ",',\n,\b,\t,` etc

Store the file name as null character separated list

find . -print0 >name.lst

and retrieve it using

read -r -d ""


find . -print0 >name.lst; cat name.lst| while IFS="" read -r -d "" file; do ls -l "$file"; done
filext () { echo ${1##*.}; }
ls -i1 filename
awk '$3==$4' /etc/passwd
cat x
cat -n file.txt
nl file.txt > file_numbered.txt
bsdiff <oldfile> <newfile> <patchfile>
2011-09-13 18:22:40
User: totti

Upload/download newer version of any file with less size and high speed.

To remake the new file use

bspatch <oldfile> <newfile> <patchfile>
strace -ff -e trace=file my_command 2>&1 | perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ && print'
2011-08-16 15:00:18
Functions: perl strace

Can be run as a script `ftrace` if my_command is substrituted with "$@"

It is useful when running a command that fails and you have the feeling it is accessing a file you are not aware of.

wget --spider $URL 2>&1 | awk '/Length/ {print $2}'
2011-07-03 00:14:58
User: d3Xt3r
Functions: awk wget

- Where $URL is the URL of the file.

- Replace the $2 by $3 at the end to get a human-readable size.

Credits to svanberg @ ArchLinux forums for original idea.

Edit: Replaced command with better version by FRUiT. (removed unnecessary grep)

rf() { for i in "$@"; do mv "$i" "$(pwgen 8 1).${i##*.}"; done }
2011-06-22 07:45:23
User: flatcap
Functions: mv

Give files a random name (don't ask why :-)

The function will rename files but maintain their extensions.

BUG: If a file doesn't have an extension it will end up with a dot at the end of the name.

The parameter '8' for pwgen controls the length of filenames - eight random characters.

mv file.png $( mktemp -u | cut -d'.' -f2 ).png
alias big='BIG () { find . -size +${1}M -ls; }; BIG $1'
2011-03-10 06:33:00
User: greggster
Functions: alias find

This is for bash - make an alias - also a good blueprint for making aliases that take arguments to functions. If for Solaris use "-size +${1}000000c" to replace "-size +${1}M"

<command> 2> <file>
readlink -f myfile.txt
2011-02-07 14:28:28
User: AlBeBack
Functions: readlink
Tags: file

Retrieve absolute path name from relative path

sed -i '/pattern/N; s/\n//' filename
file -s /dev/sd*
2010-12-28 09:56:03
User: mhs
Functions: file
Tags: file devfs

file(1) can print details about certain devices in the /dev/ directory (block devices in this example). This helped me to know at a glance the location and revision of my bootloader, UUIDs, filesystem status, which partitions were primaries / logicals, etc.. without running several commands.

See also:

file -s /dev/dm-* file -s /dev/cciss/*


( di $TOFSCK -h ; /bin/umount $TOFSCK ; time /sbin/e2fsck -y -f -v $FSCKDEV ; /bin/mount $TOFSCK ) |& /bin/mail $MAILTO -s "$MAILSUB"
2010-10-24 00:35:23
User: px
Functions: time

This one-liner is for cron jobs that need to provide some basic information about a filesystem and the time it takes to complete the operation. You can swap out the di command for df or du if that's your thing. The |& redirections the stderr and stdout to the mail command.

How to configure the variables.




FSCKDEV=`grep $TOFSCK /proc/mounts | cut -f1 -d" "`

MAILSUB="weekly file system check $TOFSCK "

watch -n <time_interval> "du -s <file_or_directory>"
find . -type f -mtime -1 \! -type d -exec ls -l {} \;
while true; do du -s <file_or_directory>; sleep <time_interval>; done
2010-08-24 19:55:13
User: potatoface
Functions: du sleep

very handy if you copy or download a/some file(s) and want to know how big it is at the moment

sed -i 's/^\s\+//' <file>
sed 's/^[ \t]*//;s/[ \t]*$//' -i file