2
0

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 5 years have passed since last update.

lsでディレクトリ名のみを取得する

Last updated at Posted at 2019-05-24

調べたら

ls -l | grep ^d

とかって出るけど、これだと

drwxr-xr-x  4 XXX  1990765396   128  5 25 07:46 bookmark
drwxr-xr-x  4 XXX  1990765396   128  5 24 00:21 category
drwxr-xr-x  7 XXX  1990765396   224  5 25 07:52 category_group
drwxr-xr-x  7 XXX  1990765396   224  5 25 07:52 contract

とか出力されて使い勝手いくない。

ls -l | grep ^d | awk '{print $9}'

だと

bookmark
category
category_group
contract

でいいかんじ。
($9の部分って環境によって違うのかな??)

これでfor文とかに入れてチョメチョメ出来る。

for file in `ls -l | grep ^d | awk '{print $9}'`; do
    echo "${file}"
done
2
0
1

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?