一、tar命令
使用tar命令对文件进行打包压缩与解压缩:
1、使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz
[root@localhost ~]# touch tar_gzip.txt
[root@localhost ~]# tar -zcvf tar_gzip.tar.gz tar_gzip.txt
tar_gzip.txt
[root@localhost ~]# ll tar*
-rw-r--r--. 1 root root 118 Jul 18 18:15 tar_gzip.tar.gz
-rw-r--r--. 1 root root 0 Jul 18 18:14 tar_gzip.txt
2、使用bzip2方式对文件夹进行压缩,并指定压缩名为 tar_bzip2.tar.bz2
[root@localhost ~]# touch tar_xz.txt
[root@localhost ~]# tar -jcvf tar-bzip2.tar.bz2 tar_xz.txt
tar_xz.txt
[root@localhost ~]# ll tar*
-rw-r--r--. 1 root root 114 Jul 18 18:17 tar-bzip2.tar.bz2
-rw-r--r--. 1 root root 0 Jul 18 18:17 tar_xz.txt
3、使用xz方式对文件进行压缩,并指定压缩名为 tar_xz.tar.xz
[root@localhost ~]# tar -jcvf tar_xz.tar.xz tar_xz.txt
tar_xz.txt
[root@localhost ~]# ll tar*
-rw-r--r--. 1 root root 114 Jul 18 18:18 tar_xz.tar.xz
-rw-r--r--. 1 root root 0 Jul 18 18:17 tar_xz.txt
4、新建文件file1.txt,file2.txt,file3.txt
对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩)
并指定压缩名为tar_file.tar.gz
[root@localhost ~]# touch file1.txt file2.txt file3.txt
[root@localhost ~]# tar --exclude file3.txt -zcvf tar_file.tar.gz file*
file1.txt
file2.txt
[root@localhost ~]# ll tar_file*
-rw-r--r--. 1 root root 202 Jul 18 18:21 tar_file.tar.gz
5、 解压tar_gzip.tar.gz到指定目录tar_test(没有这个目录就创建)
解压tar_xz.tar.xz
[root@localhost ~]# mkdir tar_test
[root@localhost ~]# tar -xvf tar_gzip.tar.gz -C ./tar_test/
tar_gzip.txt
[root@localhost ~]# ls ./tar_test/
tar_gzip.txt
[root@localhost ~]# tar -xvf tar_xz.tar.xz -C ./tar_test/
tar_xz.txt
[root@localhost ~]# ls ./tar_test/
tar_gzip.txt tar_xz.txt
二、STFP命令
在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt
1、通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
2、通过sftp的 get和put命令,将linux上的linux.txt推送到windows上
三、用户创建
1、创建普通变量local_data=1并访问
[root@localhost ~]# local_data=1
[root@localhost ~]# echo $local_data
1
[root@localhost ~]#
2、创建环境变量ROOT_DATA=root, 只有root用户可以访问到
[root@localhost ~]# vim .bash_profile
[root@localhost ~]# echo $ROOT_DATA
[root@localhost ~]# source .bash_profile
[root@localhost ~]# echo $ROOT_DATA
root
3、创建环境变量USER_DATA=user, 只有普通用户可以访问到
[root@localhost ~]# vim .bash_profile
[root@localhost ~]# source .bash_profile
[root@localhost ~]# echo $USER_DATA
user
4、创建环境变量DATA=all, root用户和普通用户都可以访问到
[root@localhost ~]# vim /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $DATA
all
[root@localhost ~]# su - rhcsa
[rhcsa@localhost ~]$ echo $DATA
all
四、创建3个文件test1.txt, test2.txt, test3.txt
1、使用find查找test1.txt,test2.txt, test3.txt
[root@localhost ~]# touch test1.txt test2.txt test3.txt
[root@localhost ~]# find . -name 'test*.txt'
./test2.txt
./test1.txt
./test3.txt
2、使用别名: 将上边命令命名为myfind
[root@localhost ~]# alias find_test="find . -name 'test*.txt'"
[root@localhost ~]# find_test
./test2.txt
./test1.txt
./test3.txt
3、取消别名
[root@localhost ~]# unalias find_test
[root@localhost ~]# find_test
bash: find_test: command not found...
五、查看最近使用的10条历史命令
[root@localhost ~]# history 10
179 ls
180 alias find_test="find . -name 'test*.txt'"
181 find_test
182 touch test1.txt test2.txt test3.txt
183 alias find_test="find . -name 'test*.txt'"
184 find_test
185 unalias find_test
186 find_tets
187 find_test
188 history 10
六、在一行上执行两个命令,打印123和从root切换到普通用户
[root@localhost ~]# echo '123';su rhcsa
123
[rhcsa@localhost root]$
七、引号的使用举例: 无引号,单引号,双引号,反引号,$()
单引号:进行单纯的输出
[root@localhost ~]# echo qwe123
qwe123
双引号:双引号里面的特殊符号 会被解析运行
输出的语句是被解析过变量以后再输出的
[root@localhost ~]# echo "$LANG"
en_US.UTF-8
无引号:和双引号相似
反引号:优先执行,先执行里面的命令,会把结果留下
[root@localhost ~]# ls `touch t1.f`*.f
t1.f
[root@localhost ~]# ls $(touch t2.f)*.f
t1.f t2.f