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 ls from sorted by
Terminal - Commands using ls - 463 results
ls -r | ?{-not $_.psiscontainer} | group extension | select name, count, @{n='average'; e={($_.group | measure -a length).average}} | ft -a @{n='Extension'; e={$_.name}}, count, @{n='Average Size (KB)'; e={$_.average/1kb}; f='{0:N2}'}
2012-03-13 17:58:10
User: brianpeiris
Functions: ls
Tags: PowerShell

Here's an annotated version of the command, using full-names instead of aliases. It is exactly equivalent to the short-hand version.

# Recursively list all the files in the current directory.

Get-ChildItem -Recurse |

# Filter out the sub-directories themselves.

Where-Object { return -not $_.PsIsContainer; } |

# Group the resulting files by their extensions.

Group-Object Extension |

# Pluck the Name and Count properties of each group and define

# a custom expression that calculates the average of the sizes

# of the files in that group.

# The back-tick is a line-continuation character.

Select-Object `




Name = 'Average';

Expression = {

# Average the Length (sizes) of the files in the current group.

return ($_.Group | Measure-Object -Average Length).Average;


} |

# Format the results in a tabular view, automatically adjusted to

# widths of the values in the columns.

Format-Table -AutoSize `


# Rename the Name property to something more sensible.

Name = 'Extension';

Expression = { return $_.Name; }




# Format the Average property to display KB instead of bytes

# and use a formatting string to show it rounded to two decimals.

Name = 'Average Size (KB)';

# The "1KB" is a built-in constant which is equal to 1024.

Expression = { return $_.Average / 1KB };

FormatString = '{0:N2}'


ls | grep -i mp3 | sort -R | sed -e 's/.*/"&"/' | xargs mpg123
2012-03-10 20:51:36
User: retrodanny
Functions: grep ls sed sort xargs

* grep -i leaves only mp3 files (case insentitive)

* sort -R randomizes list (may use GNU 'shuf' instead).

* the sed command will add double quotes around each filename (needed if odd characters are present)

ls -Rl dir1/ > /tmp/dir1.ls; ls -Rl dir2/ > /tmp/dir2.ls; meld /tmp/dir1.ls /tmp/dir2.ls
2012-03-04 13:06:55
User: joeseggiola
Functions: ls

Compare the ls -Rl output of two directories in meld (you can also use diff -y instead of meld).

find <directory> -type f -printf "%T@\t%p\n"|sort -n|cut -f2|xargs ls -lrt
ls -ltr --directory $(find . -regex "./.*[^/]*\'" -type f | xargs -n 1 dirname | sort | uniq)
2012-03-02 03:48:47
User: pdkl95
Functions: dirname find ls sort xargs

This let me find some a set of modifications that were made to a rather large tree of files, where the file-names themselves were not unique (actually: insanely redundant and useless. "1.dat 2.dat ..."). Pruning down to last-branch brough things back to the "project-name" scope, and it's then easy to see which branches of the tree have recently changed, or any other similar search.

Ideally, it should sort the directories by the mtime of the most recent *file* *inside* the directory, but that's probably outside the scope of a (sane...) command line.

ls|grep .mp3 >list.txt; while read line; do newname=`echo $line|sed 's/\ /-/g'|sort`; newname=`echo $newname|tr -s '-' `; echo $newname; echo $newname>> tracklist.txt;mv "$line" "$newname"; done <list.txt; rm list.txt
ls -t1 $* | head -1 ;
2012-02-10 22:13:24
Functions: head ls

Returns the most recently modified file in the current (or specified) directory. You can also get the oldest file, via:

ls -t1 $* | tail-1 ;

ls -l | gawk -v FIELDWIDTHS='1 3 3 3' '{print $2}'
find ./ -type f -size +100000k -exec ls -lh {} \; 2>/dev/null| awk '{ print $8 " : " $5}'
2012-01-21 04:19:35
User: Goez
Functions: awk find ls

This command does a basic find with size. It also improves the printout given (more clearer then default)

Adjusting the ./ will alter the path.

Adjusting the "-size +100000k" will specify the size to search for.

ls -t | head
2012-01-17 16:28:32
User: scottlinux
Functions: ls
Tags: tail ls head,

