tar 排除单个文件/目录,而不是模式 [英] tar exclude single files/directories, not patterns

查看:34
本文介绍了tar 排除单个文件/目录,而不是模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tar 对服务器进行每日备份,并希望避免备份/proc 和/sys 系统目录,但不排除任何名为proc"或sys"的目录其他在文件树中.

I'm using tar to make daily backups of a server and want to avoid backup of /proc and /sys system directories, but without excluding any directories named "proc" or "sys" somewhere else in the file tree.

例如,具有以下目录树(bla"是普通文件):

For, example having the following directory tree ("bla" being normal files):

# find
.
./sys
./sys/bla
./foo
./foo/sys
./foo/sys/bla

我想排除 ./sys ./foo/sys.

我似乎找不到可以做到这一点的 --exclude 模式...

I can't seem to find an --exclude pattern that does that...

# tar cvf /dev/null * --exclude=sys
foo/

或...

# tar cvf /dev/null * --exclude=/sys
foo/
foo/sys/
foo/sys/bla
sys/
sys/bla

有什么想法吗?(Linux Debian 6)

Any ideas? (Linux Debian 6)

推荐答案

您可以指定排除模式的绝对路径,这样其他 sysproc 目录将被存档:

You can specify absolute paths to the exclude pattern, this way other sys or proc directories will be archived:

tar --exclude=/sys --exclude=/proc /

这篇关于tar 排除单个文件/目录,而不是模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