lsd: Modern and better alternative for ls command in Linux
The Linux lsd command is a utility that allows users to view the contents of a directory in a colored and easily readable format. It is similar to the ls
command, but with additional formatting and options for sorting and filtering the output.
Installing lsd
tool in Linux
lsd is not a built-in command in most Linux distributions, so it may need to be installed first. It is available in the repositories of most distributions, so it can be installed using the package manager. For example, on Debian-based systems, you can use the apt
command to install lsd:
$ sudo apt update sudo apt install lsd
$ sudp snap install lsd
or, you can download debian package from here and install it with dpkg
as follows:
$ wget https://github.com/Peltoche/lsd/releases/download/0.23.1/lsd-musl_0.23.1_amd64.deb
$ sudo dpkg -i lsd-musl_0.23.1_amd64.deb
On Fedora, CentOS, or RHEL, you can use the dnf
command to install lsd as follows:
$ sudo dnf install lsd
On Arch Linux or Manjaro, you can use the pacman
command to install lsd as follows:
$ sudo pacman -S lsd
Basic Usage of lsd
command
To list the contents of a directory with lsd, you can simply type lsd
followed by the path to the directory. For example, to list the contents of the current directory, you can use the following command:
$
lsd
To list the contents of a specific directory, you can specify the path as an argument. For example:
$
lsd /etc
By default, lsd displays the files and directories in the specified directory in a long format, with the following columns:
- Name: the name of the file or directory
- Type: the type of the file or directory (e.g. file, directory, symbolic link, etc.)
- Size: the size of the file in bytes
- Modified: the date and time when the file was last modified
Options and Flags
There are several options and flags that can be used with lsd to customize the output and behavior of the command. Some of the most useful options are:
-1
: Display the contents of the directory in a single column, rather than in the long format.
-l
: Display the contents of the directory in a long format, similar to the default behavior of lsd.
-h
: Display file sizes in a human-readable format, using units such as MB, GB, etc. rather than in bytes.
-A
: Do not include the "." and ".." directories in the output.
-a
: Include hidden files and directories in the output.
--color
: Enable or disable color output. This option can be followed by always
, never
, or auto
to specify the behavior.
--sort
: Specify a criterion for sorting the output. The available criteria are name
, size
, type
, and modified
.
For example, to display the contents of the current directory in a single column, sorted by size, with human-readable file sizes, you can use the following command:
$ lsd -1 --sort size -h
Conclusion
In conclusion, the Linux lsd command is a useful utility for viewing the contents of a directory in a formatted and readable manner. It provides several options and flags for customizing the output and sorting the results, making it a powerful tool for navigating and managing files and directories in the command line.