Linux lsコマンドのサンプル

Linuxのlsコマンドを実行するサンプルです。

目次

サンプル ls -l (ファイルの一覧を詳細で表示)
  ls -n (UIDとGIDを表示)
ls -lh (サイズを読みやすい形式にする)
ls -lu (最終アクセス日を表示)
ls -1 (ファイルのみ表示する)
ls -m (カンマ区切り(csv形式)で表示する))
ls -lQ (ファイル・ディレクトリをダブルコーテーションで括る)
ls -lt (更新日の新しい順に表示する)
ls -ltr (並び順を逆にする)
ls -lS (ファイルサイズの大きい順に表示)
ls -la (隠しファイル・隠しディレクトリを表示)
ls -d */ (ディレクトリだけ表示)
ls -U (ソートせずに結果を表示)
ls -1U | wc -l (フォルダ内のファイル数を数える)

ls -l (ファイルの一覧を詳細で表示)

lはファイルの一覧を詳細で表示します。

[test@localhost test1]$ ls -l
合計 0
-rw-rw-r-- 1 test test  0  7月 20 08:34 test1.txt
-rw-rw-r-- 1 test test  0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test 23  7月 20 08:52 testdir1
[test@localhost test1]$

 

ls -n (UIDとGIDを表示)

nは、所有者とグループの代わりにUIDとGIDが表示されます。

[test@localhost test1]$ ls -n
合計 0
-rw-rw-r-- 1 1000 1000  0  7月 20 08:34 test1.txt
-rw-rw-r-- 1 1000 1000  0  7月 21 08:26 test2.txt
drwxrwxr-x 2 1000 1000 23  7月 20 08:52 testdir1
[test@localhost test1]$

 

ls -lh (サイズを読みやすい形式にする)

hはサイズを読みやすい形式にします。

[test@localhost test1]$ ls -lh
合計 12K
-rw-rw-r-- 1 test test 9.5K  7月 21 08:41 test1.txt
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
[test@localhost test1]$ ls -l
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:41 test1.txt
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
[test@localhost test1]$

1行目は、hをつけたので9.5kと表示されています。
6行目は、hをつけていないので9672と表示されています。

 

ls -lu (最終アクセス日を表示)

uは最終アクセス日を表示します。

[test@localhost test1]$ ls -lu
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:51 test1.txt
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test   23  7月 20 09:20 testdir1
[test@localhost test1]$ ls -l
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:41 test1.txt
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
[test@localhost test1]$

1行目は、uをつけたので最終アクセス日が表示されています。
6行目は、uをつけていないので更新日が表示されています。

 

ls -1 (ファイルのみ表示する)

数値の1はファイルのみ表示します。

[test@localhost test1]$ ls -1
test1.txt
test2.txt
testdir1
[test@localhost test1]$

 

ls -m (カンマ区切り(csv形式)で表示する)

mはカンマ区切り(csv形式)で表示します。

[test@localhost test1]$ ls -m
test1.txt, test2.txt, testdir1
[test@localhost test1]$

 

ls -lQ (ファイル・ディレクトリをダブルコーテーションで括る)

Qはファイル・ディレクトリをダブルコーテーションで括ります。

[test@localhost test1]$ ls -lQ
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:41 "test1.txt"
-rw-rw-r-- 1 test test    0  7月 21 08:26 "test2.txt"
drwxrwxr-x 2 test test   23  7月 20 08:52 "testdir1"
[test@localhost test1]$

 

ls -lt (更新日の新しい順に表示する)

tは更新日の新しい順に表示します。tはtimeのtです。

[test@localhost test1]$ ls -lt
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:41 test1.txt
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
[test@localhost test1]$

 

ls -ltr (並び順を逆にする)

rは並び順を逆にします。rはreverseのrです。

[test@localhost test1]$ ls -ltr
合計 12
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
-rw-rw-r-- 1 test test 9672  7月 21 08:41 test1.txt
[test@localhost test1]$

tは更新日の新しい順にしてrでその逆順にしています。
→ファイルの古い順に表示します。

 

ls -lS (ファイルサイズの大きい順に表示)

Sはファイルサイズの大きい順に表示します。

[test@localhost test1]$ ls -lS
合計 12
-rw-rw-r-- 1 test test 9672  7月 21 08:41 test1.txt
drwxrwxr-x 2 test test   23  7月 20 08:52 testdir1
-rw-rw-r-- 1 test test    0  7月 21 08:26 test2.txt
[test@localhost test1]$

 

ls -la (隠しファイル・隠しディレクトリを表示)

aは隠しファイル・隠しディレクトリを表示します。

[test@localhost test1]$ ls -la
合計 16
drwxrwxr-x.  4 test test   91  7月 21 08:41 .
drwx------. 22 test test 4096  7月 21 08:41 ..
-rw-rw-r--   1 test test    0  7月 20 08:35 .test2.txt
drwxrwxr-x   2 test test    6  7月 20 08:36 .testdir2
-rw-rw-r--   1 test test 9672  7月 21 08:41 test1.txt
-rw-rw-r--   1 test test    0  7月 21 08:26 test2.txt
drwxrwxr-x   2 test test   23  7月 20 08:52 testdir1
[test@localhost test1]$

5行目は、隠しファイルです。
6行目は、隠しディレクトリです。

 

ls -d */ (ディレクトリだけ表示)

[test@localhost test1]$ ls -d */
testdir1/
[test@localhost test1]$

 

ls -U (ソートせずに結果を表示)

Uはソートしないため高速で表示されます。
主にファイルが大量にあるときに使用します。

 

以下は先頭の10行のみ表示します。

ls -l `ls -U | head`

 

以下は1ページ単位で表示しスクロールしません。エンターで下に移動します。
ctrl + cで終了します。

ls -U | more

 

ls -1U | wc -l (フォルダ内のファイル数を数える)

[test@localhost test1]$ ls -1U | wc -l
3
[test@localhost test1]$

lsコマンドとwcコマンドを使用します。

関連の記事

△上に戻る