Find command will show hidden files.
terminal:
1) - 5)We create the hidden files and normal files
6) * can't be used to represent hidden files whose name starts with "."
7) ".*" can be used to represent hidden files names but it will make find command to "dig recursively" for "."(local) and ".."(parent) folder.
8) find without any parameter list all files without touching the "." and ".."
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./hide_file
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ mkdir dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./dir/.hide_file
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ ls -a
. .. dir hide_file o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find *
dir
dir/.hide_file
hide_file
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find .*
.
./dir
./dir/.hide_file
./o1
./o3
./o2
./hide_file
..
../xxdev
../xxdev/dir
../xxdev/dir/.hide_file
../xxdev/o1
../xxdev/o3
../xxdev/o2
../xxdev/hide_file
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find
.
./dir
./dir/.hide_file
./o1
./o3
./o2
./hide_file
2. Find Command: match file names with regular expression
Use regular expressions to match files at the local directory
1) Create temporary files o1 o2 o3
2) find all files whose names starting with "o"
3) find all files whose names starting with "o" and 2nd character is in range [1-3]
4) find all files whose names starting with "o" and 2nd character is not lower case character.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch o1 o2 o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find o*
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find o[1-3]
o1
o2
o3
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find o[^a-z]
o1
o2
o3
===========================================If the parameter doesn't represent a path, it will just search the file whose name match the expression.
If the parameter represent a path, it will search from that path, and list all names.
1) find command list all files at "~/Desktop" diretory
2) find command list all files under "dir" directory at the local place
3) d1 is not one directory at local place, then find command will search all entities(including files and directories) in local folder, but fails to find anything.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find ~/Desktop
/home/aubinxia/Desktop
/home/aubinxia/Desktop/xxdev
/home/aubinxia/Desktop/xxdev/ob
/home/aubinxia/Desktop/xxdev/dir
/home/aubinxia/Desktop/xxdev/dir/d2
/home/aubinxia/Desktop/xxdev/dir/d1
/home/aubinxia/Desktop/xxdev/oc
/home/aubinxia/Desktop/xxdev/oa
/home/aubinxia/Desktop/xxdev/.hide
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find dir
dir
dir/d2
dir/d1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find d1
find: `d1': No such file or directory
3. Find command: -prune
1) - 4): Create the files: oa, ob, oc in the local directory, also make the directory called dir, and create files: d1 and d2 inside dir.
5) find command will list all files, including files inside dir
6) with -prune option, by default, find will just list files in the "first level", which is "."(dot) current directory it won't dig into it.
7) with parameter "*", "."(dot) is not the "first level" to search any more. It will just list all files, including directories in the local place, but -prune option make find not dig into "dir" recursively.
8) with parameter ".*", it will search all files whose name starting with "." at the local place, and -prune option make find command not dig into directory including "." and "..".
9) with parameter "[a-z]*", find will search all files whose full name(including the path) starting with one lower case character, it will dig into dir to get all files
10) with parameter "[a-z]*" and option prune, it will do same things as point 9, but prune option make find not dig into the "dir"
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch oa ob oc
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ mkdir dir
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./dir/d1
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ touch ./dir/d2
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find
.
./ob
./dir
./dir/d2
./dir/d1
./oc
./oa
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find -prune
.
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find * -prune
dir
oa
ob
oc
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find .* -prune
.
..
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find [a-z]*
dir
dir/d2
dir/d1
oa
ob
oc
aubinxia@aubinxia-fastdev:~/Desktop/xxdev$ find [a-z]* -prune
dir
oa
ob
oc
No comments:
Post a Comment