文件查找
1.which
用於顯示命令的完全路徑
[root@localhost ~]# which ls
alias ls='ls --color=tty'
/bin/ls //命令的完全路徑是/bin/ls
[root@localhost ~]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@localhost ~]# which cd
/usr/bin/which: no cd in (/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin)
which 查找命令的路徑是環境變數規定的路徑
2.whereis 用於查找命令的的路徑、該文件的幫助文件、該文件的相關程序的路徑
[root@localhost ~]# whereis ls
ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz
3.locate
所有包含關鍵欄位的文件和目錄都會顯示.locate是搜索一個資料庫,資料庫里包括當前目錄.
[root@localhost ~]# locate passwd
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/lib/security/pam_passwdqc.so
/lib/security/pam_unix_passwd.so
……
新建立的文件的目錄無法自動寫入資料庫,需手動更新資料庫
[root@localhost ~]# touch Loveyouforever
[root@localhost ~]# locate Loveyouforever//無法找到文件目錄
[root@localhost ~]# updatedb//手動更新資料庫
[root@localhost ~]# locate Loveyouforever
/root/Loveyouforever//找到文件目錄
4.find
非常強大的查找命令,現對花費時間會很長,非常消耗資源.很常用
格式
find [目錄] [選項] [條件表達式] [-exec,-ok……]指令 {} \;
find /etc -name passwd -exec ls -l {} \;
-group -nogroup找屬組滿足條件的文件 用法同-user -nouser
-perm 查找許可權滿足條件的文件
find -perm num 查找許可權是num的文件
-perm -num 查找許可權全部包括num的文件
-perm num 查找許可權部分包括num的文件
[root@localhost ~]# find / -perm 777 -ok ls -l {} \;|more
< ls ... /bin/sh > ? < ls ... /bin/traceroute6 > ? < ls ... /bin/egrep > ? lrwxrwxrwx 1 root root 10 01-15 04:51 /bin/traceroute6 -> traceroute
-size 查找文件大小滿足條件的文件
-size num (單位) 大於num(單位)的文件
-size -num(單位) 小於num(單位)的文件
[root@localhost ~]# dd if=/dev/zero of=/root/hello bs=1M count=200
200 0 records in
200 0 records out
209715200 bytes (210 MB) copied, 1.01237 seconds, 207 MB/s
[root@localhost ~]# find ./ -size 100M -exec ls -l {} \;
-rw-r--r-- 1 root root 209715200 01-19 01:05 ./hello
-type查找某一類型的文件,主要有以下幾種
條件
b 塊設備文件
d 目錄
c 字元設備文件
p 管道文件
l 鏈接文件
f 普通文件
find -mtime -n n
-n n天之內
+n n天以為
n n天以前的 24時小時以內
打包歸檔及壓縮
1.unzip,zip
-l列出壓縮文件多包含的內容
-v顯示詳細的壓縮過程
[root@localhost ~]# zip -lv cc.zip cc//壓縮cc 為cc.zip
adding: cc/ (in=0) (out=0) (stored 0%)
total bytes=0, compressed=0 -> 0% savings
[root@localhost ~]# ls
anaconda-ks.cfg cc.zip install.log Loveyouforever
cc Desktop install.log.syslog 小鳥chacha初學linux.ncd
2.gzip和zcat
-#:壓縮等級.-1最快,壓縮比最差;-9最慢,壓縮比最小
[root@localhost ~]# gzip -9 Loveyouforever
[root@localhost ~]# ls
anaconda-ks.cfg Desktop install.log.syslog 小鳥chacha初學linux.ncd
cc install.log Loveyouforever.gz
[root@localhost temp]# zcat redhat.txt.gz
what do you want to do?
shut up
3.tar
-c 建立壓縮文件
-x解壓文件
-v顯示壓縮 解壓過程
-f 緊跟壓縮文件名稱
-t 查看壓縮文件
[root@localhost /]# tar -cvf root.tar /root cvf壓縮的常用組合
tar: 從成員名中刪除開頭的“/”
/root/
/root/小鳥chacha初學linux.ncd
/root/.metacity/
/root/.metacity/sessions/
/root/.metacity/sessions/1326903016-2435-745770735.ms
/root/.metacity/sessions/1326578140-2447-2422197700.ms
/root/.metacity/sessions/1326653136-2469-468411399.ms
/root/.metacity/sessions/1326575460-2584-1184827547.ms
/root/.metacity/sessions/1326744477-2478-3945392455.ms
/root/.config/
/root/.config/gtk-2.0/
/root/.config/gtk-2.0/gtkfilechooser
/root/.nautilus/
/root/.nautilus/metafiles/
……
[root@localhost /]# tar -tvf root.tar //查看tar文件中的內容
drwxr-x--- root/root 0 2012-01-19 02:34:28 root/
-rw------- root/root 22215 2012-01-19 02:34:28 root/小鳥chacha初學linux.ncd
drwx------ root/root 0 2012-01-15 05:11:00 root/.metacity/
drwx------ root/root 0 2012-01-19 00:10:16 root/.metacity/sessions/
-rw-r--r-- root/root 355 2012-01-19 00:10:16 root/.metacity/sessions/1326903016-2435-745770735.ms
-rw-r--r-- root/root 355 2012-01-15 05:55:40 root/.metacity/sessions/1326578140-2447-2422197700.ms
-rw-r--r-- root/root 355 2012-01-16 02:45:36 root/.metacity/sessions/1326653136-2469-468411399.ms
本文出自 「初學linux」 博客,請務必保留此出處http://zhxchacha.blog.51cto.com/4277964/767226
[火星人 ] 小鳥chacha初學linux 文件查找、歸檔、壓縮已經有617次圍觀