1.使用tar命令对文件进行打包压缩与解压缩:
- 使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz
[root@localhost data]# tar -cvzf tar_gzip.tar.gz args.txt
[root@localhost data]# ls
args.txt tar_gzip.tar.gz
- 使用bzip2方式对文件夹进行压缩,并指定压缩名为 tar_bzip2.tar.bz2
[root@localhost data]# tar -cjvf tar_bzip2.tar.bz2 args.txt
[root@localhost data]# ls
args.txt tar_bzip2.tar.bz2 tar_gzip.tar.gz
- 使用xz方式对文件进行压缩,并指定压缩名为 tar_xz.tar.xz
[root@localhost data]# tar -cJvf tar_xz.tar.xz args.txt
[root@localhost data]# ls
args.txt tar_gzip.tar.gz tar_xz.tar.xz tar_bzip2.tar.bz2
- 新建文件file1.txt,file2.txt,file3.txt
对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩)
并指定压缩名为tar_file.tar.gz
[root@localhost demo]# tar -czvf tar_file.tar.gz --exclude=file3.txt f*
file1.txt
file2.txt
- 新建文件file4.txt,将file4.txt添加到tar_file.tar.gz中
[root@localhost demo]# tar -rvf tar_file.tar file4.txt
file4.txt
[root@localhost demo]# tar -tvf tar_file.tar
-rw-r--r-- root/root 0 2022-07-18 11:45 file1.txt
-rw-r--r-- root/root 0 2022-07-18 11:45 file2.txt
-rw-r--r-- root/root 0 2022-07-18 13:55 file4.txt
- 查看压缩包tar_file.tar.gz有哪些文件及目录(不解压,只查看)
[root@localhost demo]# tar -tvf tar_file.tar.gz
-rw-r--r-- root/root 0 2022-07-18 11:45 file1.txt
-rw-r--r-- root/root 0 2022-07-18 11:45 file2.txt
-rw-r--r-- root/root 0 2022-07-18 13:55 file4.txt
- 解压tar_gzip.tar.gz到指定目录tar_test(没有这个目录就创建)
[root@localhost demo]# mkdir tar_test
[root@localhost demo]# tar -zxvf tar_file.tar.gz -C tar_test
file1.txt
file2.txt
file4.txt
- 解压tar_xz.tar.xz
[root@localhost data]# tar -Jxvf tar_xz.tar.xz
args.txt
2.在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt
- 通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
sftp> put windows.txt
Uploading windows.txt to /root/windows.txt
windows.txt 100% 3 0.0KB/s 00:00
- 通过sftp的 get和put命令,将linux上的linux.txt推送到windows上
sftp> get linux.txt
Fetching /root/linux.txt to linux.txt
3.变量
- 创建普通变量local_data=1并访问
[root@localhost ~]# local_data=1
[root@localhost ~]# echo $local_data
1
- 创建环境变量ROOT_DATA=root, 只有root用户可以访问到
(永久有效)
[root@localhost ~]# vi .bash_profile
export ROOT_DATA=root
[root@localhost ~]# echo $ROOT_DATA
root
方法二:(临时)
[root@localhost ~]# export ROOT_DATA=root
[root@localhost ~]# echo $ROOT_DATA
root
- 创建环境变量USER_DATA=user, 只有普通用户可以访问到
(永久有效)
[root@localhost ~]$ vi .bash_profile
export USER_DATA=user
[root@localhost ~]$ echo $USER_DATA
user
方法二:(临时)
[root@localhost ~]$ export USER_DATA=user
[root@localhost ~]$ echo $USER_DATA
user
- 创建环境变量DATA=all, root用户和普通用户都可以访问到
[root@localhost ~]# vi /etc/profile
export DATA=all
[root@localhost ~]# echo $DATA
all
4.find命令、别名
创建3个文件test1.txt, test2.txt, test3.txt
- 使用find查找test1.txt,test2.txt, test3.txt
[root@localhost find.txt]# find test*
test1.txt
test2.txt
test3.txt
- 使用别名: 将上边命令命名为myfind
[root@localhost find.txt]# alias find='find test*'
[root@localhost find.txt]# find
test1.txt
test2.txt
test3.txt
- 取消别名
[root@localhost find.txt]# unalias find
5.history命令
- 查看最近使用的10条历史命令
[root@localhost find.txt]# history 10
1033 cd .
1034 cd /home/find.txt
1035 find test*
1036 alias find=find test*
1037 find
1038 alias find='find test*'
1039 find
1040 unalias find
1041 find
1042 history 10
6.在一行上执行两个命令,打印123和从root切换到普通用户
[root@localhost find.txt]# printf 123 && su rhcsa
123[rhcsa@localhost find.txt]$
7.引号的使用举例: 无引号,单引号,双引号,反引号,$()
无引号:
[root@localhost find.txt]# echo $PATH
/home/rhcsa/.local/bin:/home/rhcsa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
双引号:
[root@localhost find.txt]# echo "$PATH"
/home/rhcsa/.local/bin:/home/rhcsa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
单引号:
[root@localhost find.txt]# echo '$PATH'
$PATH
反引号:
[root@localhost find.txt]# echo `ls` shell
1h test2.txt test3.txt shell
$():
[root@localhost find.txt]# echo $(pwd)
/home/find.txt
这篇博客详细介绍了在Linux环境下如何使用tar命令进行文件和文件夹的压缩与解压缩,包括gzip、bzip2和xz方式。同时,展示了如何创建、修改和查看压缩包内的文件,以及如何通过sftp在Linux和Windows之间传输文件。此外,还讲解了如何在Linux中设置和访问本地及环境变量,以及find命令的使用、别名的创建和取消。最后,演示了history命令查看历史命令、一行执行多个命令以及不同引号在命令行中的作用。
1190

被折叠的 条评论
为什么被折叠?



