0717RHCSA

使用tar命令对文件进行打包压缩与解压缩:
使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz

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

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

[root@server ~]# tar czf tar_gzip.tar.gz tar_file1 tar_file2 tar_file3
[root@server ~]# tar cjf tar_bzip2.tar.bz2 tar_file1 tar_file2 tar_file3
[root@server ~]# tar cJf tar_xz.tar.xz tar_file1 tar_file2 tar_file3
[root@server ~]# ls -l
-rw-r--r--. 1 root root  145 Jul 18 13:55 tar_bzip2.tar.bz2
-rw-r--r--. 1 root root    0 Jul 18 13:50 tar_file1
-rw-r--r--. 1 root root    0 Jul 18 13:50 tar_file2
-rw-r--r--. 1 root root    0 Jul 18 13:50 tar_file3
-rw-r--r--. 1 root root  147 Jul 18 13:55 tar_gzip.tar.gz
-rw-r--r--. 1 root root  188 Jul 18 13:56 tar_xz.tar.xz
  • 新建文件file1.txt,file2.txt,file3.txt

  • 对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩)

  • 并指定压缩名为tar_file.tar.gz

    [root@server ~]# tar -cvf tar_file.tar.gz flie[!3].txt
    flie1.txt
    flie2.txt
    [root@server ~]# 
    

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

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

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

    [root@server ~]# touch file4.txt
    [root@server ~]# tar -rvf tar_file.tar.gz file4.txt
    file4.txt
    [root@server ~]# tar tf tar_file.tar.gz 
    flie1.txt
    flie2.txt
    file4.txt
    [root@server ~]# mkdir tar_test
    [root@server ~]# tar xzf tar_gzip.tar.gz -C tar_test
    [root@server ~]# 
    

    解压tar_xz.tar.xz

  • [root@server ~]# tar xvf tar_xz.tar.xz 
    tar_file1
    tar_file2
    tar_file3

    在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt

  • 通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
    sftp> put C:\Users\jameth\Desktop\Windows.txt /root/
    Uploading C:/Users/jameth/Desktop/Windows.txt to /root/Windows.txt
    C:/Users/jameth/Desktop/Windows.txt                                                   100%    0     0.0KB/s   00:00
    sftp>
    

    通过sftp的 get和put命令,将linux上的linux.txt推送到windows上

  • sftp> get /root/Linux.txt C:\Users\jameth\Desktop\
    Fetching /root/Linux.txt to C:/Users/jameth/Desktop/Linux.txt
    sftp>
    

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

    [root@server ~]# export local_data=1
    [root@server ~]# echo $local_data 
    1
    

    创建环境变量ROOT_DATA=root, 只有root用户可以访问到

  • [root@server ~]# vi /root/.bashrc
    [root@server ~]# source /root/.bashrc
    [root@server ~]# echo $ROOT_DATA 
    root
    

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

  • [root@server ~]# export USER_DATA=user
    [root@server ~]# echo $USER_DATA 
    user
    

  • 创建环境变量DATA=all, root用户和普通用户都可以访问到
    [root@server ~]# vi /etc/profile
    [root@server ~]# source /etc/profile
    [root@server ~]# echo $DATA
    all
    

    创建3个文件test1.txt, test2.txt, test3.txt

  • 使用find查找test1.txt,test2.txt, test3.txt
  • 使用别名: 将上边命令命名为myfind
  • 取消别名
    [root@server ~]# touch test1.txt
    [root@server ~]# touch test2.txt
    [root@server ~]# touch test3.txt
    [root@server ~]# find test[1-3].txt
    test1.txt
    test2.txt
    test3.txt
    [root@server ~]# alias myfind=find
    [root@server ~]# myfind test[1-3].txt
    test1.txt
    test2.txt
    test3.txt
    [root@server ~]# unalias myfind
    [root@server ~]# myfind test[1-3].txt
    bash: myfind: command not found...
    [root@server ~]# 
    

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

    [root@server ~]# history 10
      122  find test[1-3].txt
      123  touch test1.txt
      124  touch test2.txt
      125  touch test3.txt
      126  find test[1-3].txt
      127  alias myfind=find
      128  myfind test[1-3].txt
      129  unalias myfind
      130  myfind test[1-3].txt
      131  history 10
    

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

    [root@server ~]# printf 123 ; su rhcsa
    123[rhcsa@server root]$ 
    

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

    [root@server ~]# numb=1
    [root@server ~]# echo "$numb"
    1
    [root@server ~]# echo '$numb'
    $numb
    [root@server ~]# n=pwd
    [root@server ~]# echo $n
    pwd
    [root@server ~]# n=`pwd`
    [root@server ~]# echo $n
    /root
    [root@server ~]# n=$(ls)
    [root@server ~]# echo $n
    aafile afile anaconda-ks.cfg args.txt a.txt bbfile bfile cut_data.txt Desktop Documents Downloads f1 f2 f3 file1 file2 file4.txt flie1.txt flie2.txt flie3.txt info_txt initial-setup-ks.cfg Linux.txt Music num.txt Pictures Public sort2.txt sort_args.txt sorted_args.txt sorted_merge.txt sorted_num.txt sort.txt tar_bzip2.tar.bz2 tar_file1 tar_file2 tar_file3 tar_file.tar.gz tar_gzip.tar.gz tar_xz.tar.xz Templates test1.txt test2.txt test3.txt uniq_data.txt Videos Windows.txt zfile zzfile
    [root@server ~]# 
    

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值