Welcome guest


ls - List Directory

Quite often you will want to look at the contents of your directories to see what files you have. You might want to see how large those files are, or when they were created. You might also want to see what files and directories are located in other directories. The command that allows you to do this is the ls (list directory) command.

Syntax

eos% ls
eos% ls pathname

ls also accepts the following dash options:

-l lists the contents in long format (all information, size, date, owner, etc.)
-a lists ALL files, even "." (dot) files
-al lists ALL files in long format

Example 1

If your current working directory was your home directory, how would you list the contents of your home directory?

ls on the File Tree

Ask yourself:

Q: What am I doing? A: Listing the contents of a directory.
Q: How do I do that? A: Using the ls command.
Q: What are the path names? A: I am in my home directory, I want to list the contents of my home directory.

 

ls in the Terminal



Notice that in this example, the dot files do not show up in the listing. You must use a dash option (specifically -a) for that to occur. You will see that in the next example.

Example 2

If your current working directory was your home directory, how would you list all the contents of your home directory, including dot files?

Another Example of ls on the File Tree

Ask yourself:

Q: What am I doing? A: Listing all the contents of a directory.
Q: How do I do that? A: Using the ls command.
Q: What are the path names? A: I am in my home directory, I want to list the contents of my home directory.

 

ls on the Terminal Example 2



In this listing you might notice the two files .. and . at the top. As mentioned earlier when we were discussing pathnames, these stand for the directory above the current working directory, and the current working directory, respectively.

Example 3

If your current working directory was your home directory, how would you list the contents of your home directory?

 

ls with the File Tree

Ask yourself:

Q: What am I doing? A: Listing the contents of a directory.
Q: How do I do that? A: Using the ls command.
Q: What are the path names? A: I am in my home directory, I want to list the contents of my home directory.

 

 

Notice in the listing below that the dot files are not shown. This is because you did not use the -a option. If you wanted to see all the files in long format you would have to combine the -l and -a options, like this: -al

ls in the Terminal