ls

What is ls?

In computing, ls is a command-line tool to list computer files in Unix and Unix-like operating systems. compared to Windows, a very similar command-line tool is dir

How to use ls

# syntax : "options" and "directory" is optional
ls <OPTIONS> <DIRECTORY> 

##### basic example of listing files
ls # lists all files/directories of the current directory your in 
ls /etc # list all files of the directory /etc
ls /root/Downloads # list all files of the directory /root/Downloads

##### examples with parameters
ls -a /root # show hidden files (.bashrc for example) of the root - home directory
ls -l /root # show all files/directories (not the hidden ones) in the directory /root with the permissions, root owner, and group owner
ls -i /root # shows the inode (index number) of the file/directory
ls -r /root # reverse sort the files/directories in the directory root
ls -R /root # list the files recursive (note that the use of tree is better to create a good overview)

##### how to combine ls with "pipe"
ls /root | grep -i doc* # list all directories/files in the root directory that start with "doc" (Capital letters don't matter now) and end on anything
ls /etc | grep -i -e sql -e apache* # list all files/directories that have the name sql or apache in them.

Last updated