- Published on
ls command-display the content and attribute information in the specified working directory
Jonas
2 min read
The ls command is one of the most commonly used commands under Linux. The ls command is the abbreviation of the English word list, just like the meaning of the English word list, its function is to list the contents and related attribute information in the specified directory.
By default, the ls command will list the contents of the current directory. With the parameters, we can do more things with ls. As the most basic and frequently used command, it is necessary for us to figure out the usage of the ls command, so let's take a look!
Syntax:
ls [options] [file]
Command parameters
-a | Show all files and directories (including hidden files starting with ".") |
-l | Use long format to list file and directory information |
-r | Display files in reverse order (by default in alphabetical order) |
-t | Sort by last modification time |
-A | Same as -a, but does not list "." (current directory) and ".." (parent directory) |
-S | Sort by file size |
-R | List all subdirectories recursively |
Example
List all files (including hidden files):[root@linuxstar ~]# ls -aList the detailed information of the file:
[root@linuxstar ~]# ls -lList all directories under the root directory (/):
[root@linuxstar ~]# ls /List all files in the current working directory whose names start with "s":
[root@linuxstar ~]# ls -ltr s*List detailed information of all directories and files in the /bin directory:
[root@linuxstar ~]# ls -lR /binList all files and directories in the current working directory and sort them by file size:
[root@linuxstar ~]# ls -AS