- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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