ls (list directory contents)
This command lists the contents of the current working directory. The command's output should be colored, which makes it easy to distinguish different types of files. If the output is not colored on your system, try adding the following →alias definition to your ~/.bashrc configuration file:
alias ls=`ls --color'
If you want some additional information on the files and directories listed by ls, try using the options -l (“long”) and -h (“human-readable”), for example:
ls -lh /
This will generate output similar to:
drwxr-xr-x 2 root root 4.0K May 23 15:46 bin
drwxr-xr-x 3 root root 4.0K May 13 01:29 boot
drwxr-xr-x 14 root root 3.4K May 24 11:27 dev
From left to right, the long listing of ls shows:
- The file's (or directory's) access permissions. The first character of the permissions string denotes the file type: d = directory, l = symbolic link, - (dash) = regular file, etc.
- The number of hard links to the file (see →ln).
- The file's owner.
- The file's group.
- The file's size in bytes. If you specify the -h option, a more user-friendly unit such as kilobytes or megabytes will be used.
- The date and time of the file's last modification.
- The file's name.
If you provide the option -t, ls will sort the directory listing by modification time. The default sorting is alphabetical by file name. Finally, the option -a (“all”) makes ls list hidden files, which are ignored by default. These are files that begin with a dot, for example .config. Linux uses them for configuration purposes. You'll find a lot of hidden files in your home directory.