ls command is one of the most commonly used tools in Unix. You simply cannot underestimate the importance of being able to confirm exactly what files and directories are available to you, and ls does its job perfectly. Most of recent Linux and Unix distros support ls colorized output which is shown above.
ls – basic syntax
Like many commands in Unix, ls expects you to specify a file or directory name for it to inspect:
$ ls file1 dir2
This command above will list (check if it exists) file called file1, and will also show contents of the dir2 directory (if dir2 exists).
The most basic way to use ls command is to simply make it list files and directories in your current directory. You don’t need to specify any parameters for it, just type the command itself.
In this example below, I’m in ~/proj directory (~ sign simply means my home directory, so with homedir /home/greys the ~/proj means /home/greys/proj) where some of my Linux-based projects are:
Symbolic links can be inspected to show destination files using pretty standard ls -l combination:
List SELinux Contexts with ls
ls command can be used with the -Z parameter to show file contexts in SELinux enabled systems:
Such output allows you to confirm the type of each directory entry, the access permissions, the number of links to this file, the ownership (user and unix group which own it), size in bytes, date of the last modification, and, finally, the name of the directory entry.
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!