linux - 用 tar 备份 home 目录

标签 linux ubuntu backup

我想分别对/home中的每个目录进行备份,并将每个目录的tar(备份)文件放入指定的目录中。 linux ubuntu下。

最佳答案

你可以在 bash 中做这样的事情:

for d in */; do short=${d%/}; tar -cvf ${short}.tar $short ;done

或者,更详细地说:

cd                               # go home
for d in */                      # for all directories
do
   short=${d%/}                  # strip off trailing slash
   tar -cvf ${short}.tar $short  # tar up directory into file with same name but ".tar" extension
done

因此,如果您有 doirectories $HOME/Documents 和 $HOME/Music,您将在主目录中获得 2 个名为 Documents.tar 和 Music.tar 的 tar 文件

关于linux - 用 tar 备份 home 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21938766/

相关文章:

java - 网址为 : "/servlet" goes to "ip/servlet" instead of "ip/app/servlet"

scala - 为什么 Intellij 将文件的所有权更改为 root?

php - 备份MySql数据库?

linux - rsync-创建每日备份并在 30 天后删除?

python - 如何使用 python 进行 tar 备份

协同内核开发

linux - 在 docker-compose 命令中使用内联注释

linux - 使用管道命令创建 AWK For 循环

c - 内部内核结构无法分配错误?

ubuntu - ubuntu 11.10 上的 opencv 安装