Ls is used to list your files inside of a bash terminal. It’s like clicking through folders but with a higher customization capability. The overall concept of the ls function includes options and a directory.
ls [options] [directory or file path]
The basic command lists all files.
To list all files including hidden files, use option a.
To list all files of a specific directory you have to include the path at the end of the ls command. For example, to view all files in your Downloads folder, use the command:
The same logic is possible for listing specific files. An important symbol therefore is *. Let’s use it to list all html files inside the directory Downloads.
The ls command takes always your current location as the starting point. If you want to force it to start from your home directory use the symbol ~. Now let’s say in your home directory is a folder called Documents and inside is a folder called lib, and your terminal is currently pointing somewhere else. To list all files inside, type:
On default you will just see the names of all files. If you are interested in a advanced view, including the file rights and last edited datetime, use the option l:
To sort all files by their last edited date time, use the option t:
Combining both options togither is also possible. Just add them together without any additional spacing or symbols. For example listing all files in an advanced view and sorting the by their last edited date time is the option lt:
Now the last option chain ltr means to list all files in an advanced view, sort them by their last edited date time in reverse order, so ascending. So include r on your command and type:
That’s all you need for your usual usage. For more options you can read through the manual with the command:
If you liked my article or I have forgot to mention some functions, please leave a commend down below!