- 一、实验目的
- 二、实验内容
- 1、文件和目录类命令
- (1)启动计算机,利用root用户登录到系统,进入字符提示界面。
- (2)用pwd命令查看当前所在的目录。
- (3)用ls命令列出此目录下的文件和目录。
- (4)用-a选项列出此目录下包括隐藏文件在内的所有文件和目录。
- (5)用man命令查看ls命令的使用手册。
- (6)在当前目录下,创建测试目录test。
- (7)利用ls命令列出文件和目录,确认test目录创建成功。
- (8)进入test目录,利用pwd命令查看当前工作目录。
- (9)利用touch命令,在当前目录创建一个新的空文件newfile。
- (10)利用cp命令复制系统文件/etc/profile到当前目录下。
- (11)复制文件profile到一个新文件profile.bak,作为备份。
- (12)用ll命令以长格式列出当前目录下的所有文件,注意比较每个文件的长度和创建时间的不同。
- (13)用less命令分屏查看文件profile的内容,注意练习less命令的各个子命令.
- (14)用grep命令在profile文件中对关键字then进行查询,并与上面的结果比较。
- (15)删除rofile文件和profile.bak文件
- (16)用tar命令把目录test打包。
- (17)在test下创建一个子目录test1
- (18)把文件test.tar解包。
- (19)复制test目录为testbak目录作为备份。
- (20)查找root用户自己的主目录下的所有名为newfile的文件。
- (21)删除test子目录下的所有文件。
- (22)利用rmdir命令删除目录test。
- 1、文件和目录类命令
- 三、实验作业
一、实验目的
二、实验内容
1、文件和目录类命令
(1)启动计算机,利用root用户登录到系统,进入字符提示界面。
(2)用pwd命令查看当前所在的目录。
[root@centos-linux ~]# pwd/root[root@centos-linux ~]#
(3)用ls命令列出此目录下的文件和目录。
[root@centos-linux ~]# lsanaconda-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面
(4)用-a选项列出此目录下包括隐藏文件在内的所有文件和目录。
[root@centos-linux ~]# ls -a. .bash_logout .config .lesshst 公共 文档.. .bash_profile .cshrc .local 模板 下载anaconda-ks.cfg .bashrc .esd_auth .tcshrc 视频 音乐.bash_history .cache .ICEauthority test 图片 桌面[root@centos-linux ~]#
(5)用man命令查看ls命令的使用手册。
[root@centos-linux test]# man lsLS(1) User Commands LS(1)NAMEls - list directory contentsSYNOPSISls [OPTION]... [FILE]...DESCRIPTIONList information about the FILEs (the current directory by default).Sort entries alphabetically if none of -cftuvSUX nor --sort is speci‐fied.Mandatory arguments to long options are mandatory for short optionstoo.-a, --alldo not ignore entries starting with .-A, --almost-alldo not list implied . and ..--authorwith -l, print the author of each file[root@centos-linux test]#
(6)在当前目录下,创建测试目录test。
(7)利用ls命令列出文件和目录,确认test目录创建成功。
[root@centos-linux ~]# mkdir test[root@centos-linux ~]# lsanaconda-ks.cfg test 公共 模板 视频 图片 文档 下载 音乐 桌面
(8)进入test目录,利用pwd命令查看当前工作目录。
[root@centos-linux ~]# cd test[root@centos-linux test]# pwd/root/test[root@centos-linux test]#
(9)利用touch命令,在当前目录创建一个新的空文件newfile。
[root@centos-linux test]# touch newfile[root@centos-linux test]# lsnewfile
(10)利用cp命令复制系统文件/etc/profile到当前目录下。
[root@centos-linux test]# cp /etc/profile .[root@centos-linux test]# lsnewfile profile
(11)复制文件profile到一个新文件profile.bak,作为备份。
[root@centos-linux test]# cp profile profile.bak[root@centos-linux test]# lsnewfile profile profile.bak
(12)用ll命令以长格式列出当前目录下的所有文件,注意比较每个文件的长度和创建时间的不同。
[root@centos-linux test]# ll总用量 4188-rw-r--r--. 1 root root 0 3月 18 14:22 newfile-rw-r--r--. 1 root root 1750 3月 18 14:58 profile-rw-r--r--. 1 root root 1750 3月 18 14:58 profile.bak[root@centos-linux test]#
(13)用less命令分屏查看文件profile的内容,注意练习less命令的各个子命令.
[root@centos-linux test]# less profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {case ":${PATH}:" in*:"$1":*);;*)if [ "$2" = "after" ] ; thenPATH=$PATH:$1elsePATH=$1:$PATHfiesac}if [ -x /usr/bin/id ]; thenif [ -z "$EUID" ]; then[root@centos-linux test]#
(14)用grep命令在profile文件中对关键字then进行查询,并与上面的结果比较。
[root@centos-linux test]# less profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you# are doing. It's much better to create a custom.sh shell script in# /etc/profile.d/ to make custom changes to your environment, as this# will prevent the need for merging in future updates.pathmunge () {case ":${PATH}:" in*:"$1":*);;*)if [ "$2" = "after" ] ; thenPATH=$PATH:$1elsePATH=$1:$PATHfiesac}if [ -x /usr/bin/id ]; thenif [ -z "$EUID" ]; then# ksh workaroundEUID=`id -u`UID=`id -ru`fiUSER="`id -un`"LOGNAME=$USERMAIL="/var/spool/mail/$USER"fi# Path manipulationif [ "$EUID" = "0" ]; thenpathmunge /usr/sbinpathmunge /usr/local/sbin:/then
(15)删除rofile文件和profile.bak文件
[root@centos-linux test]# rm -f profile[root@centos-linux test]# rm -f profile.bak
(16)用tar命令把目录test打包。
[root@centos-linux ~]# tar cvf test.tar .[root@centos-linux ~]# lsanaconda-ks.cfg test test.tar 公共 模板 视频 图片 文档 下载 音乐 桌面[root@centos-linux ~]#
(17)在test下创建一个子目录test1
[root@centos-linux test]# mkdir test1[root@centos-linux test]# lsnewfile test1[root@centos-linux test]#
(18)把文件test.tar解包。
[root@centos-linux test]# tar xvf test.tar ./test1
(19)复制test目录为testbak目录作为备份。
[root@centos-linux ~]# cp -r /root/test /root/testbak[root@centos-linux ~]# lsanaconda-ks.cfg test test.tar 模板 图片 下载 桌面core.3751 testbak 公共 视频 文档 音乐[root@centos-linux ~]#
(20)查找root用户自己的主目录下的所有名为newfile的文件。
[root@centos-linux ~]# find /root -name newfile/root/test/newfile/root/testbak/newfile[root@centos-linux ~]#
(21)删除test子目录下的所有文件。
[root@centos-linux test]# rm -f newfile[root@centos-linux test]# lstest1[root@centos-linux test]#
(22)利用rmdir命令删除目录test。
[root@centos-linux ~]# rm -rf test[root@centos-linux ~]# lsanaconda-ks.cfg testbak 公共 视频 文档 音乐core.3751 test.tar 模板 图片 下载 桌面[root@centos-linux ~]#
三、实验作业
1、在/root目录下新建目录test1/test2/test3
[root@centos-linux ~]# mkdir -p test1/test2/test3[root@centos-linux ~]# lsanaconda-ks.cfg test1 模板 图片 下载 桌面core.3751 公共 视频 文档 音乐[root@centos-linux ~]#
2、在/home目录下新建目录TEST
[root@centos-linux ~]# cd /home[root@centos-linux home]# mkdir TEST[root@centos-linux home]# lscyy TEST[root@centos-linux home]#
3、在test2目录下新建文件file1.txt
[root@centos-linux ~]# cd /root/test1/test2[root@centos-linux test2]# touch file1.txt
4、复制file1.txt文件到test2目录下重命名为file1.txt.bak
[root@centos-linux test2]# cp file1.txt file1.txt.bak[root@centos-linux test2]# lsfile1.txt file1.txt.bak test3
5、在当前用户家目录下新建文件user_file.txt
[root@centos-linux test2]# cd[root@centos-linux ~]# touch user_file.txt
6、将user_file.txt复制到TEST目录下;
[root@centos-linux ~]# cp user_file.txt /home/TEST[root@centos-linux ~]# cd /home/TEST[root@centos-linux TEST]# lsuser_file.txt
7、将test1目录下内容复制到TEST目录下;
[root@centos-linux TEST]# cp -r /root/test1 /home/TEST[root@centos-linux TEST]# lstest1 user_file.txt
8、将TEST目录重命名为test;
[root@centos-linux ~]# cd /home[root@centos-linux home]# lscyy TEST[root@centos-linux home]# mv TEST test[root@centos-linux home]# lscyy test
9、将test目录下文件user_file.txt和test2下的file1.txt移动到根目录下;
[root@centos-linux home]# mv /home/test/user_file.txt /rootmv:是否覆盖"/root/user_file.txt"? yes[root@centos-linux home]# mv /root/test1/test2/file1.txt /root[root@centos-linux home]# cd[root@centos-linux ~]# lsanaconda-ks.cfg file1.txt user_file.txt 模板 图片 下载 桌面core.3751 test1 公共 视频 文档 音乐
10、将test2目录下file1.txt.bak文件删除;
[root@centos-linux ~]# cd /root/test1/test2[root@centos-linux test2]# lsfile1.txt.bak test3[root@centos-linux test2]# rm -f file1.txt.bak
11、删除test1目录下所有内容并不提醒用户;
[root@centos-linux ~]# rm -rf /root/test1
12、使用vi编辑器编辑1.txt和2.txt
[root@centos-linux ~]# vi 1.txt[root@centos-linux ~]# vi 2.txt
13、将1.txt和2.txt的内容合并到3.txt中,并用cat查看3.txt内容
[root@centos-linux ~]# cat 1.txt 2.txt>3.txt[root@centos-linux ~]# cat 3.txt1111111111111111111111222222222222222222222222222222222222222222222222
