0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Linux】ディレクトリの一覧を取得する方法

Posted at

lsコマンド

ls -F [パス] | grep /

隠しファイルも含めて表示

ls -aF [パス] | grep /
サンプル
$ ls -F path/to/sample | grep /
app/
bin/
config/
db/
lib/
log/
public/
spec/
storage/
templates/
test/
tmp/
vendor/

$ ls -aF path/to/sample | grep /
./
../
.devcontainer/
.docker/
.git/
.vscode/
app/
bin/
config/
db/
lib/
log/
public/
spec/
storage/
templates/
test/
tmp/
vendor/

または次のように実行します。

$ ls -lR ./ | grep ^d
drwxr-xr-x 2 root root 44 12月  6 20:48 dir1
drwxr-xr-x 2 root root 44 12月  6 21:33 dir2
drwxr-xr-x 2 root root 6 12月  6 21:36 dir1-1
drwxr-xr-x 2 root root 6 12月  6 21:36 dir1-2
drwxr-xr-x 2 root root 6 12月  6 21:36 dir2-1
drwxr-xr-x 2 root root 6 12月  6 21:36 dir2-2

findコマンド

findコマンドでディレクトリのみの一覧を取得するには次のように実行します。

$ find ./ -mindepth 1 -type d
./app
./bin
./config
./db
./lib
./log
./public
./spec
./storage
./templates
./test
./tmp
./vendor
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?