Breadcrumbs 
Learning >> Documentation >> File System >> Listing files
 
Recent News
We're No 1!
We've reached the top! (Of Google!)
[ more ]
Firefox 3 Download Day
Firefox 3 has been officially released and is looking to set a world record for the most downloaded piece of software in 24hrs.
[ more ]
SSL Renewed
SSL cert has been renewed by the admin team.
[ more ]
Listing Files
Listing Files

ls [option] [file]

Probably the most used command of them all, the "ls" command (stands for "list") allows you to list the contents of a directory. While it all sounds very trivial, this is your main method for navigating through the system.

roryd@frink:~$ ls
backup compsoc include mbox dev it
mp3 public_html http_logs mail personal resources

Here we get a listing of all files in my home directory. But we can't see which are directories and which are files.

roryd@frink:~$ ls -F
backup/ compsoc/ include/ mbox dev/ it/
mp3/ public_html/ http_logs/ mail/ personal/ resources/

Ah now this is a little better, the directories have a slash at the end of them, the files (only one in this case, mbox) have none.

roryd@frink:~$ ls -l
total 3216
drwx------ 7 roryd users 4096 Aug 11 01:35 backup
drwx---r-x 5 roryd users 4096 Jun 11 21:25 compsoc
drwx------ 6 roryd users 4096 Aug 9 18:05 dev
drwxr-xr-x 2 root root 4096 Feb 3 2003 http_logs
drwx-----x 2 roryd users 4096 Jun 19 20:21 include
drwx--xr-x 3 roryd users 4096 Feb 19 15:27 it
drwx------ 6 roryd users 4096 Aug 19 13:37 mail
-rw------- 1 roryd users 3219839 Jun 26 15:23 mbox
drwxr-xr-x 2 roryd users 12288 Jun 30 11:58 mp3
drwx------ 3 roryd users 4096 Aug 14 14:48 personal
drwx--x--x 21 roryd users 4096 Aug 10 03:01 public_html
drwx---r-x 6 roryd users 4096 Jun 30 11:56 resources

The "-l" argument gives a more detailed listing. This might all look very scary now, but you'll understand it all pretty quickly. The two highlighted above are the owner of the file and the date last modified. But what's the one before the date?

roryd@frink:~$ ls -lh mbox
-rw------- 1 roryd users 3.1M Jun 26 15:23 mbox

It's the size of the file. Here we use one more argument, a "h" to give us a "humanly readable" file size. This time we've also added the file name we want to check the listing of, and we find it is 3.1 Megabytes. So as well as being able to list the contents of directories, the "ls" command can also give us the attributes of any file.

Finally there are hidden files in your home directory. They are used for configuring the various programs you learn to use as you develop a broader knowledge of what you can do. To see the one's that are created by default by the system or us for you:

defaultuser@frink:~$ ls -A
.addressbook .bash_profile .mysql_history .pinerc public_html
.news_time .viminfo .alias .bashrc Mail .bash_history mail
.bash_logout .cshrc mbox

You'll notice the hidden files have a "." before them. You don't have to know what any of these do, but just be aware they are there. One of the most common config files is the ".bashrc" which you'll learn more about in Configuring the Shell. Now lets find out how to get copy and move files.