
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
How to list the directory content in Linux?
In the Linux operating system, there are two commands available to list the directory contents.
- ls (list) command
- dir (directory) command
Listing the contents of the file using ls command.
ls (list) – the ls command is used to list the directory contents in the Linux system. By default, the ls command displays the content of the current directory. The ls command is also available in EFI (Extensible Firmware Interface) shell.
Syntax
The general syntax of the ls command is as follow −
$ ls [OPTION]... [FILE]...
Brief description of option available in the ls command.
Sr.No. | Option & Description |
---|---|
1 | -a, --all Display all files including hidden files |
2 | --author Display author of each file with -l option |
3 | -B, --ignore-backups Do not display backup file |
4 | -d, --directory List only directories, not their contents |
5 | -l Display long listing format |
6 | -N, --literal Display entry names without quoting |
7 | -R, --recursive Display subdirectories recursively |
8 | -x Display list by lines instead of by columns |
9 | -Z, --context Print any security context of each file |
10 | --help Displays a help message and then exits. |
11 | --version Output version information and exit |
To display the current directory content in the Linux/Unix system, we use the ls command as shown in below.
$ ls
Here, we will display the list contents of a directory in long listing format as well as the author of each file, date, and owner permission using -l option with the ls command in the Linux system.
vikash@tutorialspoint: ~ $ ls -l shadow total 16 -rw-rw-r—1 vikash Vikash 34 Dec 26 19:28 file.txt -rw-rw-r—1 vikash Vikash 34 Dec 26 19:28 file.txt -rw-rw-r—1 vikash Vikash 34 Dec 26 19:38 file.txt drwxrwxr-x2vikash vikash 4096 Dec 26 19:47 snow
dir (directory) – the dir command is used to list contents of the directory but the output of the dir command is not colored like ls command. In the Windows operating system the dir command is also used to list the directory contents. By default, the dir command lists the contents of a directory in a column and shorted vertically. The command is available in CLI (command line interface).
Syntax
The general syntax of the dir command
$ dir [OPTION]... [FILE]...
Brief description of options available in the dir command.
Sr.No. | Option & Description |
---|---|
1 | -a, --all Display all files including hidden files |
2 | --author Display author of each file with -l option |
3 | -B, --ignore-backups Do not display backup file |
4 | -d, --directory List only directories, not their contents |
5 | -l Display long listing format |
6 | -N, --literal Display entry names without quoting |
7 | -R, --recursive Display subdirectories recursively |
8 | -x Display list by lines instead of by columns |
9 | -Z, --context Print any security context of each file |
10 | --help Displays a help message and then exits. |
11 | --version Output version information and exit. |
To display current directory contents, also we use the dir command. The output of the dir command is not colored whereas the output of the ls command is colored.
$ dir
- Related Articles
- How to list the directory content in PowerShell?
- How to change the shell working directory in Linux?
- Linux – How to find the files existing in one directory but not in the other directory?
- How to display the current working directory in the Linux system?
- Copy a directory to an existing directory Linux?
- How to create a new directory in Linux using the terminal?
- How to Get the most recent file in a directory in Linux?
- Java Program to get the content of a directory
- How to list directory tree structure in python?
- How to display a directory list in HTML?
- How to change file or directory permission in Linux/Unix?
- How to unzip all zipped files in a Linux directory?
- How to find the most recent file in a directory on Linux?
- How to list the hidden files in a directory in Java?
- How to Create a Shared Directory for All Users in Linux?
