rhcsa第五次作业

tar归档命令压缩
tar cvf/cfv/-cvf 文件名.tar 要打包的目录或文件名列表……
创建带压缩的包文件,为节省存储空间,通常需要生成压缩格式的tar包文件,tar命令支持三种不同的压缩方式

tar  czf/-czf 文件名.tar.gz  要打包压缩的目录或文件名……
tar  cjf/-cjf 文件名.tar.bz2  要打包压缩的目录或文件名……
tar  cJf/-cJf 文件名.tar.xz  要打包压缩的目录或文件名……

z是gz型,j是bz2 ,J 是zx
另外打包时排除某个文件
tar cf 文件名.tar --exclude=路径/文件 路径
注:此处的路径前后需要保持保持一致,统一使用绝对路径
或者相对路径
例1:使用gzip方式对文件夹进行压缩,并指定压缩名为tar_gzip.tar.gz。

[root@localhost Desktop]# tar czf tar_gzip.tar.gz f1
[root@localhost Desktop]# ls
f1 tar_gzip.tar.gz


例2:使用bzip2方式对文件夹进行压缩,并指定压缩名为tar_bzip2.tar.bz2。

[root@localhost Desktop]# tar cjf tar_bzip2.tar.bz2 f1
[root@localhost Desktop]# ls
f1 tar_bzip2.tar.bz2 


例3:使用xz方式对文件夹进行压缩,并指定压缩名为tar_bzip2.tar.xz。

[root@localhost Desktop]# tar cJvf tar_xz.tar.xz f1
[root@localhost Desktop]# ls
f1 tar_xz.tar.xz


例4:创建file1.txt,file2.txt ,file3.txt 文件。使用gzip对file1.txt,file2.txt进行压缩,压缩名字为 tar_file.tar.gz:

[root@localhost Desktop]# tar -czf  tar_file.tar.gz file{1..2}.txt
[root@localhost Desktop]# ls  tar_file.tar.gz  file1  file2  file3
新建file4.txt,将file4.txt添加到file12.tar.gz中,查看这个压缩包有哪些文件及目录。不能解压,只能查看。

[root@localhost Desktop]# touch file4.txt    创建file4 
[root@localhost Desktop]# tar -f tar_file.tar.gz file4.txt --append   在压缩包里面添加
[root@localhost Desktop]# tar -tvf tar_file.tar.gz  查看
-rw-r--r-- root/root         0 2022-07-18 16:50 file1.txt
-rw-r--r-- root/root         0 2022-07-18 16:50 file2.txt
-rw-r--r-- root/root         0 2022-07-18 18:06 file4.txt
说明,之前 tar_file.tar.gz是2个文件,现在有3个了

解压 tar_file.tar.gz到目录tar_test。没有就创建

[root@localhost Desktop]# tar -zvxf tar_file.tar.gz tar_test -C         Desktop/tar_test

sftp协议
要求:
在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt
通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
通过sftp的 get和put命令,将linux上的linux.txt推送到windows上
第一步:
将本机与虚拟机连接(服务器),首先要测试2个能否互通。
第二步:
在本地 win+R 调出命令行,用sftp协议连接本机与虚拟机,如下命令:

第三步:
本机用put命令将123.txt文件传输到虚拟机
注意:本机所在虚拟机的位置就是put之后文件的位置。如下:

上传成功。
第四步:
get获取Linux上的文件到本地:如下

注意参数:D:\Desktop 是上传到本地的路径

3.创建普通变量local_data=1并访问

[root@192 ~]# local_data=1
[root@192 ~]# echo $local_data
1
[root@192 ~]# 
创建环境变量ROOT_DATA=root, 只有root用户可以访问到

root用户:
[root@192 ~]# export ROOT_DATA=root
[root@192 ~]# echo $ROOT_DATA
root


普通用户查看:
[rhcsa@192 ~]$ echo $ROOT_DATA 
[rhcsa@192 ~]$ 
创建环境变量USER_DATA=user, 只有普通用户可以访问到

普通用户:
[rhcsa@192 ~]$ export USER_DATA=user
[rhcsa@192 ~]$ echo $USER_DATA
user
[rhcsa@192 ~]$ 
root用户:
[rhcsa@192 ~]$ export USER_DATA=user
[rhcsa@192 ~]$ echo $USER_DATA
user
[rhcsa@192 ~]$ 
创建环境变量DATA=all, root用户和普通用户都可以访问到

root用户
[root@192 ~]# vim /etc/profile
[root@192 ~]# source /etc/profile
[root@192 ~]# echo $DATA
all
[rhcsa@192 ~]$ echo $DATA
[rhcsa@192 ~]$ source /etc/profile
Session lifetime based on X11 requested, but X11 initialization failed.
[rhcsa@192 ~]$ echo $DATA
all

4.创建3个文件test1.txt, test2.txt, test3.txt
  使用find查找test1.txt,test2.txt, test3.txt

[root@192 ~]# touch test{1..3}.txt
[root@192 ~]# ls test*.txt
test1.txt  test2.txt  test3.txt
[root@192 ~]# find test{1..3}.txt
test1.txt
test2.txt
test3.txt
[root@192 ~]# 
使用别名: 将上边命令命名为myfind

[root@192 ~]# alias myfind=' find '
[root@192 ~]# myfind test*.txt
test1.txt
test2.txt
test3.txt
[root@192 ~]# 


取消别名

[root@192 ~]# unalias myfind
[root@192 ~]# myfind test*.txt
bash: myfind: command not found...

5.查看最近使用的10条历史命令

[root@192 ~]# history 10
   55  allias myfind="find. -name 'test*.txt'"
   56  alias myfind="find. -name 'test*.txt'"
   57  myfind
   58  alias myfind=" find. -name 'test*.txt' "
   59  myfind
   60  alias myfind=' find '
   61  myfind test*.txt
   62  unalias myfind
   63  myfind test*.txt
   64  history  10

6.在一行上执行两个命令,打印123和从root切换到普通用户 

[root@192 ~]# echo 123;su - llilang 123                                               
[rhcsa@192 ~]$

7.引号的使用举例: 无引号,单引号,双引号,反引号,$()

[rhcsa@192 ~]$ echo 963
963
[rhcsa@192 ~]$ echo '963'
963
[rhcsa@192 ~]$ echo "963"
963
[rhcsa@192 ~]$ echo `pwd`
/home/llilang
[rhcsa@192 ~]$ echo $(pwd)
/home/llilang
[rhcsa@192 ~]$ 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值