LoginSignup
1
0

More than 1 year has passed since last update.

【Linux】ls コマンドの結果を1行ずつ表示する

Posted at

はじめに

ls コマンドの結果をテキストファイルに入れたり、Excelに貼り付けたりするときに便利なls コマンドのオプションを紹介します。

ls -1 で1行ずつに表示する

ls コマンドは基本的に横に並べたがります。

[root@localhost ~]# ls /etc/
DIR_COLORS               idmapd.conf               profile.d
DIR_COLORS.256color      init.d                    protocols
DIR_COLORS.lightbgcolor  inittab                   rc.d
・・・

ls -1としてやることで、横並びにならなくなります。

オプションは数字の1であることに気を付けてください。

[root@localhost ~]# ls -1 /etc/
DIR_COLORS
DIR_COLORS.256color
DIR_COLORS.lightbgcolor
GREP_COLORS
NetworkManager
PackageKit
・・・

ディレクトリの中身も表示したい

ディレクトリの中身まですべて表示したい(再帰的に表示したい)ときにはls -1Rとします。

[root@localhost ~]# ls -1R /etc/
・・・
/etc/NetworkManager/dispatcher.d:
04-iscsi
11-dhclient
20-chrony
no-wait.d
pre-down.d
・・・



ディレクトリ名:
ファイル名1
ファイル名2
ディレクトリ名1
・・・

といった表記で結果を得ることができます。

おわりに

使い勝手の良いオプションだと思います。
このオプションを知っているというだけでドヤ顔ができる日が来るかもしれないのでぜひ、覚えておいてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0