PUBLISHED ON: JULY 6, 2021
How to List Directory Contents in Linux
In Linux, dir
(directory), ls
(list) command already available to check the list of directory content but apart from this Linux provides vdir
(virtual directory) to list directory contents.
The vdir
command is used to list information about the files in the Linux/Unix operating system.
vdir
stands for the virtual directory.
- The
vdir
command is similar to ls -l -b
command.
- By default, files are listed in long format and special characters are represented by backslash escape sequences.
- It sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Syntax for Linux vdir command
The following is the syntax for vdir command in Linux.
vdir [OPTION]... [FILE]...
Linux vdir command Options
The following table contains a brief description of options available with the vdir
command.
Option |
Description |
-a, --all
|
It is used to display files having dot(.) in the start of name. basically a hidden file.
|
-A, --almost-all
|
do not list implied . and ..
|
--author
|
It is used to display the author of each file.
|
-B, --ignore-backups
|
It is used to ignore the listing of backup files.
|
-F, --classify
|
It is used to append indicator (one of */=>@|) to entries.
|
--file-type
|
likewise, except do not append '*'
|
-i, --inode
|
It is used to print the index number of each file.
|
-r, --reverse
|
It is used to list files in reverse order while sorting.
|
-R, --recursive
|
It is used to list subdirectories recursively.
|
--help
|
It is used to display help.
|
--version
|
It is used to print version information.
|
Example: Display hidden files in Linux
In the directory hope, a file .dubey.txt is available with dot(.) in the name. This file is a hidden file that cannot be shown without using -a or --all options in the vdir command but when we use these options then it is shown.
Example: Display author of the files with -l
In this example, by using vdir -l --author
command, we display file with owner details, group details, etc. See the output below.
Example: Display files excluding backup files ( ends with ~)
We know that backup files end with a ~ sign, like bfile.txt~ that is a backup file in the current folder and is visible by default. If we want to exclude these files then use -B or --ignore-backups options in the vdir command. See the output below.
Example: Display help and exit
In the above option table, only a few important options are given with a description but by using vdir --help
command you can explore more options with a description.
Example: Display version information of vdir command
To display the version information of vdir command, use vdir
command along with --version
option.
Conclusion
In this tutorial, we covered how to list directory contents in the Linux operating system using the vdir
command with available options and suitable examples. In Linux ls and dir are also available for the same purpose.