rhcsa第五次作业

  1. tar命令
  2. sftp的put和get命令
  3. 变量
  4. find查找文件与别名设置
  5. history 查阅命令历史
  6. 特殊符号  分号 " ; "
  7. 引号的使用举例: 无引号,单引号,双引号,反引号,$()

1.tar命令

使用tar命令对文件进行打包压缩与解压缩

压缩
[root@192 ~]# touch gzip.txt
[root@192 ~]# echo "123456789" >>gzip.txt 
[root@192 ~]# cat gzip.txt 
123456789
[root@192 ~]# tar -cvf test.tar gzip.txt 
gzip.txt
[root@192 ~]# ll
total 28
-rw-r--r--. 1 root root    10 Jul 17 23:08 gzip.txt
-rw-r--r--. 1 root root 10240 Jul 17 23:13 test.tar
drwxr-xr-x. 2 root root     6 Jul 13 06:38 Videos
[root@192 ~]# 

解压缩
[root@192 ~]# 
[root@192 ~]# tar -xvf test.tar
gzip.txt

使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz

[root@192 ~]# tar -czf tar_gzip.tar.gz gzip.txt
[root@192 ~]# ll
total 32
-rw-r--r--. 1 root root    10 Jul 17 23:08 gzip.txt
-rw-r--r--. 1 root root   131 Jul 17 23:19 tar_gzip.tar.gz
-rw-r--r--. 1 root root     5 Jul 15 08:49 test
lrwxrwxrwx. 1 root root     5 Jul 15 09:01 test2 -> test1
-rw-r--r--. 1 root root 10240 Jul 17 23:13 test.tar
[root@192 ~]# 

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

[root@192 ~]# tar -cjf tar_bzip2.tar.bz2 gzip.txt
[root@192 ~]# ll
total 36
-rw-r--r--. 1 root root    10 Jul 17 23:08 gzip.txt
-rw-r--r--. 1 root root   127 Jul 17 23:21 tar_bzip2.tar.bz2
-rw-r--r--. 1 root root   131 Jul 17 23:19 tar_gzip.tar.gz
-rw-r--r--. 1 root root     5 Jul 15 08:49 test
lrwxrwxrwx. 1 root root     5 Jul 15 09:01 test2 -> test1
-rw-r--r--. 1 root root 10240 Jul 17 23:13 test.tar
[root@192 ~]# 

使用xz方式对文件进行压缩,并指定压缩名为 tar_xz.tar.xz

[root@192 ~]# tar -cJf tar_xz.tar.xz gzip.txt
[root@192 ~]# ll
total 40
-rw-r--r--. 1 root root    10 Jul 17 23:08 gzip.txt
-rw-r--r--. 1 root root   127 Jul 17 23:21 tar_bzip2.tar.bz2
-rw-r--r--. 1 root root   131 Jul 17 23:19 tar_gzip.tar.gz
-rw-r--r--. 1 root root   184 Jul 17 23:23 tar_xz.tar.xz
-rw-r--r--. 1 root root     5 Jul 15 08:49 test
lrwxrwxrwx. 1 root root     5 Jul 15 09:01 test2 -> test1
-rw-r--r--. 1 root root 10240 Jul 17 23:13 test.tar
[root@192 ~]# 

新建文件file1.txt,file2.txt,file3.txt对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩)并指定压缩名为tar_file.tar.gz。

[root@192 ~]# tar -czf tar_file.tar.gz --exclude=file3.txt file1.txt file2.txt
[root@192 ~]# ll
total 44
-rw-r--r--. 1 root root     0 Jul 17 23:30 file1.txt
-rw-r--r--. 1 root root     0 Jul 17 23:30 file2.txt
-rw-r--r--. 1 root root     0 Jul 17 23:30 file3.txt
-rw-r--r--. 1 root root    10 Jul 17 23:08 gzip.txt
-rw-r--r--. 1 root root   127 Jul 17 23:21 tar_bzip2.tar.bz2
-rw-r--r--. 1 root root   127 Jul 17 23:33 tar_file.tar.gz
-rw-r--r--. 1 root root   131 Jul 17 23:19 tar_gzip.tar.gz
-rw-r--r--. 1 root root   184 Jul 17 23:23 tar_xz.tar.xz
-rw-r--r--. 1 root root     5 Jul 15 08:49 test
lrwxrwxrwx. 1 root root     5 Jul 15 09:01 test2 -> test1
-rw-r--r--. 1 root root 10240 Jul 17 23:13 test.tar
[root@192 ~]# tar -tvf tar_file.tar.gz
-rw-r--r-- root/root         0 2022-07-17 23:30 file1.txt
-rw-r--r-- root/root         0 2022-07-17 23:30 file2.txt
[root@192 ~]# 

