What is the ls command?
The
ls
command is a command-line utility for listing the contents of a directory or directories given to it via standard input. It writes results to standard output. The ls
command supports showing a variety of information about files, sorting on a range of options and recursive listing.How to show the contents of a directory
To show the contents of a directory pass the directory name to the
ls
command. This will list the contents of the directory in alphabetical order. If your terminal supports colours you may see that file and directory listings are a different colour.How to show hidden files and folders
To show hidden files and folders pass the
-a
option to ls
this willHow to append file types to listings
To append an indicator of the file type to a directory listing pass the
-F
option.
The following characters are appended based on this option:
/
indicates a directory@
indicates a symbolic link|
indicates a FIFO=
indicates a socket>
indicates a door- nothing is shown for regular files
How to show a long listing
To show a long listing pass the
-l
option to the ls
command. This will output detailed information on the directory listing.How to sort by size
To sort a directory listing by name pass the
-S
option. In the following example this is combined with the -l
option to show a long listing.How to sort by modification time
To sort by modification time pass the
-t
option. This causes the output to show the most recently modified files or folders at the top of the listing. In the following example this is combined with the -l
option to show a long listing.
To show the last edited file in a directory the
ls
command can be combined with head
How to sort by access time
To sort by access time pass the
-u
option. This causes the output to show the most recently accessed files of folders at the top of the listing. In the following example this is combined with the -l
option to show a long listing.How to show file size in human readable format
To show file size in human readable format pass the
-h
option. This causes the file size output to be shown in human readable format.How to display one file or folder per line
To display one file or folder per line pass the
-1
option.How to show a recursive listing
To display a recursive listing pass the
-R
option. This causes folders and files within a folder to be listed.
0 comments:
Post a Comment