Sorting the Output#Īs we seen before, by default ls command shows output in alphabetical order. Use -a option to display all files including hidden files. In Linux, a hidden file is any file that begins with a dot (. Show Hidden Files#īy default, the ls command will not show hidden files. You can change the file owner using the chown command.Īfter that is the last file modification date and time. To show the size of file in human readable format use -h option. The next two fields root root are showing the file owner and the group, followed by the size of the file ( 597 bytes).
The number 1 after the permission characters shows the number of hard links to this file. In our last example, rw-r–r– means that the user can read and write the file, and the group and others can only read the file.
Below characters are used for permissions: As per your requirement you can change the file permissions using chmod command. Out of nine, first three characters are for user, next three for the group and last three for others. Values for other file types are as follows:Īfter that, nine characters are displaying the permission of the file. In our example, the first character is – which indicates a regular file. In above output, the first character shows the file type. Following details will be displayed when long listing format used.įor example, to view details of /etc/hosts : You can use -l option with ls to show files in long listing format. Long Listing Format#īy default the ls command shows only the names of the files and directories. Make sure the user in which you are logged in should have read permission otherwise it will show the error message, ls can’t open the directory. You also can pass the multiple directories path in a single command separated by space: For example, to list the content of the /etc directory you would type type: If you want to list the content of a specific directory, pass the path to the directory as an argument with ls command. If no options or arguments used with ls command, it will show a list of the names of all files in the current working directory:īy default, the files will be listed in alphabetical order.
How to Use the ls Command#įollowing is the basic syntax for the ls command: This tutorial explains how to use the ls command with examples. By default ls utility is installed on all Linux distributions. It is not a universal "Unixism", which explains why the POSIX requirement is worded that way.The ls is a Linux shell command, used to list information about files and directories within the file system. I just tried Solaris 10 its ls also has no such behavior. have no special operating system status just ls treats them specially. The dot hides items whose presence is expected and uninteresting, not whose presence is intended to be secret.ĭotted directory entries other than. If you have read access to another user's directory, you can list their hidden files. It conceals things that we normally don't want to see, like the. The hiding of files that begin with dot is not a security mechanism it shouldn't be connected to security contexts. A script developed as non-root will change behavior when run as root.
There are good reasons not to have the behavior of programs influenced by global variables, like which user ID is in effect. "Filenames beginning with a ( '.' ) and any associated information shall not be written out unless explicitly referenced, the -A or -a option is supplied, or an implementation-defined condition causes them to be written."īeing root is evidently not considered a condition which causes hidden files to be written by the GNU Coreutils implementation of ls that is commonly packaged in Linux distros.