Linux文件系统的要点

试验4 Linux文件系统的要点

实验内容:使用find查找文件,归档压缩文件。

步骤1:使用find命令
任务:
以student帐号登录。
查看你当前的umask。
设计并且运行find命令,在下列各指令执行后,将结果写在横线处。
可能需要在在find的man page里查找。能用/stringz在 man page里查找。
1.在/var/lib目录下查找所有文件其所有者是games用户的文件
$ find /var/lib –user games 2> /dev/null

2. 在/var目录下查找所有文件其所有者是root用户的文件的命令是。
$find /var -user root -group mail 2> /dev/null
_______________________________________________________

3.查找/tmp下 所有文件其所有者不是root和student用户并用长格式显示(如ls –l 的显示结果)。
find /tmp -not -user root -and -not -user student -ls
find /tmp -not -user root -and -not -user student | ls -l
find / -not –user root –not –user bin –not –user student –ls 2> /dev/null
or
find / ! –user root ! –user bin ! –user student –exec ls –ld {} \; 2> /dev/null

4.查找/usr/bin目录下所有大小超过一百万bytes的文件并用长格式显示(如ls –l 的显示结果)。
find /usr/bin -size +1000000c -ls

5.对/etc/mail目录下的所有文件使用file命令.
$file /etc/mail/*
$find /etc/mail/ -exec file {} \;
_________________________________________________________
6.查找/tmp目录下属于student的所有普通文件,这些文件的修改时间为120分钟以前,查询结果用长格式显示(如ls –l 的显示结果)。

find /tmp -cmin -120 -user student -ls

7. 对于查到的上述文件,用-ok选项删除。

find /tmp -cmin -120 -user student -ok rm {} \;


步骤2:归档和压缩

情景/故事:
你的系统上的主硬盘在你使用它的时候有可怕的噪音,但是它上面有有价值的数据。系统在两年半以前备份过,你决定手动备份少数几个最紧要的文件。 /tmp 目录储存在不同的硬盘的分区上,你想临时的把快坏的分区文件备份到那里。

任务:
1. 在/home目录里,用find命令定位文件所有者是student的文件。然后将其压缩。
$ find /home -user student -exec tar rvf /tmp/backup.tar {} \;

2. 保存/etc目录下的文件到/tmp目录下:
$ tar cvf /tmp/confbackup.tar /etc

3. 列出两个文件的大小
$ ls –lh /tmp/*.tar
backup.tar文件的大小_11M_______
confbackup.tar文件的大小___60M_____

4. 使用gzip压缩你的文档。然后报告文件的大小:
$ cd /tmp
$ gzip –v *.tar
$ ls –lh *tar*
backup.tar.gz文件大小为___2.9M_________
backup.tar.gz文件的压缩百分比__72.9%______
confbackup.tar.gz文件大小为____8.3M________
confbackup.tar.gz文件的压缩百分比___86.1%__

5. 先解压缩gzip文件然后再用bzip2压缩,比较新文件的大小:
$ gunzip *.gz

$ ls –lh *.tar ls

$ bzip2 –v *.tar
$ ls –lh *.bz2

backup.tar.bz2文件大小为__3.4M__________
backup.tar.bz2文件的压缩百分比_68.89%_______
confbackup.tar.bz2文件大小为___5.7M_________
confbackup.tar.bz2文件的压缩百分比__90.49%______

6. 在传统UNIX系统,


$ rm confbackup.tar.bz2
$ tar czf test1.tgz /etc
$ tar cjf test2.tbz /etc

$ file test*
test1.tgz:gzip compressed data,deflated,last modified:Wed Oct 18 01:52:11 2000,os:Unix
test2.tbz:bzip2 compressed data,block size = 900K

结果:
你的“重要数据”被压缩备份到/tmp目录里了。

问题答案2

2. find /var –user root –group mail 2>/dev/mull
3. find / -not –user root –not –user bin –not –user student –ls 2> /dev/null
or
find / ! –user root ! –user bin ! –user student –exec ls –ld {} \; 2> /dev/null

4. find /usr/bin –size +1000000c –ls 2> /dev/null
5. find /etc/maill –exec file {} \; 2 > /dev/null
6. find /tmp –user student –and –mmin +120 –and –type f –ls 2> /dev/null
7. find /tmp –user student –and –mmin +120 –and –type f –ok rm {} \;


相关文档
最新文档