RHCE033--文件查找与压缩和打包
时间:2010-09-27 来源:twenty_four
- which
显示一个可执行文件的完整路径[root@localhost ~]# which ls //查看命令ls这个可执行文件的完整路径alias ls='ls --color=tty'/bin/lswhich 首先查找系统中别名记录(alias),然后查找系统路径($PATH)[root@localhost ~]# which pwd/bin/pwd[root@localhost ~]# which halt/sbin/halt[root@localhost ~]# which cal/usr/bin/cal
- whereis
用于显示查找文件的路径、该文件的帮助文件路径、该文件的相关原程序的路径,例如:[root@localhost ~]# whereis fstabfstab: /etc/fstab /usr/include/fstab.h /usr/share/man/man5/fstab.5.gz[root@localhost ~]# whereis passwdpasswd: /usr/bin/passwd /etc/passwd.OLD /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz二、find- find 是我们最常用的文件查找工具,语法:
find [路径] [参数] [表达式][root@localhost ~]# find . -name "51cto" //查找当前目录含有51cto的文件命令 路径 参数 表达式./51ctofind的常用find参数如下:-user:根据文件拥有者寻找文件-group:根据文件所属组寻找文件-name:根据文件名寻找文件-perm:根据文件权限寻找文件-size:根据文件大小寻找文件-type:根据文件类型寻找文件,参数对应c、b、l、f、d[root@localhost ~]# find . -user 51cto //查找文件的拥有者是51cto的文件./51cto./51cto.com[root@localhost ~]# find . -group 51cto //查找文件的所属组是51cto的文件./51cto./51cto.com三、grep - 显示文件中匹配关键字的行- grep用来从一个文件中找出匹配指定关键字的那一行,并送到标准输出。
结合管道,我们通常用它来过滤搜索结果,用的超多!例如:[root@localhost ~]# ls -a |grep bash //列出含有bash的文件.bash_history.bash_logout.bash_profile.bashrc[root@localhost ~]# ls -a |grep 51cto //列出含有51cto的文件51cto51cto.com四、常用的文件操作指令- diff - 报告文本差异内容
[root@localhost ~]# echo "51cto">file1 //将“51cto”添加到file1中[root@localhost ~]# cat file151cto[root@localhost ~]# echo "51CTO">file2[root@localhost ~]# diff file1 file21c1< 51cto---> 51CTO- uniq - 去除文件中重复的行
-u参数可以只显示那些没有被重复过的行;-d显示有被重复过的行。[root@localhost ~]# cat 51ctothis is 51ctothis is 51ctothis is 51ctothis is 51ctothis is 51cto.com //观察到只有this is 51cto重复4次[root@localhost ~]# uniq -d 51cto //显示有被重复过的行this is 51ctothis is 51cto[root@localhost ~]# uniq -u 51cto//显示没有被重复过的行this is 51cto.comthis is 51cto.com五、压缩和打包在Linux系统中,常用的打包文件是.tar,压缩文件有tar.gz和.zip。可以使用tar命令将文件打包或者压缩成.tar.gz文件,处理.zip文件的命令有zip和unzip- tar命令
语法: tar 主选项 文件或目录说明:用于对多个文件或目录打包,但不压缩,同时可以用于解包。常用选项说明:-c 创建一个打包文件-v 详细报告tar处理的文件信息-f 使用打包文件或设备时是必选选项-x 解除打包文件的内容-z 用gzip来压缩/解压缩文件,加上这个选项后可以对打包文件进行压缩,同时还原时也一定要使用该选项来进行解压缩[root@localhost ~]# tar -cvf 51cto.tar 51cto //将51cto文件打包成51cto.tar51cto[root@localhost ~]# ll 51cto.tar-rw-r--r-- 1 root root 10240 Sep 27 02:56 51cto.tar[root@localhost ~]# tar -czvf 51cto.com.tar.gz 51cto.com//将51cto.com打包并且用gzip进行压缩成51cto.com.tar.gz51cto.com[root@localhost ~]# ll 51cto.com.tar.gz-rw-r--r-- 1 root root 136 Sep 27 02:58 51cto.com.tar.gz[root@localhost ~]# tar xvf 51cto.tar -C / //解包51cto.tar到根目录51cto[root@localhost ~]# cd / //切换到根目录[root@localhost /]# ll 51cto-rwSr-Sr-- 1 51cto 51cto 74 Sep 27 02:22 51cto常用选项说明:-d 将压缩文件解压-t 测试,检查压缩文件是否完整不加任何选项直接压缩- gzip命令
语法:gzip 选项 压缩(解压缩)的文件名说明:用于对系统文件进行压缩和解压缩,压缩后系统自动在源文件后加.gz扩展名[root@localhost ~]# gzip 51cto //压缩51cto文件成51cto.gz[root@localhost ~]# ll 51cto.gz-rw-r-Sr-- 1 51cto 51cto 46 Sep 27 02:22 51cto.gz[root@localhost ~]# ll 51cto //发现源文件51cto没了,被压缩了ls: 51cto: No such file or directory[root@localhost ~]# gzip -t 51cto.gz //检查压缩文件是否完整[root@localhost ~]# gzip -d 51cto.gz //解压51cto.gz[root@localhost ~]# ll 51cto-rw-r-Sr-- 1 51cto 51cto 74 Sep 27 02:22 51cto对于用gzip压缩的文件,有一系列以z为开头的文件,可以在不经解压的情况下,直接操作文件[root@localhost ~]# gzip 51cto[root@localhost ~]# cat 51cto.gz……乱码报错.....[root@localhost ~]# zcat 51cto.gzthis is 51ctothis is 51ctothis is 51ctothis is 51ctothis is 51cto.com- bzip2命令
语法:bzip2 选项 压缩文件说明:用于对文件或目录进行压缩或解压缩,压缩文件的扩展名默认为.bz2-d 将压缩文件解压-t 测试,检查压缩文件是否完整不加任何选项直接压缩[root@localhost ~]# bzip2 51cto //压缩51cto文件成51cto.bz2[root@localhost ~]# ll 51cto.bz2-rw-r-Sr-- 1 51cto 51cto 67 Sep 27 02:22 51cto.bz2[root@localhost ~]# ll 51cto //发现源文件51cto没了,被压缩了ls: 51cto: No such file or directory[root@localhost ~]# bzip2 -t 51cto.bz2 //检查压缩文件是否完整[root@localhost ~]# bzip2 -d 51cto.bz2 //解压51cto.bz2[root@localhost ~]# ll 51cto-rw-r-Sr-- 1 51cto 51cto 74 Sep 27 02:22 51cto相关阅读 更多 + - whereis
一、可执行文件的搜索