This will quickly display files last changed in a directory, with the newest on top.

ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'
lso(){ jot -w '%04d' 7778 0000 7777 |sed '/[89]/d;s,.*,printf '"'"'& '"'"';chmod & '"$1"';ls -l '"$1"'|sed s/-/./,' \ |sh \ |{ echo "lso(){";echo "ls \$@ \\";echo " |sed '";sed 's, ,@,2;s,@.*,,;s,\(.* \)\(.*\),s/\2/\1/,;s, ,,';echo \';echo };};}
2012-01-08 05:48:24
User: argv
Functions: chmod echo ls sed sh

this requires the use of a throwaway file.

it outputs a shell function.

assuming the throwaway file is f.tmp

usage: >f.tmp;lso f.tmp > f.tmp; . f.tmp;rm f.tmp;lso -l ...


credit epons.org for the idea. however his version did not account for the sticky bit and other special cases.

many of the 4096 permutations of file permissions make no practical sense. but chmod will still create them.

one can achieve the same sort of octal output with stat(1), if that utility is available.

here's another version to account for systems with seq(1) instead of jot(1):


case $# in


{ case $(uname) in


jot -w '%04d' 7778 0000 7777 ;;


seq -w 0000 7777 ;;

esac; } \

|sed '


s,.*,printf '"'"'& '"'"';chmod & '"$1"';ls -l '"$1"'|sed s/-/./,' \

|sh \


echo "lso(){";

echo "ls \$@ \\";

echo " |sed '";

sed '

s, ,@,2;


s,\(.* \)\(.*\),s/\2/\1/,;

s, ,,';

echo \';

echo };




echo "usage: lso tmp-file";




this won't print out types[1]. but its purpose is not to examine types. its focus is on mode and its purpose is to make mode easier to read (assuming one finds octal easier to read).

1. one could of course argue "everything is a file", but not always a "regular" one. e.g., a "directory" is really just a file comprising a list.

ls | view -
2012-01-04 07:18:44
User: lefada
Functions: ls
Tags: vim

view does not enable the buffer because it opens in read-only, so it does the same

ls -d1 $PWD/*
ls | vim +'set bt=nowrite' -
ls -d1 $PWD/{.*,*}
ls -a | sed "s#^#${PWD}/#"
2011-12-16 22:19:06
User: bbbco
Functions: ls sed
Tags: sed ls pwd

Use the -a flag to display all files, including hidden files. If you just want to display regular files, use a -1 (yes, that is the number one). Got this by RTFM and adding some sed magic.

[bbbco@bbbco-dt ~]$ ls -a | sed "s#^#${PWD}/#"











[bbbco@bbbco-dt ~]$ ls -1 | sed "s#^#${PWD}/#"








ls -d $PWD/*
find `pwd` -maxdepth 1 -exec ls --color -d {} \;
ls -1 | awk ' { print "zip "$1".zip " $1 } ' | sh
2011-12-14 20:30:56
User: kaywhydub
Functions: awk ls
Tags: awk zip sh

This will list the files in a directory, then zip each one with the original filename individually.

video1.wmv -> video1.zip

video2.wmv -> video2.zip

This was for zipping up large amounts of video files for upload on a Windows machine.

ls -ad */
2011-12-10 17:08:07
User: tbekolay
Functions: ls
Tags: ls directory

Like normal ls, but only lists directories.

Can be used with -l to get more details (ls -lad */)

ls ${my_dir:=/home}
2011-11-30 15:06:51
Functions: ls

Will use variable value (for variable $my_dir, in this case), an assign a default value if there is none.

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.

function right { bc <<< "obase=8;ibase=2;$1"; }; touch foo; chmod $(right 111111011) foo; ls -l foo
2011-11-16 22:43:31
User: nerd
Functions: bc chmod ls touch

I simply find binary notation more straightforward to use than octal in this case.

Obviously it is overkill if you just 600 or 700 all of your files...

ls -l `whereis gcc`
2011-11-15 19:45:08
User: knathan54
Functions: ls
Tags: which ls zsh

whereis (1) - locate the binary, source, and manual page files for a command

Not actually better, just expanded a bit. The "whereis" command has the following output:

whereis gcc

gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz

therefore the 'ls' error on first line, which could be eliminated with a little extra work.