mac 指定したユーザーが作成したものだけを取得する

  • 作成日 2023.08.14
  • mac
mac 指定したユーザーが作成したものだけを取得する

macのターミナル上で、指定したユーザーが作成したものだけを取得する手順を記述してます。「find」コマンドのオプションである「-user」に対象のユーザーを指定するだけで可能です。

環境

  • OS macOS Monterey
  • SHELL /bin/zsh

手順

指定したユーザーが作成したものだけを取得するには、「find」コマンドのオプション「-user」を使用します。

実際に、以下のディレクトリからrootが作成したもののみを取得してみます。

$ ls -l

合計 24
drwxr-xr-x  2 admin  staff   64 Sep 28 09:26 bar
-rw-r--r--  1 admin  staff   24 Sep 27 10:08 bar.tsv
-rw-r--r--  1 admin  staff   80 Sep 27 10:32 bar.txt
drwxr-xr-x  5 admin  staff  160 Sep 22 11:45 foo
-rw-r--r--  1 admin  staff   24 Sep 27 10:08 foo.tsv
-rw-r--r--  1 admin  staff   55 Sep 25 12:59 foo.txt
drwxr-xr-x  2 admin  staff   64 Sep 28 09:26 hoge
-rw-r--r--  1 admin  staff   24 Sep 25 13:06 hoge.csv
-rw-r--r--  1 admin  staff   24 Sep 25 13:08 hoge.tsv
-rw-r--r--  1 admin  staff   20 Sep 25 16:13 hoge.txt
lrwxr-xr-x  1 admin  staff   15 Sep 28 11:32 hosts -> ../../etc/hosts
-rw-r--r--  1 admin  staff  156 Sep 28 11:50 index.html
-rw-r--r--  1 admin  staff  575 Sep 24 12:13 paste.txt
-rw-r--r--  1 root   staff    0 Sep 28 12:08 test.txt
-rw-r--r--  1 root   staff    0 Sep 28 12:08 test2.txt

rootを指定して実行します。

$ find . -user root

./test
./test2.txt
./test.txt

取得されていることが確認できます。

UIDを使用しても同じ結果が得られます。

$ find . -user 0

./test.txt
./test2.txt
./test