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 by knoppix5 from sorted by
Terminal - Commands by knoppix5 - 43 results
ls -lart|lolcat -a
2016-11-18 02:45:39
User: knoppix5
Functions: ls

(example above is the 'ls' command with reduced output speed)

lsa() { ls -lart; history -s "joe \"$(\ls -apt|grep -v /|head -1)\"" ; }
2016-07-07 21:27:55
User: knoppix5
Functions: ls

Display recursive file list (newest file displayed at the end) and be free to access last file in the list simply by pressing arrow_up_key i.e. open it with joe editor.

BTW IMHO the list of files with newest files at the end is often more informative.

Put this 'lsa' function somewhere in your .bashrc and issue

. ~/.bashrc


source ~/.bashrc

to have access to the 'lsa' command immediately.


(the function appends command "joe last_file_in_the_list" at the end of command history)

tree -isafF /var|grep -v "/$"|tr '[]' ' '|sort -k1nr|head
Ctrl + Alt
2015-11-10 22:08:57
User: knoppix5

Hold 'Ctrl' + 'Alt' key while selecting rectangular text area of the screen with

left mouse button.

Should work in any terminal screen (xterm, konsole, ...) under X, if not

then try with 'Ctrl' + 'Shift' + 'Alt' or two-combination of these.

bar() { foo=$(ls -rt|tail -1) && read -ep "cat $foo? <y/n> " a && [[ $a != "n" ]] && eval "cat $foo" ;}
2015-10-21 20:09:33
User: knoppix5
Functions: eval ls read tail

This command will display the file, but you can change 'cat' to anything else

(type 'n' when prompted to cancel the command or anything else to proceed).


Some hints for newbies:


unset bar

to make 'bar' function annihilated.

For permanent usage you can put this (bar) function in your .bashrc (for bash) or in .profile (for sh).


. ~/.bashrc

you can get all new inserted functions in .bashrc (so the function 'bar'

or whatever name you choose) immediately available.

echo -e ''$_{1..80}'\b+'
2015-05-05 22:13:33
User: knoppix5
Functions: echo

(here is character '+' repeated 80 times)

Sometimes needed to enhance the title of the script.

clear; while sleep 1; do d=$(date +"%H:%M:%S"); e=$(echo "toilet -t -f mono12 $d");tput setaf 1 cup 0; eval $e; tput setaf 4 cup 8; eval "$e -F flop";tput cup 0; done
for a in $(ls /usr/sbin /usr/bin); do ps -fC $a;done|grep -v PPID
2015-04-27 18:15:56
User: knoppix5
Functions: grep ls ps

Thanks to pooderbill for the idea :-)

env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit
2015-04-12 13:48:31
User: knoppix5
Functions: env

Usage example: display output of a command running in the background at desired time

The example in details: report disk quotas and that backup process will start soon

In my /etc/crontab file I added following four lines for weekly automatic incremental backup:


52 13 * * 7 root mount /dev/sda3 /media/da2dc69c-92cc-4249-b2c3-9b00847e7106


53 13 * * 7 knoppix5 df -h >~/df.txt


54 13 * * 7 knoppix5 env DISPLAY=:0 /usr/bin/gedit ~/df.txt && wmctl -a gedit


55 13 * * 7 root /home/knoppix5/rdiff-backup.sh


line one: as root mount media for backup on Sunday 13:52

line two: as user knoppix5 write out to text file in home directory the free space of all mounted disks on Sunday 13:53

line three: in front of you open and display a very simple text editor (I prefer gedit) with content of previously reported disk usage at Sunday 13:54

wmctl -a gedit means (from the manual):

-a Switch to the desktop containing the window , raise the window, and give it focus.

line four: as root run incremental backup script rdiff-backup.sh as root on Sunday 13:54


