1. 创建一个目录/data。 
[root@StudyServer[1] oldboystudy]# mkdir data
[root@StudyServer[1] oldboystudy]# ll
total 4
drwxr-xr-x. 2 root root 4096 Apr 11 09:49 data
2. 在/data下面建立一个文件oldboy.txt。 
[root@StudyServer[1] oldboystudy]# cd data/
[root@StudyServer[1] data]# touch oldboy.txt
[root@StudyServer[1] data]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 11 09:53 oldboy.txt
[root@StudyServer[1] data]#
3. 为oldboy.txt增加内容为“I am studying linux.”。 
[root@StudyServer[1] data]# vim oldboy.txt 
[root@StudyServer[1] data]# cat oldboy.txt 
i am studying linux.
[root@StudyServer[1] data]#
4. 把oldboy.txt文件拷贝到/tmp下。 
[root@StudyServer[1] data]# cp oldboy.txt /tmp 
[root@StudyServer[1] data]# ll /tmp/
total 8
-rw-r--r--. 1 root root   21 Apr 11 09:55 oldboy.txt
drwx------. 2 root root 4096 Jan 13 16:31 pulse-GmmRjFD7HG5z
[root@StudyServer[1] data]#
5. 把/data目录移动到/root下。
[root@StudyServer[1] oldboystudy]# ll
total 4
drwxr-xr-x. 2 root root 4096 Apr 11 10:01 data
[root@StudyServer[1] oldboystudy]# mv  data/  /root
[root@StudyServer[1] oldboystudy]# ll
total 0
[root@StudyServer[1] oldboystudy]# cd
[root@StudyServer[1] ~]# ll
total 108
-rw-r--r--. 1 root root   143 Mar 16 14:39 !
-rw-------. 1 root root  1554 Dec 22 12:21 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 Apr 11 10:01 data

[root@StudyServer[1] ~]# ll data/
total 4
-rw-r--r--. 1 root root 21 Apr 11 09:55 oldboy.txt
[root@StudyServer[1] ~]#  
6. 进入/root目录下的data目录,删除oldboy.txt文件。 
[root@StudyServer[1] ~]# ll data/
total 4
-rw-r--r--. 1 root root 21 Apr 11 09:55 oldboy.txt
[root@StudyServer[1] ~]# 
[root@StudyServer[1] ~]# 
[root@StudyServer[1] ~]# 
[root@StudyServer[1] ~]# cd data/
[root@StudyServer[1] data]# rm -f oldboy.txt    #-f表示强制删除文件
[root@StudyServer[1] data]# ll
total 0
[root@StudyServer[1] data]#
7. 接第6题,退出到上一级目录,删除data目录。 
[root@StudyServer[1] data]# cd
[root@StudyServer[1] ~]# rm -f data/
rm: cannot remove `data/': Is a directory   #必须加上-r参数进行递归删除
[root@StudyServer[1] ~]# rm -rf data/     #递归强制删除目录
[root@StudyServer[1] ~]#
8. 已知文件test.txt内容为:
test
liyao	
oldboy 
9. 请给出输出test.txt文件内容时,不包含oldboy字符串的命令。 
[root@StudyServer[1] oldboystudy]# cat test.txt 
test
liyao
oldboy
[root@StudyServer[1] oldboystudy]# tail -n 2 test.txt 
liyao
oldboy
[root@StudyServer[1] oldboystudy]#
10. 请用一条命令完成创建目录/oldboy/test,即创建/oldboy目录及/oldboy/test目录 
[root@StudyServer[1] oldboystudy]# mkdir -p  /oldboy/test
[root@StudyServer[1] oldboystudy]# cd /oldboy/test/
[root@StudyServer[1] test]#
Mkdir常用的参数介绍:
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
#-p参数表示当父目录不存在是直接创建父目录,如该题中/oldboy目录不存在的情况下创建test这个目录时,需要使用-p参数自动创建test目录的父目录。
  -v, --verbose     print a message for each created directory
  -Z, --context=CTX  set the SELinux security context of each created
                      directory to CTX
      --help     display this help and exit
      --version  output version information and exit
11. 已知/tmp下已经存在test.txt文件,如何执行命令才能把/mnt/test.txt拷贝到/tmp下覆盖掉/tmp/test.txt,而让系统不提示是否覆盖(root权限下)。 
[root@StudyServer[1] ~]# cp -f -r  /mnt/test.txt /tmp/test.txt 
cp: overwrite `/tmp/test.txt'? 
[root@StudyServer[1] ~]#
#理论上来说,-r表示递归,-f表示强制。增加了-r和-f参数不会再提示是否覆盖的情况,但实际情况仍然会提示是否覆盖,什么原因呢?是别名在作怪,请看下面:
[root@StudyServer[1] ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
这就意味着,执行cp命令实际上执行的是cp –i命令。那么我们想要通过cp命令在不提示覆盖的前提下实现覆盖,就需要修改alias。
[root@StudyServer[1] ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
#alias cp='cp -i'   #将cp相关的alias注释掉
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
[root@StudyServer[1] ~]#
#注释掉后重新登录即可。
附上cp命令相关参数:
-R, -r, --recursive          copy directories recursively
      --reflink[=WHEN]         control clone/CoW copies. See below.
      --remove-destination     remove each existing destination file before
                                 attempting to open it (contrast with --force)
      --sparse=WHEN            control creation of sparse files. See below.
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 Argument
-f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (redundant if
                                 the -n option is used)
12. 只查看/etc/passwd文件(共100行)内第20到第30行的内容 
head -n 30 /etc/passwd | tail -n +20