单纯提供一个相对的解答,并不是标准答案!
单纯就是个解答的参考,写完之后再来这边查查看答案跟你想的一样不一样!?
[student@station10-101 ~]$ cd /dev/shm [student@station10-101 shm]$ pwd /dev/shm
[student@station10-101 shm]$ mkdir class3 [student@station10-101 shm]$ ll 总计 0 drwxrwxr-x. 2 student student 40 3月 10 08:30 class3 <==确实存在这个目录了!
[student@station10-101 shm]$ ll class3/ 总计 0 # 在观察该目录时,缺省好像没任何数据存在。 [student@station10-101 shm]$ ll -a class3/ 总计 0 drwxrwxr-x. 2 student student 40 3月 10 08:30 . drwxrwxrwt. 3 root root 60 3月 10 08:30 .. # 再观察隐藏档,其实,空目录里面确实存在了两个隐藏档,分别是 . 与 .. 这两个目录!
[student@station10-101 shm]$ cp /etc/hosts class3 [student@station10-101 shm]$ ll -a class3/ 总计 4 drwxrwxr-x. 2 student student 60 3月 10 08:34 . drwxrwxrwt. 3 root root 60 3月 10 08:30 .. -rw-r--r--. 1 student student 158 3月 10 08:34 hosts # 数据确实拷贝进来咯!
[student@station10-101 shm]$ ll 总计 0 drwxrwxr-x. 2 student student 60 3月 10 08:34 class3 # 先确定一下,确实有存在这个目录文件喔! [student@station10-101 shm]$ rmdir class3/ rmdir: failed to remove 'class3/': 目录不是空的 # 但是无法删除~说是目录不是空的。一般来说,所谓的『空目录』指的是该目录底下除了 . 与 .. 之外,不存在任何其他文件名,就是所谓的空目录。以上面这个案例来说, 因为 class3 还有存在 hosts 这个文件,因此当然就不是空目录。而 rmdir 缺省只能删除空目录,使用 --help 确认一下:
[student@station10-101 shm]$ rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.
....
所以,自然无法删除 class3 这个目录了。[student@station10-101 shm]$ cd class3/ [student@station10-101 class3]$ ll 总计 4 -rw-r--r--. 1 student student 158 3月 10 08:34 hosts # 删除是很可怕的行为,所以,进行删除之前,请务必先以 ll 查看一下你要删除的目录与数据是否正确! # 在本例中,该目录下只有 hosts ,观察的结果是正确的!所以可以放心删除了 [student@station10-101 class3]$ rm * [student@station10-101 class3]$ ll 总计 0 [student@station10-101 class3]$ ll -a 总计 0 drwxrwxr-x. 2 student student 40 3月 10 08:42 . drwxrwxrwt. 3 root root 60 3月 10 08:30 .. # 目录中又只剩下 . 与 .. 的空目录状态
[student@station10-101 class3]$ cd .. [student@station10-101 shm]$ ll 总计 0 drwxrwxr-x. 2 student student 40 3月 10 08:42 class3 # 确实存在 class3 这个目录 [student@station10-101 shm]$ rm class3 rm: 无法移除 'class3': 是个目录 [student@station10-101 shm]$ rmdir class3/ [student@station10-101 shm]$ ll 总计 0 # 确定删除了!因为 rm 『缺省』只能删除文件,不能删除目录档,除非加上某些特定的选项才行。所以,还是以 rmdir 来删除空目录才是。
[student@station10-101 shm]$ ll -d /etc/?????
drwxr-x---. 4 root root 100 2月 26 09:15 /etc/audit
drwxr-xr-x. 4 root root 71 2月 26 09:06 /etc/avahi
drwxr-xr-x. 4 root root 31 2月 26 09:03 /etc/dconf
drwxr-xr-x. 3 root root 38 2月 26 09:03 /etc/fonts
-rw-r--r--. 1 root root 655 2月 26 09:01 /etc/fstab
drwxr-xr-x. 3 root root 79 2月 26 09:05 /etc/fwupd
......
如上表,你可以看到输出的文件名都是 5 个字符!
[student@station10-101 shm]$ ll -d /etc/*[0-9]*
drwxr-xr-x. 4 root root 78 2月 26 09:03 /etc/dbus-1
-rw-r--r--. 1 root root 5214 5月 12 2019 /etc/DIR_COLORS.256color
lrwxrwxrwx. 1 root root 22 11月 26 00:08 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
drwxr-xr-x. 2 root root 159 2月 26 09:03 /etc/iproute2
-rw-r--r--. 1 root root 812 11月 9 01:10 /etc/krb5.conf
drwxr-xr-x. 2 root root 55 2月 26 09:06 /etc/krb5.conf.d
......
[student@station10-101 ~]$ cd /dev/shm [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 # 确定不存在 rc1.d
[student@station10-101 shm]$ cp -r /etc/rc.d/rc1.d rc1.d [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 drwxr-xr-x. 2 student student 40 3月 10 09:26 rc1.d <==有这个文件名存在! [student@station10-101 shm]$ ll rc1.d 总计 0 # 目录底下暂时没数据
[student@station10-101 shm]$ cp -r /etc/rc.d/rc1.d rc1.d [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 drwxr-xr-x. 3 student student 60 3月 10 09:28 rc1.d <==变化不大,只是时间参数改变了 [student@station10-101 shm]$ ll rc1.d 总计 0 drwxr-xr-x. 2 student student 40 3月 10 09:28 rc1.d <==竟然多了这个文件名出现!第一次拷贝时,该目录底下并没有该文件,所以拷贝行为没问题。第二次拷贝时,该目标目录是存在的!所以, 第二次拷贝时,会将该目录放置到新目录底下去,于是就出现最后一行的状态。这个在运行备份的脚本制作时, 得要特别注意这个问题!
[student@station10-101 shm]$ cd /dev/shm [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 drwxr-xr-x. 3 student student 60 3月 10 09:28 rc1.d <==目标目录文件名 [student@station10-101 shm]$ rm rc1.d rm: 无法移除 'rc1.d': 是个目录 <==缺省就是不能杀目录 [student@station10-101 shm]$ rm -r rc1.d <==加上 -r 才能删除目录! [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2
[student@station10-101 shm]$ rm --help 用法:rm [选项]... [文件]... Remove (unlink) the FILE(s). ...... To remove a file whose name starts with a '-', for example '-foo', use one of these commands: rm -- -foo rm ./-foo ......在查找的结果当中发现,文件名的处理可以使用两种方式,但鸟哥个人比较建议使用相对路径、绝对路径的文件名处理方式来略过减号 (-) 的问题即可! 不要增加许多背诵的问题~
[student@station10-101 shm]$ rm -r ./-newdir* or [student@station10-101 shm]$ rmdir ./-newdir*
[student@station10-101 ~]$ file /etc/rc0.d /etc/rc.d/rc0.d /dev/null /dev/vda /etc/rc0.d: symbolic link to rc.d/rc0.d <==链接档 /etc/rc.d/rc0.d: directory <==目录档 /dev/null: character special (1/3) <==周边界面档 /dev/vda: block special (252/0) <==区块设备 (一般是保存媒体)
[student@station10-101 shm]$ cd [student@station10-101 ~]$ pwd /home/student
[student@station10-101 ~]$ ll -d /etc/rpm drwxr-xr-x. 2 root root 25 11月 9 06:56 /etc/rpm [student@station10-101 ~]$ cp -a /etc/rpm . [student@station10-101 ~]$ ll -d rpm drwxr-xr-x. 2 student student 25 11月 9 06:56 rpm
[student@station10-101 ~]$ mv rpm /dev/shm [student@station10-101 ~]$ ll -d rpm ls: 无法访问 'rpm': 没有此一文件或目录 [student@station10-101 ~]$ ll /dev/shm 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 drwxr-xr-x. 2 student student 60 11月 9 06:56 rpm <==在这里了
[student@station10-101 ~]$ cd /dev/shm [student@station10-101 shm]$ ll -d rpm drwxr-xr-x. 2 student student 60 11月 9 06:56 rpm [student@station10-101 shm]$ mv rpm init.d3 [student@station10-101 shm]$ ll 总计 0 drwxr-xr-x. 2 student student 80 3月 10 09:13 init.d drwxr-xr-x. 2 student student 80 2月 26 09:05 init.d2 drwxr-xr-x. 2 student student 60 11月 9 06:56 init.d3 <==在这里了
# 先创建所需要的工作目录 [student@station10-101 shm]$ mkdir /dev/shm/testing [student@station10-101 shm]$ cd /dev/shm/testing [student@station10-101 testing]$ pwd /dev/shm/testing # 开始创建这许多的空文件 [student@station10-101 testing]$ touch mytest_{jan,feb,mar,apr}_{one,two,three}_{a1,b1,c1} [student@station10-101 testing]$ ls mytest_apr_one_a1 mytest_feb_one_a1 mytest_jan_one_a1 mytest_mar_one_a1 mytest_apr_one_b1 mytest_feb_one_b1 mytest_jan_one_b1 mytest_mar_one_b1 mytest_apr_one_c1 mytest_feb_one_c1 mytest_jan_one_c1 mytest_mar_one_c1 mytest_apr_three_a1 mytest_feb_three_a1 mytest_jan_three_a1 mytest_mar_three_a1 mytest_apr_three_b1 mytest_feb_three_b1 mytest_jan_three_b1 mytest_mar_three_b1 mytest_apr_three_c1 mytest_feb_three_c1 mytest_jan_three_c1 mytest_mar_three_c1 mytest_apr_two_a1 mytest_feb_two_a1 mytest_jan_two_a1 mytest_mar_two_a1 mytest_apr_two_b1 mytest_feb_two_b1 mytest_jan_two_b1 mytest_mar_two_b1 mytest_apr_two_c1 mytest_feb_two_c1 mytest_jan_two_c1 mytest_mar_two_c1
[student@station10-101 testing]$ mkdir /dev/shm/student [student@station10-101 testing]$ cd /dev/shm/student [student@station10-101 student]$ touch 4XXXC0{01..50} [student@station10-101 student]$ ls 4XXXC001 4XXXC006 4XXXC011 4XXXC016 4XXXC021 4XXXC026 4XXXC031 4XXXC036 4XXXC041 4XXXC046 4XXXC002 4XXXC007 4XXXC012 4XXXC017 4XXXC022 4XXXC027 4XXXC032 4XXXC037 4XXXC042 4XXXC047 4XXXC003 4XXXC008 4XXXC013 4XXXC018 4XXXC023 4XXXC028 4XXXC033 4XXXC038 4XXXC043 4XXXC048 4XXXC004 4XXXC009 4XXXC014 4XXXC019 4XXXC024 4XXXC029 4XXXC034 4XXXC039 4XXXC044 4XXXC049 4XXXC005 4XXXC010 4XXXC015 4XXXC020 4XXXC025 4XXXC030 4XXXC035 4XXXC040 4XXXC045 4XXXC050
[student@station10-101 ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[student@station10-101 ~]$ cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
......
[student@station10-101 ~]$ cat --help 用法:cat [选项]... [文件]... Concatenate FILE(s) to standard output. ...... -n, --number number all output lines ...... [student@station10-101 ~]$ cat -n /etc/profile 1 # /etc/profile 2 3 # System wide environment and startup programs, for login setup 4 # Functions and aliases go in /etc/bashrc 5 ...... 83 . /etc/bashrc 84 fi 85 fi
[student@station10-101 ~]$ head /etc/profile
[student@station10-101 ~]$ tail /etc/passwd
[student@station10-101 ~]$ tail --help 用法:tail [选项]... [文件]... Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. ...... -n, --lines=[+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM ...... [student@station10-101 ~]$ tail -n 5 /etc/services
[student@station10-101 shm]$ cd [student@station10-101 ~]$ history ...... 334 cd /dev/shm 335 mkdir "class one" 336 ll ...... 391 touch mytest_{jan,feb,mar,apr}_{one,two,three}_{a1,b1,c1} 392 ls 393 mkdir /dev/shm/student 394 cd /dev/shm/student 395 touch 4XXXC0{01..50} ...... 408 vim services 409 cd 410 history假设看起来就是 334 到 410 之间的指令,所以大概有 80 行左右。
[student@station10-101 ~]$ history 80 >> ~/history.log
[student@station10-101 ~]$ vim ~/history.log 334 cd /dev/shm 335 mkdir "class one" 341 rmdir class one 342 rmdir class\ one/ 345 mkdir /dev/shm/-newdir 346 mkdir ./-newdir2 347 ll -d ./*new* 348 rm --help 350 rm -r ./-newdir* 353 ll -a # 上面的反白处理流程是这样的: # 1. 先到第一列的第一个字符上面,按下 [ctrl]+v ,这时会变成选取模式 # 2. 使用方向键,移动到最底下,然后向右,就可以圈选到你的范围 # 3. 按下 d ,就可以删除上面圈选的部份了! # 4. 最后按下 :w 保存,再按下 :q 就可以离开!
[student@station10-101 ~]$ vim /dev/shm/mycheck.txt [student@station10-101 ~]$ ll /dev/shm/mycheck.txt -rw-rw-r--. 1 student student 17 3月 10 22:54 /dev/shm/mycheck.txt [student@station10-101 ~]$ cat /dev/shm/mycheck.txt 鸟哥 4070CXXX
[student@station10-101 ~]$ file /etc/group /bin/groups /etc/group: ASCII text /bin/groups: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=5818633243684d2d3bf73b27cf5480d69dc2b8eb, stripped, too many notes (256) [student@station10-101 ~]$ file /etc/group /bin/groups >> /dev/shm/mycheck.txt [student@station10-101 ~]$ cat /dev/shm/mycheck.txt 鸟哥 4070CXXX /etc/group: ASCII text /bin/groups: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=5818633243684d2d3bf73b27cf5480d69dc2b8eb, stripped, too many notes (256)
[student@station10-101 ~]$ ll -d /etc/s*s -rw-r--r--. 1 root root 692241 9月 10 2018 /etc/services -rw-r--r--. 1 root root 44 9月 10 2018 /etc/shells drwxr-xr-x. 3 root root 74 2月 26 09:06 /etc/smartmontools -r--r-----. 1 root root 4328 12月 13 20:56 /etc/sudoers [student@station10-101 ~]$ ll -d /etc/s*s >> /dev/shm/mycheck.txt [student@station10-101 ~]$ tail -n 4 /dev/shm/mycheck.txt -rw-r--r--. 1 root root 692241 9月 10 2018 /etc/services -rw-r--r--. 1 root root 44 9月 10 2018 /etc/shells drwxr-xr-x. 3 root root 74 2月 26 09:06 /etc/smartmontools -r--r-----. 1 root root 4328 12月 13 20:56 /etc/sudoers
[student@station10-101 ~]$ history | grep 'rm ' 191 rm --help 192 rm /dev/shm/backup/etc/passwd* 196 rm /dev/shm/backup/etc/X11 198 rm -r /dev/shm/backup/etc/X11 201 rm -ri /dev/shm/backup/etc/xdg/ 202 rm -rI /dev/shm/backup/etc/xdg/ 239 rm ./X11/xinit 240 rm -r ./X11/xinit 258 rm hosts 269 rm * 275 rm class3 289 rm rc0.d 293 rm rc0.d 308 rm -r rc0.d/ 313 rm init.d 331 rm rc1.d 332 rm -r rc1.d 348 rm --help 350 rm -r ./-newdir* 446 history | grep 'rm ' [student@station10-101 ~]$ history | grep 'rm ' >> /dev/shm/mycheck.txt
[student@station10-101 ~]$ cat -n /etc/passwd | head -n 5 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin 3 daemon:x:2:2:daemon:/sbin:/sbin/nologin 4 adm:x:3:4:adm:/var/adm:/sbin/nologin 5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin [student@station10-101 ~]$ cat -n /etc/passwd | tail -n 5 40 gnome-initial-setup:x:979:977::/run/gnome-initial-setup/:/sbin/nologin 41 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 42 avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin 43 tcpdump:x:72:72::/:/sbin/nologin 44 student:x:1000:1000:student:/home/student:/bin/bash [student@station10-101 ~]$ cat -n /etc/passwd | head -n 5 >> /dev/shm/mycheck.txt [student@station10-101 ~]$ cat -n /etc/passwd | tail -n 5 >> /dev/shm/mycheck.txt
[student@station10-101 ~]$ mkdir /dev/shm/unit03 [student@station10-101 ~]$ mkdir /dev/shm/unit03/files [student@station10-101 ~]$ cd /dev/shm/unit03/files [student@station10-101 files]$ touch ksu{001..100} [student@station10-101 files]$ ll 总计 0 -rw-rw-r--. 1 student student 0 3月 10 23:07 ksu001 -rw-rw-r--. 1 student student 0 3月 10 23:07 ksu002 ......
[student@station10-101 files]$ cd .. [student@station10-101 unit03]$ mkdir dirs [student@station10-101 unit03]$ cd dirs [student@station10-101 dirs]$ pwd /dev/shm/unit03/dirs [student@station10-101 dirs]$ mkdir dir{01..10} [student@station10-101 dirs]$ ll 总计 0 drwxrwxr-x. 2 student student 40 3月 10 23:10 dir01 drwxrwxr-x. 2 student student 40 3月 10 23:10 dir02 ......
[student@station10-101 dirs]$ cd .. [student@station10-101 unit03]$ mkdir season [student@station10-101 unit03]$ cd season/ [student@station10-101 season]$ mkdir jan feb mar [student@station10-101 season]$ ll 总计 0 drwxrwxr-x. 2 student student 40 3月 10 23:12 feb drwxrwxr-x. 2 student student 40 3月 10 23:12 jan drwxrwxr-x. 2 student student 40 3月 10 23:12 mar
[student@station10-101 season]$ touch {jan,feb,mar}/mylog_{1..9}_{aa,bb}_{start,end}.txt [student@station10-101 season]$ ll -R .: 总计 0 drwxrwxr-x. 2 student student 760 3月 10 23:14 feb drwxrwxr-x. 2 student student 760 3月 10 23:14 jan drwxrwxr-x. 2 student student 760 3月 10 23:14 mar ./feb: 总计 0 -rw-rw-r--. 1 student student 0 3月 10 23:14 mylog_1_aa_end.txt -rw-rw-r--. 1 student student 0 3月 10 23:14 mylog_1_aa_start.txt
[student@station10-101 season]$ cd .. [student@station10-101 unit03]$ mkdir spc [student@station10-101 unit03]$ cd spc [student@station10-101 spc]$ mkdir ./-check.txt [student@station10-101 spc]$ ll 总计 0 drwxrwxr-x. 2 student student 40 3月 10 23:24 -check.txt