Linux vdir Command Tutorial for Beginners (8 Examples)
Listing contents of a directory is one of the most basic tasks that users (both pro and noobs) find themselves involved in. The ls command is hands down the most popular tool used for this purpose. However, it’s not the only one.
There are some alternatives. For example, there’s a utility called vdir, basics of which we’ll be discussing here. But before we do that, it’s worth mentioning that all examples in this tutorial have been tested on an Ubuntu 18.04 LTS machine.
Like ls, the vdir command in Linux is also used to list directory contents. Following is its syntax:
vdir [OPTION]… [FILE]…
And here’s how the tool’s man page explains it:
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Following are some Q&A-styled examples that should give you a good idea on how the vdir command works.
Q1. How to use vdir?
Basic usage is pretty simple – just execute the vdir command sans any option.
vdir
For example, in my case, running ‘vdir’ produced the following output:
total 12
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Documents
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Downloads
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 8980 Sep 26 09:29 examples.desktop
drwxrwxr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Files-From-Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Music
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Pictures
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Public
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Templates
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Videos
So you can see the output is similar to the ‘ls -l’ command.
Q2. How to make vdir display entries starting with dot (.)?
By default, the vdir command output doesn’t show names that begin with dot (.). However, you can change this behavior using the -a command line option.
vdir -a
Following output was produced in my case:
total 52
drwx------ 20 guest-A8CLd9 guest-A8CLd9 540 Sep 26 09:30 .
drwxrwxrwt 7 root root 16384 Sep 26 10:17 ..
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 220 Sep 26 09:29 .bash_logout
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 3637 Sep 26 09:29 .bashrc
drwxr-xr-x 12 guest-A8CLd9 guest-A8CLd9 260 Sep 26 09:37 .cache
drwxr-xr-x 16 guest-A8CLd9 guest-A8CLd9 360 Sep 26 09:29 .config
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Documents
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Downloads
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 8980 Sep 26 09:29 examples.desktop
drwxrwxr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Files-From-Desktop
drwx------ 3 guest-A8CLd9 guest-A8CLd9 60 Sep 26 09:30 .gconf
drwx------ 3 guest-A8CLd9 guest-A8CLd9 60 Sep 26 09:30 .gnome2
drwx------ 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:30 .gnome2_private
-rw------- 1 guest-A8CLd9 guest-A8CLd9 358 Sep 26 09:29 .ICEauthority
drwxr-xr-x 3 guest-A8CLd9 guest-A8CLd9 60 Sep 26 09:29 .kde
drwx------ 3 guest-A8CLd9 guest-A8CLd9 60 Sep 26 09:29 .local
drwx------ 4 guest-A8CLd9 guest-A8CLd9 80 Sep 26 09:30 .mozilla
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Music
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Pictures
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 697 Sep 26 09:29 .profile
drwxrwxr-x 2 guest-A8CLd9 guest-A8CLd9 60 Sep 26 09:29 .psensor
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Public
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Templates
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Sep 26 09:29 Videos
-rw------- 1 guest-A8CLd9 guest-A8CLd9 61 Sep 26 09:29 .Xauthority
-rw------- 1 guest-A8CLd9 guest-A8CLd9 108 Sep 26 09:29 .xsession-errors
So you can see that file names beginning with a dot are also produced in output.
Q3. How to make vdir scale sizes by fixed size?
Suppose you want vdir to print sizes (5th column in output) in blocks of megabytes, then you can do this using the –block-size option, by supplying ‘M’ as input to it.
vdir –block-size=M
Following is the output this command produced on my system:
total 1M
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Documents
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Downloads
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 examples.desktop
drwxrwxr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Files-From-Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Music
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Pictures
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Public
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Templates
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 1M Sep 26 09:29 Videos
So you can see that size entries are produced in blocks of megabytes (M).
Here’s some useful information related to the input that this option requires:
The SIZE argument is an integer and optional unit (example: 10K is
10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,...
(powers of 1000).
Q4. How to make vdir produce output like ls?
By default, the ls command doesn’t produce details in output – just name of files/directories in the current directory.
However, vdir produces a whole lot of info by default. But if you want, you can restrict vdir to an ‘ls’ like output. This you can do using the -C command line option.
vdir -C
Following output was produced in my case:
Desktop Documents Downloads examples.desktop Files-From-Desktop Music Pictures Public Templates Videos
Q5. How to make vdir produce colored output?
If you compare the output produced by vdir in the previous section with the output produced by ‘ls’ command, you’ll observe one difference: the ls command output is colored while that of vdir isn’t.
However, you can force vdir to produce colored output as well. This you can do using the –color command line option.
vdir –color
Q6. How to make vdir produce unsorted output?
This you can do using the -f command line option.
vdir -f
Following is the output this command produced in my case:
. .gnome2 Files-From-Desktop .local Music Templates .xsession-errors .cache .bash_logout
.. .mozilla .ICEauthority Videos Documents Downloads .Xauthority .config .profile
.gnome2_private .psensor .gconf Pictures Public Desktop .kde examples.desktop .bashrc
Here’s how the man page explains this -f option:
-f do not sort, enable -aU, disable -ls --color
Q7. How to make vdir group directories first in the output?
If you want the vdir command to group directories first in the output, use the –group-directories-first option.
vdir –group-directories-first
Following is the output this command produced in my case:
total 12
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Desktop
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Documents
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Downloads
drwxrwxr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Files-From-Desktop
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Music
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Pictures
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Public
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Templates
drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Videos
-rw-r--r-- 1 guest-eugepN guest-eugepN 8980 Aug 22 2011 examples.desktop
So you can see all directories got listed first.
Q8. How to make vdir produce index number for each file?
This can be achieved using the -i command line option.
vdir -i
Following is a sample output:
total 12
22 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Desktop
26 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Documents
23 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Downloads
6 -rw-r--r-- 1 guest-eugepN guest-eugepN 8980 Aug 22 2011 examples.desktop
155 drwxrwxr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Files-From-Desktop
27 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Music
28 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Pictures
25 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Public
24 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Templates
29 drwxr-xr-x 2 guest-eugepN guest-eugepN 40 Aug 22 2011 Videos
The first column contains the respective index numbers.
Depending upon the requirement, the vdir command can prove to be a useful tool for you. In this tutorial, we have discussed some key option this utility offers. To learn more about this tool, head to its man page.