Linux练习

时间:2023-03-09 17:13:09
Linux练习

1.创建目录/perm ,在/perm目录下创建文件newfile ,授予/perm目录所有用户都有rwx权限;

#创建perm目录
[root@CentOS62 ~]# mkdir perm
[root@CentOS62 ~]# cd perm
#建立文件
[root@CentOS62 perm]# touch newfile
[root@CentOS62 perm]# cd ..
#设置权限
[root@CentOS62 ~]# chmod 777 perm

2,在/root目录下创建文件newfile2 ,移动文件newfile2到/perm目录下同时改名为file01 ;改变/perm/file01文件权限为“rwxrw-r–”;删除/perm目录

#建立文件
[root@CentOS62 ~]# touch newfile2
#移动文件
[root@CentOS62 ~]# mv newfile2 perm/file01
#设置权限
[root@CentOS62 ~]# chmod 764 perm/file01
#删除文件夹
[root@CentOS62 ~]# rm -ir perm
rm: descend into directory 'perm'? y
rm: remove regular empty file 'perm/file01'? y
rm: remove regular empty file 'perm/newfile'? y
rm: remove directory 'perm'? y

3.在/etc目录下查找所有后缀名为“.conf”的文件;在/boot目录下查找文件名为grub.conf的文件并同时列出文件的详细信息;在根目录下查找系统中大于100MB小于150MB的文件

#搜索".conf"文件
[root@CentOS62 ~]# find /etc -name '*.conf'
#搜索"grub.conf"文件
[root@CentOS62 ~]# find /boot -name 'grub.conf' -exec ls -l {} \;
-rw-------. 1 root root 795 Jul 19 2012 /boot/grub/grub.conf
#搜索大于100MB小于150MB的文件
[root@CentOS62 ~]# find /root -size +100M -size -150M

4.创建目录/comp ,拷贝文件/etc/services到/comp目录下,分别对services文件进行压缩,生成 .gz .zip .bz2三种格式的压缩包;

#创建文件夹
[root@CentOS62 ~]# mkdir comp
#拷贝文件
[root@CentOS62 ~]# cp /etc/services comp
[root@CentOS62 ~]# cd comp
#gzip模式压缩
[root@CentOS62 comp]# gzip services
#bz2模式压缩
[root@CentOS62 comp]# bzip2 services
#zip模式压缩
[root@CentOS62 comp]# zip services.zip /comp/services

5.查看/etc目录的详细信息(权限,大小等);查看/etc/目录下文件的详细信息时实现分页浏览;查看/etc目录下文件名包含.conf的文件有多少个;统计/etc目录下有多少个子目录

#搜索etc文件夹信息
[root@CentOS62 ~]# ls -ld /etc
drwxr-xr-x. 111 root root 12288 Aug 16 11:53 /etc
#搜索etc目录下文件名包含.conf的文件有多少个
[root@CentOS62 ~]# ls -l /etc |less
[root@CentOS62 ~]# find /etc -name '*.conf' | wc -l
402
#统计etc目录下有多少个子目录
[root@CentOS62 ~]# find /etc -type d | wc -l
328

6.将文件1.txt和2.txt合并成一个文件12.txt

#建立文件
[root@CentOS62 ~]# touch 1.txt 2.txt
#合并文件
[root@CentOS62 ~]# cat 1.txt 2.txt > 12.txt

7.目录ABC下有两个子目录a1,a2,以及5个普通文件,如果想删除ABC目录,应该使用什么样的命令?

[root@CentOS62 ~]# rm -r ABC

8.在文件1.txt中查找包含字符串“name”的行,将其输出在屏幕上

[root@CentOS62 ~]# grep 'name' 1.txt
this is name
name2

9,对文件2.tar.gz进行解压缩、解包操作

#打包命令
[root@CentOS62 ~]# tar -zpcv -f /root/2.tar.gz 1.txt
#解包命令
[root@CentOS62 ~]# tar -zxv -f 2.tar.gz

10,给用户增加对文件file1.c的读和写权限

[root@CentOS62 ~]# chmod 666 file1.c

11.将文件a.c b.c打包成文件ab.tar,放在目录/home/ks/a下

[root@CentOS62 ~]# tar -cv -f /home/ks/a/ad.c.tar a.c b.c          

12.连续显示file1, file2, file3三个文件的内容

#创建文件
[root@CentOS62 ~]# vi file1
[root@CentOS62 ~]# vi file2
[root@CentOS62 ~]# vi file3
#显示文件
[root@CentOS62 ~]# cat file1 file2 file3
this is 1
this is 2
this is 3

13.列出所有的文件系统,查看磁盘与目录的使用情况

[root@CentOS62 ~]# df -am