-type option will let find command to filter files by its types: d for directory, f for ordinary file, and l for symbolic link.
terminal:
1 - 5): create 3 files: o1, o2, o3, and one directory: dir. Inside dir, create 2 ordinary files, d1 and d2. Create one hard link: hl_o1 one soft link: sl_o2.
6) Find all files whose type is directory
7) Find all files whose type is ordinary file
8) Find all files whose type is soft links.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ mkdir dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./dir/d1 ./dir/d2
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ln o1 hl_o1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ln -s o2 sl_o2
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -type d
dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -type f
dir/d2
dir/d1
hl_o1
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -type l
sl_o2
2. Find Command: -links
-links option could help find command to filter on files on the count of hard links.
terminal:
1 - 4): Create file structure
5) List all files, "ol" and "hl_o1" both points to the same part of data, so their hard link number is 2. Directory "dir"'s hard link count is 2.
6) Find all files whose number of hard link is exactly 2.
7) Find all files whose number of hard link is less than 2.
8) Find all files whose number of hard link is is more than 1.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ mkdir dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./dir/d1 ./dir/d2
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ln o1 hl_o1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -lrt
total 4
-rw-rw-r-- 1 aubinxia aubinxia 0 Jul 5 16:49 o3
-rw-rw-r-- 1 aubinxia aubinxia 0 Jul 5 16:49 o2
-rw-rw-r-- 2 aubinxia aubinxia 0 Jul 5 16:49 o1
-rw-rw-r-- 2 aubinxia aubinxia 0 Jul 5 16:49 hl_o1
drwxrwxr-x 2 aubinxia aubinxia 4096 Jul 5 16:49 dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -links 2
dir
hl_o1
o1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -links -2
dir/d2
dir/d1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -links +1
dir
hl_o1
o1
3. Find Command: -atime, -ctime, -mtime
-atime <num> option help find command to select files whose access time is in last <num> days.
-ctime <num> option help find command to select files whose change time is in last <num> days.
-mtime <num> option help find command to select files whose modification time is in last <num> days.
terminal:
1) Create 3 files: o1, o2, o3
2) Find all files whose access time is in last 0 days, which means, list all files who are accessed today
3) Find all files whose access time is in last "less than 1 day".
4) Find all files whose access time is in last "more than 1 day"
-mtime and -ctime is similar from -atime.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -atime 0
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -atime -1
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -atime +1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$
No comments:
Post a Comment