The ls
command in Linux is used to display the contents of the current working directory in the terminal. By default, the ls
command displays the names of files and subdirectories in the current directory.
The ls
command in Linux is used to display a list of files and directories in a specified directory. It is one of the most basic and frequently used commands in Unix-like operating systems. Here are the basic functions and parameters of the ls command:
File and directory list: by default, the ls command displays the names of all files and folders in the current directory.
Displays a detailed list including permissions, owner, file size, and modification date.
-l
to display file sizes in an easy-to-read format (e.g. KB, MB).ls:
Displays a list of files and folders in the current directory.ls -l:
Shows a detailed list of files and folders.ls -a:
Shows all files, including hidden files.ls -lh:
Shows a detailed list with convenient file sizes.The ls command is useful for navigating the file system and getting information about the contents of directories.
Some common options for the ls
command include:
-l
: displays a long output format that includes additional information about each file, such as permissions, owner, group, size, creation date, etc.
-a
: displays all files, including hidden files starting with a dot.
-h
: displays file size in human-readable format (e.g., "1K", "2M", etc.).
-t
: displays files in order of most recent modification, starting with the most recent.
-r
: displays files in reverse order.
An example of using the ls
command with the -l
option:
$ ls -l
total 0
drwxr-xr-x 2 user user 6 Feb 28 14:25 dir1
-rw-r--r-- 1 user user 0 Feb 28 14:25 file1.txt
-rw-r--r-- 1 user user 12 Feb 28 14:25 file2.txt
In the above example, each line represents information about a file or directory in the current directory, including permissions, number of hard links, owner, group, size, date last modified, and file name.