初学者的 Linux vdir 命令教程(8 个示例)
在此页
- Q1。如何使用虚拟目录?
- Q2。如何使 vdir 显示以点 (.) 开头的条目?
- Q3。如何按固定大小制作 vdir 比例大小?
- Q4。如何让 vdir 产生像 ls 一样的输出?
- Q5。如何让 vdir 产生彩色输出?
- Q6。如何让 vdir 产生未排序的输出?
- Q7。如何在输出中首先制作 vdir 组目录?
- Q8。如何让 vdir 为每个文件生成一个索引号?
列出目录的内容是用户(包括专业人士和新手)发现自己参与的最基本的任务之一。ls 命令无疑是用于此目的的最流行的工具。然而,它不是唯一的。
有一些选择。例如,有一个名为 vdir 的实用程序,我们将在此处讨论其基础知识。但在我们这样做之前,值得一提的是,本教程中的所有示例都已经在 Ubuntu 18.04 LTS 和 Debian 10 机器上进行了测试。
与 ls 一样,Linux 中的 vdir 命令也用于列出目录内容。以下是它的语法:
vdir [OPTION]... [FILE]...
以下是工具手册页对其的解释:
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
以下是一些 Q&A 风格的示例,应该可以让您对 vdir 命令的工作原理有一个很好的了解。
Q1。如何使用虚拟目录?
基本用法非常简单 - 只需执行没有任何选项的 vdir 命令。
vdir
例如,在我的例子中,运行 vdir 会产生以下输出:
total 12
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Documents
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Downloads
-rw-r--r-- 1 guest-A8CLd9 guest-A8CLd9 2513 Apr 16 14:33 examples.desktop
drwxrwxr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Files-From-Desktop
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Music
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Pictures
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Public
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Templates
drwxr-xr-x 2 guest-A8CLd9 guest-A8CLd9 40 Apr 16 14:33 Videos
所以你可以看到输出类似于 ls -l 命令。
Q2。如何使 vdir 显示以点 (.) 开头的条目?
默认情况下,vdir 命令输出不显示以点 (.) 开头的名称。但是,您可以使用 -a 命令行选项更改此行为。
vdir -a
在我的案例中产生了以下输出:
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
所以你可以看到输出中也产生了以点开头的文件名。
Q3.如何按固定大小制作 vdir 比例大小?
假设您希望 vdir 以兆字节为单位打印大小(输出中的第 5 列),那么您可以使用 --block-size 选项将 M 作为输入来执行此操作。
vdir --block-size=M
以下是此命令在我的系统上产生的输出:
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
因此您可以看到大小条目是以兆字节 (M) 为单位生成的。
以下是与此选项所需的输入相关的一些有用信息:
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.如何让 vdir 产生像 ls 一样的输出?
默认情况下,ls 命令不会在输出中产生详细信息 - 只是当前目录中文件/目录的名称。
但是,默认情况下 vdir 会生成大量信息。但是如果你愿意,你可以像输出一样将 vdir 限制为 ls。您可以使用 -C 命令行选项执行此操作。
vdir -C
在我的案例中产生了以下输出:
Desktop Documents Downloads examples.desktop Files-From-Desktop Music Pictures Public Templates Videos
Q5.如何让 vdir 产生彩色输出?
如果将上一节中 vdir 生成的输出与 ls 命令生成的输出进行比较,您会发现一个区别:ls 命令的输出是彩色的,而 vdir 的不是。
但是,您也可以强制 vdir 生成彩色输出。这可以使用 --color 命令行选项来完成。
vdir --color
Q6.如何让 vdir 产生未排序的输出?
您可以使用 -f 命令行选项执行此操作。
vdir -f
以下是此命令在我的案例中产生的输出:
. .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
以下是手册页解释此 -f 选项的方式:
-f do not sort, enable -aU, disable -ls --color
Q7.如何在输出中首先制作 vdir 组目录?
如果您希望 vdir 命令在输出中首先对目录进行分组,请使用 --group-directories-first 选项。
vdir --group-directories-first
以下是此命令在我的案例中产生的输出:
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
所以你可以看到所有目录都首先列出。
Q8.如何让 vdir 为每个文件生成一个索引号?
这可以使用 -i 命令行选项来实现。
vdir -i
以下是示例输出:
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
第一列包含各自的索引号。
根据要求,vdir 命令可以证明是对您有用的工具。在本教程中,我们讨论了该实用程序提供的一些关键选项。要了解有关此工具的更多信息,请访问其手册页。