ディレクトリのコンテンツを一覧表示することは、ユーザー(proとnoobsの両方)が関与している最も基本的なタスクの1つです。lsコマンドは、この目的で使用される最も一般的なツールです。ただし、それだけではありません。
いくつかの選択肢があります。たとえば、 vdirというユーティリティがあります 、その基本についてはここで説明します。ただし、その前に、このチュートリアルのすべての例がUbuntu18.04LTSおよびDebian10マシンでテストされていることを言及する価値があります。
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.
以下は、vdirコマンドがどのように機能するかについての良いアイデアを与えるはずのQ&Aスタイルの例です。
Q1。 vdirの使い方は?
基本的な使用法は非常に簡単です。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」コマンドによって生成された出力と比較すると、1つの違いがわかります。つまり、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コマンドが便利なツールになる場合があります。このチュートリアルでは、このユーティリティが提供するいくつかの重要なオプションについて説明しました。このツールの詳細については、マニュアルページにアクセスしてください。