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 - 454 results
mplayer $(ls -t /tmp/Flash*|head -1)
2009-02-19 04:38:40
User: mulad
Functions: ls
1

Many sites with Flash video players will download video files to /tmp on Linux, with temporary filenames like "FlashbGTHm4". These will often play in mplayer, totem, or other movie playing software. You must first navigate to a video page, let it start loading, and then pause playback.

ls *(m-1)
ls **/fred*~*junk*/*
ls -ld **/*(/^F)
ls |while read line ; do mpg321 -w "$line.wav" "$line" ; done
ls -ad .*
2009-02-18 15:22:39
User: osantana
Functions: ls
-3

List only hidden files (or directories). You also can use:

ls -lad .*
ls -d */
2009-02-18 14:00:42
User: starchox
Functions: ls
8

This command would be useful when it is desirable to list only the directories.

Other options

Hidden directory

ls -d .*/

Other path

ls -d /path/to/top/directory/.*/

Long format:

ls -ld */
ls -l !* | /usr/bin/grep '^d'
ls -lrt
2009-02-17 19:51:08
User: guidouil
Functions: ls
2

Show you the list of files of current directory sorted by date youngest to oldest, remove the 'r' if you want it in the otherway.

find . -size +10240k -exec ls -l {} \; | awk '{ print $5,"",$9 }'|sort -rn > message.out
2009-02-17 19:39:56
User: rommelsharma
Functions: awk find ls
5

This command specifies the size in Kilobytes using 'k' in the -size +(N)k option. The plus sign says greater than. -exec [cmd] {} \; invokes ls -l command on each file and awk strips off the values of the 5th (size) and the 9th (filename) column from the ls -l output to display. Sort is done in reversed order (descending) numerically using sort -rn options.

A cron job could be run to execute a script like this and alert the users if a dir has files exceeding certain size, and provide file details as well.

ls -1 . dir2 dir3|sort|uniq -d
2009-02-17 16:29:03
User: tlknv
Functions: ls
1

cat file1 file2 file3|sort|uniq -d

finds the same lines in several files, especially in files with lists of files.

ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"
2009-02-17 14:46:01
User: stinger
Functions: grep ls whatis xargs
4

Get simple description on each file from /bin dir, in list form, usefull for newbies.

find / -type f -size +25M -exec ls -lh {} \; | awk '{ print $5 " " $6$7 ": " $9 }'
2009-02-16 12:27:48
User: darkon1365
Functions: awk find ls
1

Very useful for finding all files over a specified size, such as out of control log files chewing up all available disk space. Fedora Core x specific version.

ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
2009-02-15 20:43:21
Functions: grep ls sed
53

Prints a graphical directory tree from your current directory

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
2009-02-13 19:20:54
User: iArno
Functions: awk ls
6

Do ls with permissions written in octal form.

ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''
2009-02-09 22:32:01
User: scw
Functions: grep ls sed
-3

Shows the current directory and those below it in a simple tree structure. Recommended use:

alias lt='$command_above'

ls -l | egrep ^d
2009-02-08 22:21:55
User: ergut
Functions: egrep ls
3

This command would be useful when it is desirable to list only the directories. 'egrep' chooses only the lines that begin with 'd'.

while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
ls -al /proc/<PID>/fd
2009-02-07 22:57:03
User: al3x
Functions: ls
1

Useful for examining hostile processes (backdoors,proxies)

find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
ls -la | awk '$3 == "oracle" || $3 == "root" {print $9}'
ls -la | awk '{print $5, " " ,$9}' | sort -rn
for i in $(ls /the/path); do du -hs /the/path/$i; done
strace -f -s 512 -v ls -l
2009-02-06 02:45:33
User: mkc
Functions: ls strace
5

strace can be invaluable in trying to figure out what the heck some misbehaving program is doing. There are number of useful flags to limit and control its output, and to attach to already running programs. (See also 'ltrace'.)