我想分别对/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/