ls – List directory contents
ls [options] [files]
The ls command will list the files and directories within the current working directory (the directory you are currently in).
There are a few options you can use with ls, and the format, or syntax of the command is….
ls [options] [file]
>ls -l /home/rich/www
Lets break that down….
ls is the command
-l is the option which will give you a long listing format (which shows more info than just the file names – the owner, size, date last modified etc)
/home/rich/www is the directory we want to see a listing of (if you omit this part, ls will print the contents of the directory you are in).
Some useful options are -l, -a, -s, -h and -R
-l will give you a long listing (as explained above)
-a will show you ALL the files in the directory, including hidden files
-R will the subdirectories recursively, which means it will show all the directories and files within the specified directory.
-s will also show you the size of the files (in blocks, not bytes)
-h will show the size in “human readable format” (ie: 4K, 16M, 1G etc). Of course you must use this option in conjunction with the -s option.
You can combine as many of these options as you wish.
>ls -la /home
Lists ALL the files and directories in the /home directory, in the long listing format.
Lists ALL the files in the current directory (no directory was specified so it lists the contents of the current directory), and the size of the files/directories, written in ‘human readable’ format.
There are many more options for ls, but these are a few you may want to use. To see the total list of options for the ls command, you can type man ls at the prompt.
ls by last modified date?
or (for reverse, most recent at bottom):
ls -halt is for human readable, show hidden, print details, sort by date. –
Long listing format sorted by date/time:
$ ls -lt
drwxr-xr-x 2 user user 120 2011-08-17 18:14 Pictures
-rw-r–r– 1 user user 131 2011-08-17 18:07 todo.txt
drwxr-xr-x 2 user user 80 2011-08-17 16:52 Desktop
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Documents
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Downloads
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Music
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Public
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Templates
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Videos
The syntax is:
ls -lt | less
ls -lt ~/Downloads/ | less
alias l=’ls -lrth’
alias lt=’ls -Alhtr’