my rdiff-backup.sh, with root permissions backups in short time (writes only changes from the last backup) the etire linux system (except excluded - i.e. you don't want backup recursively your backup disk), looks like this (Show sample output):

a=$(b=$(($LINES/2));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '
cp -Rs dir1 dir2
2015-04-01 22:51:16
User: knoppix5
Functions: cp

dir1 and all its subdirs and subdirs of subdirs ... but *no files*

will be copied to dir2 (not even symbolic links of files will be made).

To preserve ownerships & permissions:

cp -Rps dir1 dir2

Yes, you can do it with

rsync -a --include '*/' --exclude '*' /path/to/source /path/to/dest

too, but I didn't test if this can handle attributes correctly

(experiment rsync command yourself with --dry-run switch to avoid

harming your file system)

You must be in the parent directory of dir1 while executing

this command (place dir2 where you will), else soft links of

files in dir2 will be made. I couldn't find how to avoid this

"limitation" (yet). Playing with recursive unlink command loop


PS. Bash will complain, but the job will be done.

clear;while true;sleep 1;do for((a=1;a<=$(tput cols)/3;a++));do tput cup 0 $a;echo " " $(date);done;sleep 1;for((a;a>=1;a--));do tput cup 0 $a;echo $(date) " ";done;done
sed 's/[0-9]\+/ [&] /g'
for a in $(seq 15); do (xset led 3);(xset -led 3);sleep .9;done
find . -type d| while read i; do echo $(ls -1 "$i"|wc -m) $(du -s "$i"); done|sort -s -n -k1,1 -k2,2 |awk -F'[ \t]+' '{ idx=$1$2; if (array[idx] == 1) {print} else if (array[idx]) {print array[idx]; print; array[idx]=1} else {array[idx]=$0}}'
2014-02-25 22:50:09
User: knoppix5
Functions: awk du echo find ls read sort wc

Very quick! Based only on the content sizes and the character counts of filenames. If both numbers are equal then two (or more) directories seem to be most likely identical.

if in doubt apply:

diff -rq path_to_dir1 path_to_dir2

AWK function taken from here:


(sed 's/#.*//g'|sed '/^ *$/d'|tr '\n' ';'|xargs echo) < script.sh
2013-10-26 23:23:51
User: knoppix5
Functions: sed tr xargs


Convert an one-liner to script:

foo() { <one-liner> ; }


typeset -f foo


unset -f foo
2013-10-09 08:40:06
User: knoppix5
Tags: man search

Will highlight search term i.e. "foo" across entire man page (scroll up or down to see)


That is how to find things ;)


(slash+empty string+Enter) will jump to the next occurence of previous searched item.

rsync -v -r --size-only --compare-dest=../A/ B/ C/
2013-09-10 21:41:16
User: knoppix5
Functions: rsync

Assumed dir A, B, C are subdirs of the current dir

Exact syntax of the command is:

rsync -v -r --size-only --compare-dest=/path_to_A/A/ /path_to_B/B/ /path_to_C/C/

(do not omit end-slashes, since that would copy only the names and not the contents of subdirs of dir B to dir C)

You can replace --size-only with --checksum for more thorough file differences validation

Useful switch:

-n, --dry-run perform a trial run with no changes made

echo "template file: ";read tpl;echo "new file(s separated w. space):"; read fl;touch $fl;find $fl -exec cp -ap $tpl "{}" \;
2013-03-08 10:00:36
User: knoppix5
Functions: cp echo find read touch

make a bunch of files with the same permissions, owner, group, and content as a template file

(handy if you have much to do w. .php, .html files or alike)

sed -i -n '/%/p' *.php
hexdump -v -e '"%u"' </dev/urandom|fold -60|head -n 30|sed 's/\(.\{2\}\)/\1 /g'
2013-02-16 12:56:24
User: knoppix5
Functions: fold head hexdump sed


od /dev/urandom -w60 -An|sed 's/ ..../ /g'|head -n 30

(this one lacks digits 8 and 9)

for count in $(seq 2 1001); do espeak "$count sheeps";sleep 2;done
tr -s ' \t' <1.txt >2.txt
2012-12-19 07:36:00
User: knoppix5
Functions: tr

Remove empty lines additionally:

tr -s ' \t\n' <1.txt >2.txt

identical with:

tr -s '[:space:]' <1.txt >2.txt

To "clean perfectly" a text or code file, You can combine this command with

another one:

while read l; do echo -e "$l"; done <1.txt >2.txt

(= remove all leading and trailing spaces or tabs from all lines of a text file)

a=$(stty -a -F /dev/tty1| awk -F'[ ;]' '/columns/ { print $9 }'); fold -w$a /dev/vcs1;echo
source ~/.bashrc
2012-10-01 08:30:19
User: knoppix5

Any changes to BASH shell made in .bashrc will be active in the current terminal window from the moment you execute this command, ie. aliases, prompt settings etc. No need to restart terminal.

(In BASH 'source' simile to 'eval' lets you generally execute any bunch of commands stacked in a text file).