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 - 461 results
ls | grep -Eo "\..+" | sort -u
folder=0;mkdir $folder; while find -maxdepth 1 -type f -exec mv "{}" $folder \; -quit ; do if [ $( ls $folder | wc -l ) -ge 100 ]; then folder=$(( $folder + 1 )); mkdir $folder; fi ; done
2011-02-11 21:28:01
User: Juluan
Functions: find ls mkdir mv wc

If you have a folder with thousand of files and want to have many folder with only 100 file per folder, run this.

It will create 0/,1/ etc and put 100 file inside each one.

But find will return true even if it don't find anything ...

ls -Xp | grep -Eo "\.[^/]+$" | sort | uniq
2011-02-10 20:47:59
User: Amarok
Functions: grep ls sort
Tags: uniq ls grep

Works on current directory, with built-in sorting.

ls -l --time-style=+"%Y-%m-%d %H:%M:%S"
2011-02-10 17:15:37
User: bartonski
Functions: ls

the --time-style argument to 'ls' takes several possible modifiers: full-iso, long-iso, iso, locale, +FORMAT.

The +FORMAT modifier uses the same syntax as date +FORMAT.

--time-style=+"%Y-%m-%d %H:%M:%S" strikes a happy medium between accuracy and verbosity:

ls -lart --time-style=long-iso

doesn't show time down to the nearest second,

ls -lart --time-style=full-iso

displays time to 10E-9 second resolution, but with no significant digits past the full seconds, also showing the timezone:

-rw-r--r-- 1 bchittenden bchittenden 0 2011-02-10 12:07:55.000000000 -0500 bar
dpkg -S $( which ls )
exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; done
ls > ls; paste ls ls > ren; nano ren; sed 's/^/mv /' ren|bash; rm ren ls
2011-02-08 17:07:13
User: romulusnr
Functions: ls paste rm sed

Instead of tedious manual mv commands and tabbing, this routine creates a file listing all the filenames in the PWD twice, edit the second instance on each line to the new name, then save the file, the routine does the rest. Feel free to replace nano with your holy war editor of choice.

You will get a lot of "mv: 'x' and 'x' are the same file" warnings, these could be cleaned up but the routine works.

ls -ai | grep filename | find . -inum `awk '{print $1}'` -exec rm {} \;
2011-02-04 10:29:54
User: YogiBare
Functions: find grep ls rm

This command, when run from the directory containing "filename", will remove the file and any hard or symbolic links to the file.

IFS=$'\n'; i=1; ls -lt *mp3 | cut -d ":" -f2 | cut -d " " -f2- | while read f; do mv "$f" $(echo "$i"."$f"); ((i++)); done
2011-01-22 00:21:12
User: m1cawber
Functions: cut echo ls mv read

i use this after ripping internet radio streams to number the files as they originally played (even though streamripper can do this with -q).

to number other types of files, or all files, just change the *mp3. to rename directories only you could use

... ls -lt | grep ^d | cut -d ":" -f2 | cut -d " " -f2- | while read ...

ls -S|head -1find
ls /usr/bin | shuf -n 1
2011-01-07 22:09:12
User: pebkac
Functions: ls

This command will show an random command. this is useful if you want to explore various random commands.

ls -la | tee ~/log.txt
ls | grep '^[A-Z0-9]*$'
2010-12-19 21:45:53
User: b_t
Functions: grep ls

Some source package have many 'README' kind of files, among many other regular files/directories. This command could be useful when one wants to list only 'README' kind of files among jungle of other files. (e.g. I came across this situation after downloading source for module-init-tools)

Warning: This command would miss a file like => README.1 (or one with spaces in-between)

Corrections welcome.

ls *(.x)
ls -F | grep '*$'
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
ls $(grep cifs /etc/fstab | grep -v ^# |awk ' { print $2 } ') 1>/dev/null
2010-12-10 09:27:19
User: niall
Functions: awk grep ls
Tags: fstab cifs

It disturbs me when my logwatch report tells me a share or machine has disappeared, esp as mount isn't telling me what's gone. This command outputs to stderr the erroring cifs entries from fstab.

ls -1t --group-directories-first /path/to/dir/ | tail -n 1
2010-12-02 12:25:16
User: fpunktk
Functions: ls tail

reverse the sorting of ls to get the newest file:

ls -1tr --group-directories-first /path/to/dir/ | tail -n 1


If there are no files in the directory you will get a directory or nothing.

for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done
2010-12-01 14:13:31
User: joenjeru
Functions: ls

Do you have a large library of flv's you have picked up over the years using FlashGot Firefox plugin?

Do you want to be able to convert them to Ogg Theora (video) at once?

Try out this script...

ls /var/log/ |wc -l
ls --[TAB][TAB]
2010-11-18 15:31:28
User: strzel_a
Functions: ls

Use it for command like : mkdir, chown, ls, less...

ls -l
ls | grep .gz >> list.txt && cat list.txt | while read x ; do gunzip -d $x ; done && rm -rf list.txt
zcat -f $(ls -tr access.log*)
2010-10-30 22:54:54
User: dooblem
Functions: ls zcat
Tags: logs zcat

with zcat force option it's even simpler.

ls |tee >(grep xxx |wc >xxx.count) >(grep yyy |wc >yyy.count) |grep zzz |wc >zzz.count