Linux Search

数据库搜索--只能通过文件名搜索
1. 更新数据:updatedb (default system will run the command at 4.02am)
2.搜索文件:locate 文件名
Addition: locate -r to use regular expression
Example:
locate -r 'ls$': to find the file name which end with 'ls'
locate -r '^ls': to find the file name which start with 'ls'
'.*': any length of any character
'a*': any length of a
'\<ls' : word start with ls
'\>ls': word end with ls
 
find
1. search by name:find / -name <file name> (find use wildcard: * ?)
2. search by size:find / -size +20000  找大于20M的文件
3. search by inode:find / -inum 文件或文件夹的inode
4. search by user: find / [-user/-nouser] <username>
5. search by group: find / [-group/-nogroup] <groupname>
6. search by priliege: find / -perm [/mode/-mode/mode]
a. /mode: any one match
b. -mode: contain match
c. mode: exact match
 
7. search by type: find / -type <file type>
file type: b: block device / d: directory / c: character device / p: piple / l: link / f: file / s: socket
 
8. search by time:
A. mtime: content modify time (vi, echo) --> mmin
B. atime: access time (touch) --> amin
C. ctime: file create time (chmod, chgrp, mv) --> cmin
find <path> {-mtime/-mmin/-atime/-amin/-ctime/-cmin} [+N/-N/N]

 
9. 直接处理搜索结果:
例如:查询所有inode为79706的文件,并用ll查询
find / -inum 79706 -exec ls -l {} \;
例如:查询/database/archivelogz文件夹下所有24小时以前的文件并删除
find /database/archivelog -atime 1 -exec rm {} \;
Additional: If need check before delete
find /database/archivelog -atime 1 -ok rm {} \;
 
awk
例如:查询所有uid>500的用户,显示他们的用户名和uid
awk -F: '$3>500 { print $1,$3 }' passwd

-F:表示间隔符

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error