The ls command's -l option prints a specified directory's contents in a long listing format. If no directory is specified then, by default, the contents of the current directory are listed.
The output first displays total, which indicates the total size in blocks of all the files in the listed directory. It then displays eight columns of information for each file in the listed directory. Below are the details for each column in the output:
Column No.
Example
Description
1.1
d
File type (see table below)
1.2
rwxr-xr-x
Permission string
2
3
Number of hard links
3
root
Owner name
4
root
Owner group
5
4096
File size in bytes
6
Apr 21 03:44
Modification time
7
acpi
File name
File Type
The file type can be one of any of the following characters.
Character
File Type
-
Regular file
b
Block special file
c
Character special file
C
High performance ("contiguous data") file
d
Directory
D
Door (special IPC file in Solaris 2.5+ only)
l
Symbolic link
M
Off-line ("migrated") file (Cray DMF)
n
Network special file (HP-UX)
p
FIFO (named pipe)
P
Port (special system file in Solaris 10+ only)
s
Socket
?
Some other file type
List the Ten Most Recently Modified Files
The following will list up to ten of the most recently modified files in the current directory, using a long listing format (-l) and sorted by time (-t).
ls -lt |head
List All Files Including Dotfiles
A dotfile is a file whose names begin with a .. These are normally hidden by ls and not listed unless requested.
For example the following output of ls:
$ ls
bin pki
The -a or --all option will list all files, including dotfiles.
$ ls -a
. .ansible .bash_logout .bashrc .lesshst .puppetlabs .viminfo
.. .bash_history .bash_profile bin pki .ssh
The -A or --almost-all option will list all files, including dotfiles, but does not list implied . and ... Note that . is the current directory and .. is the parent directory.
$ ls -A
.ansible .bash_logout .bashrc .lesshst .puppetlabs .viminfo
.bash_history .bash_profile bin pki .ssh
List Files
The ls command lists the contents of a specified directory, excluding dotfiles. If no directory is specified then, by default, the contents of the current directory are listed.
Listed files are sorted alphabetically, by default, and aligned in columns if they don’t fit on one line.
$ lsapt configs Documents Fonts Music Programming Templates workspace
bin Desktop eclipse git Pictures Public Videos
# display the files and directories that are in the current directoryprintf"%s\n" *
# display only the directories in the current directoryprintf"%s\n" */
# display only (some) image filesprintf"%s\n" *.{gif,jpg,png}
To capture a list of files into a variable for processing, it is typically good practice to use a bash array(opens new window):
files=( * )# iterate over themforfilein"${files[@]}";doecho"$file"done
List Files in a Tree-Like Format
The tree command lists the contents of a specified directory in a tree-like format. If no directory is specified then, by default, the contents of the current directory are listed.