Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using ls from sorted by
Terminal - Commands using ls - 448 results
cdn() { cd $(ls -1d */ | sed -n $@p); }
watch ls -lh /path/to/folder
2014-03-27 10:51:36
User: vonElfensenf
Functions: ls watch
Tags: pv
0

forgot to use a pv or rsync and want to know how much has been copied.

ls -lF -darth `find . -mmin -3`
2014-03-22 16:52:20
User: UncleLouie
Functions: ls
-3

Provides a recursive time ordered list of the current directory over the last 3 minutes.

Excluding zero byte files:

ls -lF -darth `find . -size +0 -mmin -3`

For the last day's files, change "-mmin -3" to "-mtime -1":

ls -lF -darth `find . -size +0 -mtime -1`
find ./ -type l -print0 | xargs -0 ls -plah
2014-03-20 20:36:39
Functions: find ls xargs
0

shows you the symlinks in the current directory, recursively, but without following them

ls | xargs WHATEVER_COMMAND
2014-03-12 18:00:21
User: pdxdoughnut
Functions: ls xargs
-4

xargs will automatically determine how namy args are too many and only pass a reasonable number of them at a time. In the example, 500,002 file names were split across 26 instantiations of the command "echo".

ls | grep ".txt$" | xargs -i WHATEVER_COMMAND {}
find . \( -iname "*.doc" -o -iname "*.docx" \) -type f -exec ls -l --full-time {} +|sort -k 6,7
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
0

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:

http://stackoverflow.com/questions/2912224/find-duplicates-lines-based-on-some-delimited-fileds-on-line

npm ls -g|grep "^[├└]\(.\+\)\?[┬─] "
ls | tr [:upper:] [:lower:] | grep -oP '\.[^\.]+$' | sort | uniq -c | sort
2014-01-30 11:37:27
User: icefyre
Functions: grep ls sort tr uniq
1

displays a list of all file extensions in current directory and how many files there are of each type of extension in ascending order (case insensitive)

ls -1 | xargs ruby -e'puts ARGV.shuffle'
ls -l /usr/share/xsessions/
2014-01-17 05:09:18
User: puresky
Functions: ls
0

Sometimes there are just no variables such as $DESKTOP_SESSION, $GDMSESSION, or $WINDOWMANAGER.

ls --color=never -1| grep -E "[0-9]{4}"|sed -re "s/^(.*)([0-9]{4})(.*)$/\2 \1\2\3/" | sort -r
for i in $(ls *.mp3); do mplayer $i && echo "delete it? [y/n]" && read trash && if [ "$trash" == "y" ]; then rm $i; fi; do
2013-12-23 20:09:56
User: wibbel4
Functions: echo ls read rm
-2

Old drive with lots of music or unsorted drive? This command will play all mp3 files in a folder and after playing one song or pressing q, it will ask you if you want to delete the file.

ls -d .??*
2013-12-17 19:06:30
User: pydave
Functions: ls
Tags: bash glob
2

You can omit the -d to see what's inside directories. In that case, you may want -a to see dotfiles inside those directories. (Otherwise you don't need -a since you're explicitly looking at them.)

ls -ls -tr | tail
ls -al | awk '/^-rwx/ {print $9}'
find ~ -type f -size +500M -exec ls -ls {} \; | sort -n
2013-11-17 13:13:14
User: marcanuy
Functions: find ls sort
Tags: size find
-1

Find all files larger than 500M in home directory and print them ordered by size with full info about each file.

find *.less | xargs -I {} lessc {} {}.css && ls *.less.css | sed -e 'p;s/less.css/css/' | xargs -n2 mv
while true; do ls -lah && sleep 1; done
2013-10-20 07:16:49
User: exolon
Functions: ls sleep
0

This one works without an external program (watch). Witch is not await able all the time. HINT: use CTRL + C to exit the loop.

ls -R | grep -v skipme | xargs rm -Rf
2013-10-18 08:11:39
Functions: grep ls rm xargs
Tags: delete rm
-11

This command will delete all files and folders except 'skipme'. it could be a file or a folder.

ls -lR | less
watch --interval 1 ls -lah
2013-10-16 10:41:15
User: c0r3dump3d
Functions: ls watch
-1

Use this command if you want to control the size of the files in human readable, every one second.

ls -l `find . -maxdepth 1 -type l -print`
find . -name '*pdf*' -print0 | xargs -0 ls -lt | head -20
2013-10-03 21:58:51
User: fuats
Functions: find head ls xargs
1

Sorts by latest modified files by looking to current directory and all subdirectories