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