练习题一:
1、在根下的usr下的games下创建两个目录分别为lianliankan和lol,在lianliankan目录下创建两个普通文件,这两个文件名分别为xiaoxiaole,xiaoxiaoxiao。
查看根下有无usr、games目录,出现下列现象,表示这两个目录存在:
[root@localhost ~]# ll /usr/games/
总用量 0
或者切换查看,切换成功即存在:
[root@localhost ~]# cd /usr/games/
[root@localhost games]#
进入/usr/games创建lianliankan和lol目录(使用相对路径):
[root@localhost games]# mkdir lianliankan lol
[root@localhost games]# ll
总用量 0
drwxr-xr-x. 2 root root 6 1月 15 23:04 lianliankan
drwxr-xr-x. 2 root root 6 1月 15 23:04 lol
或者在任何位置都可以这样创建目录(使用绝对路径):
[root@localhost lianliankan]# mkdir /usr/games/{lianliankan,lol}
创建xiaoxiaole和xiaoxiaoxiao文件(使用相对路径):
[root@localhost games]# cd lianliankan
[root@localhost lianliankan]# touch xiaoxiao{le,xiao}
[root@localhost lianliankan]# ll
总用量 0
-rw-r--r--. 1 root root 0 1月 15 23:07 xiaoxiaole
-rw-r--r--. 1 root root 0 1月 15 23:07 xiaoxiaoxiao
或者在任何位置都可以这样创建文件(使用绝对路径):
[root@localhost lianliankan]# touch /usr/games/lianliankan/xiaoxiao{le,xiao}
2、在xiaoxiaole里面写入内容“kaixin xiaoxiaole”,在xiaoxiaoxiao里面写入内容”nishi chaoxide“,将xiaoxiaoxiao的内容追加到xiaoxiaole里面。
[root@localhost lianliankan]# echo kaixin xiaoxiaole > ./xiaoxiaole(.是当前目录)
[root@localhost lianliankan]# cat xiaoxiaole
kaixin xiaoxiaole
[root@localhost lianliankan]# echo nishichaoxide > xiaoxiaoxiao
[root@localhost lianliankan]# cat xiaoxiaoxiao
nishichaoxide
[root@localhost lianliankan]# cat xiaoxiaoxiao >>xiaoxiaole(追加重定向)
[root@localhost lianliankan]# cat xiaoxiaole
kaixin xiaoxiaole
nishichaoxide
3、在/下创建一个普通文件叫waigua,在此文件里面写入内容”haha,woshi henlihaide“,将waigua文件移动到lianliankan目录下。
[root@localhost lianliankan]# echo haha,woshi henlihaide > /waigua(如果有waigua则执行,如果没有则创建waigua)
[root@localhost lianliankan]# cat /waigua
haha,woshi henlihaide
[root@localhost lianliankan]# mv /waigua .(.代表当前目录,使用相对路径)
或者:
[root@localhost lianliankan]# mv /waigua /usr/games/lianliankan/(使用绝对路径)
4、将waigua文件复制到lol目录中。
[root@localhost lianliankan]# ll
总用量 12
-rw-r--r--. 1 root root 22 1月 15 23:33 waigua
-rw-r--r--. 1 root root 32 1月 15 23:27 xiaoxiaole
-rw-r--r--. 1 root root 14 1月 15 23:24 xiaoxiaoxiao
[root@localhost lianliankan]# cp waigua ../lol/(..代表上一级目录)
[root@localhost lianliankan]# ll ../lol/
总用量 4
-rw-r--r--. 1 root root 22 1月 15 23:40 waigua
5、在/下的usr下创建一个目录名叫wangyou,移动该目录到games下面,将lol目录复制到wangyou目录下。
[root@localhost lianliankan]# mkdir /usr/wangyou
[root@localhost lianliankan]# mv /usr/wangyou/ ..
[root@localhost lianliankan]# cd ..
[root@localhost games]# ll
总用量 0
drwxr-xr-x. 2 root root 55 1月 15 23:35 lianliankan
drwxr-xr-x. 2 root root 19 1月 15 23:40 lol
drwxr-xr-x. 2 root root 6 1月 15 23:44 wangyou
[root@localhost games]# cp -r lol wangyou/
[root@localhost games]# ll
总用量 0
drwxr-xr-x. 2 root root 55 1月 15 23:35 lianliankan
drwxr-xr-x. 2 root root 19 1月 15 23:40 lol
drwxr-xr-x. 3 root root 16 1月 15 23:48 wangyou
[root@localhost games]# cd wangyou/
[root@localhost wangyou]# ll
总用量 0
drwxr-xr-x. 2 root root 19 1月 15 23:48 lol
练习题二:
1、在root用户的主目录下创建两个目录分别为haha和hehe,复制hehe目录到haha目录并重命名为apple。
创建目录的两种方式:
[root@localhost ~]# mkdir /root/haha /root/hehe
[root@localhost ~]# mkdir /root/{haha,hehe}
[root@localhost ~]# ll haha hehe (查看目录里面的文件)
haha:
总用量 0
hehe:
总用量 0
[root@localhost ~]# ll -d haha hehe (查看目录本身)
drwxr-xr-x. 2 root root 6 1月 17 22:41 haha
drwxr-xr-x. 2 root root 6 1月 17 22:41 hehe
[root@localhost ~]# cp -r /root/hehe /root/haha/apple
[root@localhost ~]# ll /root/haha/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 22:49 apple
[root@localhost ~]# ll -d /root/haha/apple/ (查看apple目录本身)
drwxr-xr-x. 2 root root 6 1月 17 22:49 /root/haha/apple/
2、将hehe目录移动到apple目录下,在haha目录下创建一个普通文件为heihei.txt。
[root@localhost ~]# mv /root/hehe /root/haha/apple
[root@localhost ~]# ll /root/hehe -d
ls: 无法访问/root/hehe: 没有那个文件或目录 (移动成功)
[root@localhost ~]# ll /root/haha/apple/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 22:41 hehe
[root@localhost ~]# touch /root/haha/heihei.txt
[root@localhost ~]# ll /root/haha/heihei.txt (查看)
[root@localhost ~]# ll /root/haha (或者这样查看)
总用量 0
drwxr-xr-x. 3 root root 17 1月 17 22:56 apple
-rw-r--r--. 1 root root 0 1月 17 23:00 heihei.txt
-rw-r--r--. 1 root root 0 1月 17 23:00 /root/haha/heihei.txt
3、写一个命令别名为aoe,他实现的功能为:列出上一题haha目录下的详细内容。
[root@localhost ~]# alias aoe='ll /root/haha'
[root@localhost ~]# aoe
总用量 0
drwxr-xr-x. 3 root root 17 1月 17 22:56 apple
-rw-r--r--. 1 root root 0 1月 17 23:00 heihei.txt
若想取消别名:
[root@localhost ~]# unalias aoe
4、在/usr/local/etc下创建一个目录为mulu1,创建一个普通文件为wenjian1。在/usr/local/bin创建一个目录为mulu2,创建一个普通文件为wenjian2。创建成功后使用ls命令以及它的选项来检查该题的正确性
首先查看/usr/local/etc是否存在
[root@localhost ~]# ll /usr/local/etc/
总用量 0
[root@localhost ~]# mkdir /usr/local/etc/mulu1
[root@localhost ~]# ll /usr/local/etc/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 23:10 mulu1
[root@localhost ~]# touch /usr/local/etc/wenjian1
[root@localhost ~]# ll /usr/local/etc/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 23:10 mulu1
-rw-r--r--. 1 root root 0 1月 17 23:10 wenjian1
同样也是查看/usr/local/bin是否存在
[root@localhost ~]# ll /usr/local/bin/
总用量 0
[root@localhost ~]# mkdir /usr/local/bin/mulu2
[root@localhost ~]# ll /usr/local/bin/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 23:14 mulu2
[root@localhost ~]# touch /usr/local/bin/wenjian2
[root@localhost ~]# ll /usr/local/bin/
总用量 0
drwxr-xr-x. 2 root root 6 1月 17 23:14 mulu2
-rw-r--r--. 1 root root 0 1月 17 23:14 wenjian2
5、温馨提示:使用echo、cat、>、>>命令。
(1)/下有目录text,text里面有文件b和g,文件b的内容为b is a boy,g的内容为g is a girl。
[root@localhost ~]# ll /text (先查看是否存在)
ls: 无法访问/text: 没有那个文件或目录
[root@localhost ~]# mkdir /text
[root@localhost ~]# touch /text/{b,g}
[root@localhost ~]# ll /text/
总用量 0
-rw-r--r--. 1 root root 0 1月 17 23:16 b
-rw-r--r--. 1 root root 0 1月 17 23:16 g
[root@localhost ~]# echo b is a boy > /text/b
[root@localhost ~]# cat /text/b
b is a boy
[root@localhost ~]# echo g is a girl > /text/g
[root@localhost ~]# cat /text/g
g is a girl
(2)在root的主目录里面创建文件bg,文件内容为what is bg,将根下的b和g的内容追加到bg文件下。
[root@localhost ~]# touch /root/bg
[root@localhost ~]# echo what is bg > /root/bg
[root@localhost ~]# cat /text/b /text/g
b is a boy
g is a girl
[root@localhost ~]# cat /text/b /text/g >> /root/bg
[root@localhost ~]# cat /root/bg
what is bg
b is a boy
g is a girl
6、(1)在根下面创建一个目录test,在test里面有一个文件为c,文件内容为c is a cat。
[root@localhost ~]# mkdir /test
[root@localhost ~]# touch /test/c
[root@localhost ~]# echo c is a cat > /test/c
[root@localhost ~]# cat /test/c
c is a cat
(2)在root的家目录下有一个目录为workbook,将test目录移动到workbook下面并重命名为practice。
[root@localhost ~]# mkdir /root/workbook
[root@localhost ~]# mv /test /root/workbook/practice
[root@localhost ~]# ll /root/workbook/practice/
总用量 4
-rw-r--r--. 1 root root 11 1月 17 23:24 c
[root@localhost ~]# ll /test (被移动)
ls: 无法访问/test: 没有那个文件或目录
(3)将文件c复制到根下并重命名为right。
[root@localhost ~]# cp /root/workbook/practice/c /right
[root@localhost ~]# cat /right
c is a cat