6
7

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.

zshで属性を考慮してファイル名を展開する

Last updated at Posted at 2015-01-17

zshのファイル展開は便利でfindが殆ど必要なくなります

昔から使える展開

ls *
ls *.c

で現在のディレクトリ以下のファイル一覧、あるいは拡張子.cを持つファイルを一覧します。
当然cp, rm等でも使えます。
注意すべきは、zshが*を先に展開してから実行コマンドに渡される点です。

再帰的にディレクトリを走査する

ls **/*
ls **/bin/*

**をは任意のディレクトリ階層にマッチします。
これで現在のディレクトリから、再帰的に以下のファイルを走査します。

ファイルの属性を考慮した展開

上述の**を使う展開ではマッチするファイルが増えすぎるので、
何かで制限したくなります。

ls **/*(.)       # 通常ファイルのみ
ls **/*(/)       # ディレクトリのみ
ls **/bin/*(.*)  # 通常ファイルで実行可能なもの

最後の例のように複数の指定子を組みあわせて使う事ができます。
zshの補完機能をonしていれば(を入れた段階でTABで候補が説明付きででます。

ls **/*(
%  -- device files
)  -- end of qualifiers
*  -- executable plain files
+  -- + command name
-  -- follow symlinks toggle
.  -- plain files
/  -- directories
:  -- modifier
=  -- sockets
@  -- symbolic links
A  -- group-readable
D  -- glob dots
E  -- group-executable
F  -- non-empty directories
G  -- owned by EGID
I  -- group-writeable
L  -- + size
M  -- mark directories
N  -- use NULL_GLOB
O  -- + sort order, down
P  -- prepend word
R  -- world-readable
S  -- setgid
T  -- mark types
U  -- owned by EUID
W  -- world-writeable
X  -- world-executable
Y  -- + at most ARG matches
[  -- + range of files
^  -- negate qualifiers
a  -- + access time
c  -- + inode change time
d  -- + device
e  -- execute code
f  -- + access rights
g  -- + owning group
l  -- + link count
m  -- + modification time
n  -- numeric glob sort
o  -- + sort order, up
p  -- name pipes (FIFOS)
r  -- owner-readable
s  -- setuid
t  -- sticky bit set
u  -- + owning user
w  -- owner-writeable
x  -- owner-executable
6
7
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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?