LoginSignup
3
3

More than 5 years have passed since last update.

[Bash] lsコマンド まいちっぷす

Posted at

役に立ちそうな使いかたを覚書。随時更新する。

更新時刻でソート(-lrt)

$ ls -lrt
total 0
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 work
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 hoge
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:54 fuga
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:54 piyo
-rwxr-xr-x 1 nagamee nagamee 0 Jun 24 00:55 test.sh
-rw-rw-r-- 1 nagamee nagamee 0 Jun 24 00:55 data.txt

新しいものほど下段に表示される。

1行1ファイルで表示する(-1)

パイプするときによくつかう。

$ ls -F
data.txt  fuga/  hoge/  piyo/  test.sh*  work/

$ ls -1
data.txt
fuga
hoge
piyo
test.sh
work

拡張子単位でグルーピング(-X)

いろんな拡張子のファイルが混在していてごちゃついてるときに。

$ ls -l
total 0
-rwxr-xr-x 1 nagamee nagamee 0 Jun 24 01:15 abc.sh
-rw-rw-r-- 1 nagamee nagamee 0 Jun 24 00:55 data.txt
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 hoge
-rwxr-xr-x 1 nagamee nagamee 0 Jun 24 00:55 test.sh
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 work

$ ls -lX
total 0
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 hoge  #拡張子なし
drwxrwxr-x 2 nagamee nagamee 6 Jun 24 00:53 work
-rwxr-xr-x 1 nagamee nagamee 0 Jun 24 01:15 abc.sh # .sh
-rwxr-xr-x 1 nagamee nagamee 0 Jun 24 00:55 test.sh
-rw-rw-r-- 1 nagamee nagamee 0 Jun 24 00:55 data.txt #.txt

一時的にエイリアスを無効化したい(\ls)

lsコマンドに限らずな内容だけど、ls以外で使ったことない。
(なぜならエイリアスほとんど使わないからw)

$ type ls
ls is aliased to `ls -F --color'

$ ls
data.txt  fuga/  hoge/  piyo/  test.sh*  work/

# あたまに\をつける
$ \ls
data.txt  fuga  hoge  piyo  test.sh  work

# 実行ファイルをフルパス指定
$ /usr/bin/ls
data.txt  fuga  hoge  piyo  test.sh  work
3
3
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
3
3