Linux常用命令(3)——查找定位文件命令

pwd

#查看当前用户所处目录
[root@hostname etc]# pwd
/etc

cd

切换工作路径。

[root@hostname ~]# cd /etc #cd到指定地址
[root@hostname ~]# cd -    #返回上一次
[root@hostname ~]# cd ../  #返回上一级
[root@hostname ~]# cd ~   #快速切换到家目录

ls

显示目录中文件信息。ls [参数] [文件名称]

[root@hostname ~]# ls
[root@hostname ~]# ls -a #包括隐藏文件
[root@hostname ~]# ls -l #文件详细信息
[root@hostname ~]# ls /dev/sd*  #显示以sd开头的文件
/dev/sda  /dev/sda1  /dev/sda2

tree

显示当前内存使用量。tree [参数]

[root@hostname ~]# tree    #树状显示
.
├── anaconda-ks.cfg
├── backup.txt
├── Desktop
├── Documents
├── Downloads
├── initial-setup-ks.cfg
├── Music
├── Pictures
├── Public
├── Templates
└── Videos

8 directories, 3 files
[root@hostname ~]# tree -t #按修改时间排序
[root@hostname ~]# tree -f #带相对路径
[root@hostname ~]# tree -d #只显示目录的层级关系

find

按指定条件查找文件对应位置。find [查找范围] 寻找条件

[root@hostname ~]# find / -name *.conf  	#全盘搜索以.conf结尾的文件
[root@hostname ~]# find /etc -size +1M  	#/etc中搜索大于1M的文件
[root@hostname ~]# find /home -user toor    #/home目录中搜索指定用户toor的文件
[root@hostname ~]# find .				 	#列出当前目录所有文件、目录及子文件信息
[root@hostname ~]# find /var/log -name "*.log"	#/var/log下后缀为.log的文件
[root@hostname ~]# find /var/log !-name "*.log"	#/var/log下后缀不为.log的文件
[root@hostname ~]# find . -mtime +7		#当前工作目录最近7天被修改过的文件
[root@hostname ~]# find / -type d -perm 1777  #全盘搜索类型为目录,权限为1777的目录文件
# -exec...{
    
    } \;  {
    
    }代表被查到的文件
[root@hostname ~]# find / -name "*.mp4" -exec rm -rf {
    
    } \;  #全盘搜索后缀为.mp4的文件并删除
[root@hostname ~]# find / -user toor -exec cp -a {
    
    } /root/results/  \;  #全盘搜索用户toor的文件并复制到/root/results目录中

locate

按名称快速搜素文件对应位置,是基于数据文件(/var/lib/locatedb)定点查找。 locate [参数] 文件

[root@hostname ~]# updatedb #第一次执行前先生成索引数据库
[root@hostname ~]# locate network #搜索名称含nerwork的文件
[root@hostname ~]# locate /dev/network #搜索/dev目录下名称含nerwork的文件

whereis

按名称快速搜索二进制程序(命令)、源代码以及帮助文件对应的位置。

[root@hostname ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@hostname ~]# whereis pwd
pwd: /usr/bin/pwd /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz

which

按指定名称快速搜索二进制程序(命令)所对应位置。不关心同名文件(find/locate),也不关心源代码和帮助文件(whereis),查找命令本身所在路径。

[root@linuxprobe etc]# which locate
/usr/bin/locate
[root@linuxprobe etc]# which whereis
/usr/bin/whereis

参考

《Linux就该这么学》

猜你喜欢

转载自blog.csdn.net/weixin_47505548/article/details/130149517