wc [选项] 文件名称
选项 | 作用 |
---|---|
-l | 只显示行数 |
-w | 只显示单词数 |
-c | 只显示字节数 |
在Linux系统中,/etc/passwd是用于保存系统账户信息的文件,要统计当前系统中有多少个用户,
[root@kongd ~]# wc -l /etc/passwd
45 /etc/passwd
cp [选项] 源文件 目标文件
选 项 | 功能 |
---|---|
-a | 通常在拷贝目录时使用。它保留链接、文件属性,并递归地拷贝目录 |
-d | 拷贝时保留链接 |
-f | 在覆盖已经存在的目标文件时不提示 |
-i | 在覆盖目标文件之前将给出提示要求用户确认。回答y时目标文件将被覆盖,是交互式拷贝 |
-p | 除复制源文件的内容外,还将把其修改时间和访问权限也复制到新文件中 |
-r | 若给出的源文件是一目录文件,此时cp将递归复制该目录下所有的子目录和文件。 此时目标 文件必须为一个目录名 |
mv [选项] 源文件名称 目标文件名称
[root@kongd ~]# mv x.log linux.log
[root@kongd ~]# ls
install.log linux.log
命令 | 说明 | 示例 |
---|---|---|
whereis | 可以搜索系统命令的可执行文件路径和说明文档 | # whereis ls |
which | which 是搜索系统命令的可执行文件 | #which ls |
locate | 按照数据库搜索,搜索速度快,消耗资源小。数据库位置/var/lib/mlocate/mlocate.db, 可以使用 updatedb 命令强制更新数据库。 | #locate ls |
find | 可按照文件名、大小、时间、权限、类型、所属者、所属组来 搜索文件 | find [path...] [expression] |
# whereis ls which
#which ls locate
#locate ls find
find [path...] [expression]
简介:
参数 | 作用 |
---|---|
-name | 根据文件basename匹配名称 |
-path | -path可以对文件的dirname+basename进行查找。 |
-size | 匹配文件的大小(+50KB为查找超过50KB的文件,而-50KB为查找小于50KB的文 件) |
-mtime [+|-]n | 匹配修改内容的时间(-4指小于等于4天内的文件名;+4,大于等于5天前的文件 名;4指前4~5那一天的文件) |
-atime [+|-]n | 匹配访问文件的时间 |
-ctime [+|-]n | 匹配修改文件权限的时间 |
参数 | 作用 |
---|---|
-newer f1 !f2 | 匹配比文件f1新但比f2旧的文件 |
-perm | 匹配权限(mode为完全匹配,-mode为包含即可) |
-user | 匹配所有者 |
-group | 匹配所有组 |
-nouser | 匹配无所有者的文件 |
-nogroup | 匹配无所属组的文件 |
参数 | 作用 |
---|---|
-type b/d/c/p/l/f | 匹配文件类型(后面的字母参数依次表示块设备、目录、字符设备、管道、链接 文件、文本文件) |
-prune | 忽略某个目录下的文件,需要和-path一起使用 |
-depth | 先从该目录子目录下查找,再查找该目录 |
-maxdepth levels -mindepth levels | 最多查找多少层目录;最少查找多少层目录 |
-delete | 将找到的文件删除,如果是目录只能删除找到的空目录。 |
-exec …… {}\; | 后面可跟用于进一步处理搜索结果的命令 |
[root@localhost ~]# find 路径 [选项] 搜索内容
选项:
-name: 按照文件名搜索
-iname: 按照文件名搜索,不区分文件名大小写
-inum: 按照 inode 号搜索
[root@kongd ~]# find /etc -name "host*" -print
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/avahi/hosts
/etc/hostname
[root@shell ~]# find /etc -path "*ssh/ssh*"
/etc/ssh/ssh_config
/etc/ssh/ssh_config.d
/etc/ssh/ssh_config.d/05-redhat.conf
/etc/ssh/sshd_config
/etc/ssh/ssh_host_ed25519_key
/etc/ssh/ssh_host_ed25519_key.pub
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ecdsa_key.pub
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
[root@shell ~]# find /tmp/test ! -path /tmp/test
[root@shell ~]# find . ! -path .
[root@shell ~]# find . -name file
./file
./dir1/file
./test/file
[root@shell ~]# find ~+ -name file
/root/file
/root/dir1/file
/root/test/file
[root@shell ~]# find $PWD -name file
/root/file
/root/dir1/file
/root/test/file
[root@shell ~]# find $(pwd) -name file
/root/file
/root/dir1/file
/root/test/file
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-size [+|-]大小: 按照指定大小搜索文件,这里的“+”的意思是搜索比指定大小还要大的文件,
“-”的意思是搜索比指定大小还要小的文件
-size 0可以查找大小为0的普通文件。如果要查找没有任何文件的目录或者空的普通文件可以使用empty
[root@master ~]# find . -size +10M
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-atime [+|-]时间: 按照文件访问时间搜索
-mtime [+|-]时间: 按照文件数据修改时间搜索
-ctime [+|-]时间: 按照文件状态修改时间搜索
-newer file: 把比file修改时间更新的文件列出来
-newerXY:如果所考虑的文件的时间戳X比文件引用的时间戳Y新,则成功。字母X和Y可以是以下任意字
母。
a文件引用的访问时间
B文件引用的出生时间
c索引节点状态更改参考时间
m文件引用的修改时间
t将所指定的参数理解为一个具体的时间值
-5:代表 5 天内修改的文件。
5:代表前 5~6 天那一天修改的文件。
+5:代表 6 天前修改的文件。
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-perm 权限模式: 查找文件权限刚好等于“权限模式”的文件
-perm -权限模式: 查找文件权限全部包含“权限模式”的文件
-perm +权限模式: 查找文件权限包含“权限模式”的任意一个权限的文件
[root@kongd ~]# find / -perm -4000 -print
/usr/bin/fusermount
/usr/bin/chage
………………省略部分输出信息………………
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-uid 用户 ID: 按照用户 ID 查找所有者是指定 ID 的文件
-gid 组 ID: 按照用户组 ID 查找所属组是指定 ID 的文件
-user 用户名: 按照用户名查找所有者是指定用户的文件
-group 组名: 按照组名查找所属组是指定用户组的文件
-nouser: 查找没有所有者的文件
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-type d: 查找目录
-type f: 查找普通文件
-type l: 查找软链接文件
[root@localhost ~]# find 搜索路径 [选项] 搜索内容
选项:
-a: and 逻辑与
-o: or 逻辑或
-not: not 逻辑非
优先级:与>或>非
选项 | 说明 |
---|---|
printf | %f是获取basename(去除所有路径前缀) %p是获取路径自身,一般用不上,%P是 获取除了find搜索路径的剩余部分 |
补充说明-exec参数:
举例: 在整个文件系统中找出所有归属于kongd用户的文件并复制到 /root/findresults 目录。
[root@shell ~]# find /root -printf "%f\n" [root@kongd ~]# find / -user kongd -exec cp -a {} /root/findresults/ \;