In the terminal, “ls” is one of the most important commands for listing folder and file names. The LS command can still be improved a lot. How you can get more color and power in “ls”, we show you here for Ubuntu-based Linux distributions such as Ubuntu, Linux Mint and Pop! _OS.
The first tips show what you can do with the ls command. The last two tips show you how to make the ls command more colorful.
List hidden files and directories
The terminal command “ls” does not display any hidden files or directories by default. However, you can change that by adding the command line option “-a” (all) at the end.
Entries “. “And” .. “do not display
The command “ls -a” also shows the entries for the current and previous directory at the top of the list, which are marked with a period (.) And two consecutive periods (..). If you want to save yourself the display of these entries, simply use the command line option “-A” (almost-all).
Show files and directories in reverse order
By default, “ls” displays files and directories in alphabetical order. You can display it in reverse order with the command line option “-r” (reverse).
Show output sorted by date
The “ls” command lists files and directories sorted by date using the “-t” (time) command line option. If you want to have the elements with the most recent date listed below, use “-tr” (time, reverse).
View files / folders with details
The “-l” (long) command line option lists files and directories with permissions, owners, file size, date, and file name.
Show file sizes in megabytes instead of bytes
By default, the “ls -l” command displays file sizes in bytes. But if you prefer to view these in megabytes, gigabytes, etc., you can also use the command line option “-h” (human-readable).
Show only file names with file sizes
While “ls” only shows file / directory names and “ls -l” a lot of information with file size, you can only list the names with file size. To do this, use the command line option “-s” (size). We also recommend “-h” (human readable).
List directories first
The terminal command “ls” lists folders and directories mixed in alphabetical order. If you want to display the folders first, use the command line option “–group-directories-first”.
List subdirectories recursively
The “ls” command can also display the contents of subdirectories. Simply use the command line option “-R”.
What else is possible with “ls”?
If you want to see all available command line options of “ls”, type the command in the terminal
man ls one. Scroll down the list to see everything. With the “q” key you close the overview again.
Nicer colors for “ls”
The terminal command “ls” shows some entries in color by default. But there is much more that can be done: We recommend the Monokai theme for the Gnome Terminal. The Gnome Terminal is preinstalled in Ubuntu, Linux Mint and Pop! _OS, for example. One more thing in advance: The theme changes the terminal colors as a whole, not just for the LS command. But that is intentional.
Open the terminal by using the keyboard shortcut [Strg] + [Alt] + [T] presses. For this you need the small tool dconf, which you can install with the following terminal command:
sudo apt install dconf-cli
Enter your password and confirm with [Enter]. The tool may already be preinstalled with you. You also need the tool “git”, which you install as follows:
sudo apt install git
Enter your password and confirm with [Enter]. Then you clone the associated package source (repository) of the Monokai theme with the command:
git clone https://github.com/0xComposure/monokai-gnome-terminal
The folder “monokai-gnome-terminal” with the required content has now been created in your “personal folder”. Now switch to the folder inside the terminal with the following command:
Then you install the terminal theme with the command:
You will probably now see the message “No profile found“. Confirm the request by “yes“And confirm with Enter to create a new profile in the terminal. Linux now asks which terminal profile should be selected. Select the number here “Monokai“And confirm with [Enter]. Linux asks if you are sure to overwrite the selected profile. Confirmed again with “yes” and [Enter]. Closes the terminal. In your “personal folder” you can now delete the “monokai-gnome-terminal” folder because it is no longer needed. Then open a new terminal to see it in the colors of the Monokai theme.
Back to the old terminal theme
If you want to undo the changes, click the right click in a terminal window and select “ideas” out. Next “Profile“You click on the plus symbol (+) and enter a name for the new profile, for example “Standard“, And confirmed with [Enter]. The new profile contains the standard colors. Click on the new profile “Standard” and then next to the text “Standard” on the small arrow pointing downwards. Elects “Set as default” out. Close the window.
“Exa” is the better “ls”
I don’t feel like giving command line options all the time when listing files / directories. I also want an even more colorful display of the items listed. For example, when I enter the “ls” command in my terminal, the output automatically looks like this:
To get this view, use the command line program “exa” and create an “alias” for “ls” including the desired command line options. And this is how it works:
First install the package manager “cargo”, which can then be used to install “exa”. The associated command is:
sudo apt install cargo
Then you install “exa” with the command:
cargo install exa
Now you open your home directory with a file manager. Show you all the hidden files. This usually works with the key combination: [Strg] + [H]. Now creates a backup copy of the file “.bashrc“.
Opens the original file “.bashrc“With a text editor and inserts the following line as shown in the screenshot above:
Look further down in the file for the line that starts with “alias ls“Begins. Put a hash symbol (#) in front of this line to comment it out. Add the following line above:
alias ls=”exa -l –color=always –group-directories-first‘
Saves the file and closes all open terminals. Opens a new terminal. If you now enter “ls”, you should see the view as I showed it above. Especially in combination with the Monokai theme, the terminal and the LS command now look really good.