Output of most of the commands in Linux can be modified by using options/switches. ls command is also not an exception. ls command is used to list the contents of a directory. It has lots and lots of switches to customize its output.
Switches are case sensitive. Switches can be appended after the command with - sign. Multiple switches can be used in combination.
This post lists some more common switches for ls command.
Example : ls -la or ls -al
a : a switch is used to list all files (ie hidden files also)
A : same as a but excludes . And ..
l : for long listing. The default output format is
drwxr-xr-x 5 newevon newevon 4096 Nov 17 11:31 data.txt Description :
First columns shows permission. Initial d represents directory. First three characters represents permissions for owner, next three for group and last three for other users.
Here, r stands for read, w for write and x for execute.
Third column tells the user to which the file belongs.
Fourth column is group.
Fifth column is size of the file.
Sixth Columns shows the last modified datetime.
Seventh Column is the name of file.
--author : Prints the author name of each file.
b : Prints escape for non-graphic characters.
--block-size=M|K : List the size of files and directories in desired scale format. M stands for Megabyte, K for KiloByte.
B : Restrict BackUp files to show in the listing.
d : Display the information of directory itself instead of its contents.
g : Lists files and directories without their owner name.
h : Prints the size of files and folders in human readable format (In K,M and G units).
m : Lists contents of directory separated by comma.
r : Prints the contents of directory in reverse order.
R : Prints contents of directory and sub-directories recursively.
S : Prints contents sorted by size (Largest first). To sort in ascending order user with r switch.
group-directories-first : Lists directories before files.