主に自分用のメモです。閲覧いただいた方にはわかりにくいかもしれません m(_ _)m
Linuxのコマンドラインにて、ファイル検索
find
オプション
ファイル・ディレクトリ名: -name xxxx
例:カレントディレクトリ以下で、.git ディレクトリを検索
find . -name .git -type d
所有者で検索: -user xxxx
所有グループで検索: -group xxxx
lsのリスト形式で表示: -ls
ファイルのみ検索: -type f (ディレクトリは -type d)
特定のパスに含まれるのを削除したい
find に除外がなかったため、grep コマンドに渡して対応
man find 抜粋
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
-user uname File is owned by user uname (numeric user ID allowed). -type c File is of type c: d directory f regular file l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype. -group gname File belongs to group gname (numeric group ID allowed). -ls True; list current file in ls -dils format on standard output. The block counts are of 1K blocks, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. See the UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled. |
grep
オプション
-v xxxx
xxxxが含まれるものを除外
1 2 |
-v, --invert-match Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.) |
使用例
find public -type f -group aaaa -ls | grep -v vendor | grep -v public/pdf
→ publicディレクトリで、所有group が aaaa で、パスに vendor と public/pdf を含まないものを検索。
コメント