ls is used to list out the contents of a specified directory. It provides useful information about the files such as permissions, owner, size, date modified, and more.
Basic Syntax
ls [options] [target]
Here, options are the various flags that can be used with the ls command, and target is the name of the directory whose contents you want to list. If no directory is specified, ls lists the contents of the current working directory.
Commonly Used Options
-
-l: This displays the contents of the directory in a long format, providing detailed information about the files. -
-a: This lists all files, including hidden files, in the directory. -
-h: This displays the file sizes in a human-readable format. -
-t: This lists the files in the directory based on the time they were last modified. -
-r: This reverses the order of the files listed. -
-S: This lists the files in order of size. -
-R: This recursively lists the contents of all subdirectories.
Useful Examples
-
ls: This lists the contents of the current working directory. -
ls -lah ~/.: This lists the contents of the user’s home directory in a long format with human readable file sizes and displays hidden files.
Leave a Reply