Linux 命令记录 - EricYangXD/LearnReact GitHub Wiki

记录一些命令行

打包/解压 & 加密打包/解密解压

  • 注意修改file/folder为实际的文件或文件夹名称

  • 1.打包

tar -zcvf root.tar.gz *
tar -zcvf /path/to/file.tar.gz file
  • 2.解压
tar -zxvf /path/to/file.tar.gz /another-path/to
tar -zxvf root.tar.gz
  • 3.加密打包
tar -czvf - your-file | openssl des3 -salt -k your-password -out /path/to/file.tar.gz
  • 4.解密解压
openssl des3 -d -k your-password -salt -in /path/to/file.tar.gz | tar xzf -
  • 5.排除目录中的某些文件,然后进行压缩
tar --exclude=目录名/* 或者 文件名 -zcvf 备份文件名.tgz 目录名
  • 具体举例:
# 创建一个名为 abc 的目录
mkdir abc

# 进入 abc 这个目录
cd abc

# 创建两个文件,文件名为1.txt 2.txt
touch 1.txt 2.txt

# 切换到 abc 的父目录
cd ..

# 将文件 abc 进行压缩时,排除1.txt,压缩后的文件名为 abc.tar
tar --exclude=abc/1.txt -zcvf abc.tgz abc

# 解压文件
tar -zxvf abc.tgz

# 删除压缩文件
rm abc.tgz

# 删除解压后的文件,并删除文件夹
rm -rf abc
  • 6.pbkdf2加密/解密
# 压缩
openssl aes-256-cbc -salt -pbkdf2 -in name -out name.aes
# 解压
openssl aes-256-cbc -d -salt -pbkdf2 -in name.aes -out name