新建文件file4.txt,将file4.txt添加到tar_file.tar.gz中

[root@192 ~]# tar -rvf tar_file.tar file4.txt
file4.txt
[root@192 ~]# tar -xvf tar_file.tar
file4.txt
file4.txt
file4.txt
[root@192 ~

 注意:-rvf 只能往打包文件中添加文件,不能往压缩文件中添加文件

查看压缩包tar_file.tar.gz有哪些文件及目录(不解压,只查看)

[root@192 ~]# tar -tvf tar_file.tar.gz
-rw-r--r-- root/root         0 2022-07-17 23:30 file1.txt
-rw-r--r-- root/root         0 2022-07-17 23:30 file2.txt
[root@192 ~]#

解压tar_gzip.tar.gz到指定目录tar_test(没有这个目录就创建)

[root@192 ~]# mkdir tar_test
[root@192 ~]# tar -xzf tar_gzip.tar.gz -C tar_test
[root@192 ~]# ls tar_test
gzip.txt
[root@192 ~]# 

解压tar_xz.tar.xz

[root@192 ~]# tar -xvf tar_xz.tar.xz
gzip.txt
[root@192 ~]# 

2.在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt
 通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
 通过sftp的 get和put命令,将linux上的linux.txt推送到windows上

windows:
C:\Users\**>sftp root@192.168.177.128
The authenticity of host '192.168.177.128 (192.168.177.128)' can't be established.
ECDSA key fingerprint is SHA256:3kNePb1Z6NTr2a5zXsOVPVo7nhn9/kHvdyISwk0rlrU.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Warning: Permanently added '192.168.177.128' (ECDSA) to the list of known hosts.
root@192.168.177.128's password:
Connected to 192.168.177.128.
sftp> put c:\windo
stat c:/windo: No such file or directory
sftp> put c:\windows.txt /root/
stat c:/windows.txt: No such file or directory
sftp> put C:\Users\**\Desktop\windows.txt /root/
Uploading C:/Users/**/Desktop/windows.txt to /root/windows.txt
C:/Users/**/Desktop/windows.txt                                                   100%   10     9.8KB/s   00:00
sftp>

linux查看:
[root@192 ~]# ls windows.txt
windows.txt
[root@192 ~]# cat windows.txt
12345678
[root@192 ~]# 
windows:
sftp> get  /root/linux.txt C:\Users\李浪\Desktop\
Fetching /root/linux.txt to C:/Users/李浪/Desktop/linux.txt
/root/linux.txt                                                                       100%    9     8.8KB/s   00:00
sftp>

 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

普通用户查看:
[llilang@192 ~]$ echo $ROOT_DATA

[llilang@192 ~]$ 

创建环境变量USER_DATA=user, 只有普通用户可以访问到

普通用户:
[llilang@192 ~]$ export USER_DATA=user
[llilang@192 ~]$ echo $USER_DATA
user
[llilang@192 ~]$ 


root用户:
[llilang@192 ~]$ export USER_DATA=user
[llilang@192 ~]$ echo $USER_DATA
user
[llilang@192 ~]$ 

创建环境变量DATA=all, root用户和普通用户都可以访问到

root用户
[root@192 ~]# vim /etc/profile
[root@192 ~]# source /etc/profile
[root@192 ~]# echo $DATA
all
[root@192 ~]# 


[llilang@192 ~]$ echo $DATA

[llilang@192 ~]$ source /etc/profile
Session lifetime based on X11 requested, but X11 initialization failed.
[llilang@192 ~]$ echo $DATA
all
[llilang@192 ~]$ 

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...
[root@192 ~]# 

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
[root@192 ~]# 

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

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

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

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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值