Generally ls is used just for listing the entries in a directory. But there is more to ls. If you look up the man page for 'ls' or 'info ls', then you can begin to understand the varieties of things 'ls' is capable of.
Let's work through few of the things you can do with ls.
Show all the files including [.] files: ls -a
Sort by last modified date: ls -t
Show detailed info (permission, owner, date etc): ls -l
Show filesize in KB or MB instead of bytes: ls -lh
Show files starting with character a only: ls a*
Show files without 'a' as the first letter: ls [^a]*
Note the above command will list all the files recursively if there are directories in the current path.
ls -d [^a]* -d will restrict the display to the base directory
Multiple excludes ls -d [^abc]*
will display all the files except those starting with a b and c.
More information can be found if you look into 'info ls'
Comments on this hack
Showing messages 1 through 3 of 3.
use an alias to list just directories
2006-01-24 10:43:23
mumblingmutant
[View]
make a new command alias to just list directories
alias dir='ls -lah | egrep "^d"'
ls, awk and grep oh my
2004-02-25 14:00:53
gruggni
[View]
ls -lh | awk '{print $9,"=", $5}' | grep '[0-9]M'
ls -l generates date in column format thus we use awk's column printing:
$9 is filename
$5 is filesize
$6 is month
grep is used to find files in the meg range, i.e. large files.
make a new command alias to just list directories
alias dir='ls -lah | egrep "^d"'