Training Missions

Missions: Using command line shell

Using ls for listing directory contents

ls: List directory contents

1. List files using ls with no options:

$ ls

ls command with no option will list files and directories in bare format and you won't be able to view details like file type, size, modification date, permissions etc.

2. List files using -l option:

$ ls -l

The ls command with option -l (i.e. ls -l) will list files and directories along with their size, modified date and time, owner of the file, and permissions. It will look something like this:

    drwxr-xr-x   2 root root  4096 Oct 11 00:20 bin

3. View hidden files:

$ ls -a

The ls command with option -a (i.e. ls -a) will list all files, including hidden files (whose names start with '.').

There are many other options available. For more options, type ls --help in your shell and you'll get a list of available options along with a short description for each option. (if you are using OS X or zsh man ls)


What does the command ls do when used with the -s argument?

$ ls -s
print the allocated size of each file, in blocks.
list subdirectories recursively.
reverse order while sorting.
It produces an error message.