您的位置:首页 > 运维架构 > Linux

Linux初学练习

2016-09-21 22:56 211 查看
1.用命令和正则表达式按照要求建立文件
*)用一条命令建立12个文件WESTOS_classX_linuxY(X的数值范围为1-2,Y的数值范围为1-6)
*)这些文件都包含在root用户桌面的study目录中

[root@localhost home]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg  Documents  Music     Public     Videos
Desktop          Downloads  Pictures  Templates
[root@localhost ~]# cd Desktop/
[root@localhost Desktop]# cd study/
bash: cd: study/: No such file or directory
[root@localhost Desktop]# mkdir study
[root@localhost Desktop]# ls
9.200   9.21   hehe~      study            westos
9.200~  9.21~  hello.exe  Untitled Folder  westos~
[root@localhost Desktop]# cd study/
[root@localhost study]# touch WESTOS_classX{1..2}_linuxY{1..6}
[root@localhost study]# ls
WESTOS_classX1_linuxY1  WESTOS_classX1_linuxY5  WESTOS_classX2_linuxY3
WESTOS_classX1_linuxY2  WESTOS_classX1_linuxY6  WESTOS_classX2_linuxY4
WESTOS_classX1_linuxY3  WESTOS_classX2_linuxY1  WESTOS_classX2_linuxY5
WESTOS_classX1_linuxY4  WESTOS_classX2_linuxY2  WESTOS_classX2_linuxY6

*)用一条命令建立8个文件redhat_versionX(x的范围为1-8)
*)redhat_virsionX这些文件都包含在/mnt目录中的VERSION中

[root@localhost Desktop]# touch redhat_versionX{1..8}
[root@localhost Desktop]# ls
9.200   hehe~             redhat_versionX3  redhat_versionX7  westos
9.200~  hello.exe         redhat_versionX4  redhat_versionX8  westos~
9.21    redhat_versionX1  redhat_versionX5  study
9.21~   redhat_versionX2  redhat_versionX6  Untitled Folder
[root@localhost Desktop]# mv redhat_version* /mnt/VERSION
mv: target ‘/mnt/VERSION’ is not a directory
[root@localhost Desktop]# cd /home
[root@localhost home]# ls
student
[root@localhost ~]# cd /mnt
[root@localhost mnt]# mkdir VERSION
[root@localhost mnt]# cd Desktop
bash: cd: Desktop: No such file or directory
[root@localhost mnt]# cd /root/Desktop/
[root@localhost Desktop]# mv redhat_versionX* /mnt/VERSION/
[root@localhost Desktop]# cd /mnt/VERSION/
[root@localhost VERSION]# ls
redhat_versionX1  redhat_versionX3  redhat_versionX5  redhat_versionX7
redhat_versionX2  redhat_versionX4  redhat_versionX6  redhat_versionX8

2.管理刚才新建立的文件要求如下
*)用一条命令把redhat_versionX中的带有奇数的文件复制到桌面的SINGLE中

[root@localhost Desktop]# cp /mnt/VERSION/redhat_versionX{1,3,5,7,9} SINGLE
[root@localhost Desktop]# cd SINGLE/
[root@localhost SINGLE]# ls
redhat_versionX1  redhat_versionX3  redhat_versionX5  redhat_versionX7

*)用一条命令把redhat_versionX中的带偶数数的文件复制到/DOUBLE中

[root@localhost SINGLE]# cd ..
[root@localhost Desktop]# mkdir DOUBLE
[root@localhost Desktop]# ls
9.200   9.21   DOUBLE  hello.exe  study            westos
9.200~  9.21~  hehe~   SINGLE     Untitled Folder  westos~
[root@localhost Desktop]# cp /mnt/VERSION/redhat_versionX{2,4,6,8} DOUBLE/
[root@localhost Desktop]# cd DOUBLE/
[root@localhost DOUBLE]# ls
redhat_versionX2  redhat_versionX4  redhat_versionX6  redhat_versionX8
[root@localhost DOUBLE]#

*)用一条命令把WESTOS_classX_linuxY中class1的文件移动到当前用户桌面的CLASS1中
这部分要注意移动文件要将study(即WESTOS_class1_linuxY所在位置)作为当前位置。
[root@localhost study]# mv WESTOS_classX1_linuxY{1..6} /root/Desktop/CLASS1
[root@localhost study]# ls
WESTOS_classX2_linuxY1  WESTOS_classX2_linuxY3  WESTOS_classX2_linuxY5
WESTOS_classX2_linuxY2  WESTOS_classX2_linuxY4  WESTOS_classX2_linuxY6

*)用一条命令把WESTOS_classX_linuxY中class2的文件移动到当前用户桌面的CLASS2中

[root@localhost study]# mv WESTOS_classX2_linuxY{1..6} /root/Desktop/CLASS2
[root@localhost study]# cd ..
[root@localhost Desktop]# cd CLASS2
[root@localhost CLASS2]# ls
WESTOS_classX2_linuxY1  WESTOS_classX2_linuxY3  WESTOS_classX2_linuxY5
WESTOS_classX2_linuxY2  WESTOS_classX2_linuxY4  WESTOS_classX2_linuxY6

3.备份/etc目录中所有名字带有数字并且以.conf结尾的文件到桌面上的confdir中
这部分因为一些原因电脑不能运行,有错误的话请多指教。
[root@localhost study]# cp /etc*[[:digit:]]*.conf confdir/

5.删掉刚才建立或者备份的所有文件
rm -f    ##强制删除文件
rm -fr   ##强制删除目录
[root@localhost Desktop]# rm -fr CLASS*
[root@localhost Desktop]# rm -fr SINGLE
[root@localhost Desktop]# rm -fr confdir
[root@localhost Desktop]# rm -fr DOUBLE
[root@localhost Desktop]# rm -fr study
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 用户 表达式