在crontab的单行tar语句中找到/SED将绝对路径转换为相对路径 [英] Find /SED to convert absolute path to relative path within a single line tar statement for crontab

查看:88
本文介绍了在crontab的单行tar语句中找到/SED将绝对路径转换为相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何精心设计find语句,以去除绝对路径名中的前导斜杠,并提供要添加到tar中的项目作为相对路径名,以避免出现不必要的错误:"tar:从成员名中删除前导"/"?

How can a find statement be crafted to strip the leading slash off absolute path names and deliver items to add to the tar as relative path names in order to avoid the unwanted error: "tar: Removing leading `/' from member names" ?

当前语句:

# tar -zcvf /root/TEST1-strip-slash-find-statement.tar.gz `find /root/test -mmin -1450 -print`

在Ubuntu 16.04 LTS bash shell上产生以下输出

Produces the following output on Ubuntu 16.04 LTS bash shell

tar: Removing leading `/' from member names
/root/test/
/root/test/file2.txt
/root/test/file3.txt
/root/test/file1.txt
/root/test/file4.txt
tar: Removing leading `/' from hard link targets
/root/test/file2.txt
/root/test/file3.txt
/root/test/file1.txt
/root/test/file4.txt

Find向tar发送斜杠:tar:从成员名称中删除开头的"/"

Find is sending leading slashes to tar: tar: Removing leading `/' from member names

如何修改find​​语句以首先从绝对路径名中去除前导斜杠,然后将相对路径名发送到tar?

How can the find statement be revised to first strip the leading slashes from the absolute path names, then send the relative path name to tar ?

从crontab运行此命令时,前导斜杠错误会导致发送大量有关tar的电子邮件:从成员名称中删除前导"/".I有必要继续接收其他错误的电子邮件,因此不能选择使用dev/null或mailto ="发送电子邮件.

When this command is run from crontab , the leading slash error results in numerous emails being sent about tar: Removing leading `/' from member names. I It is necessary to continue receiving emails for other errors, so disabling email sending with dev/null or mailto="" is not an option.

推荐答案

要摆脱"tar:从成员名称中删除开头的'/'":

To get rid of "tar: Removing leading `/' from member names":

添加 -C/并从路径中删除前导/.

Add -C / and remove leading / from your paths.

tar -C / -zcvf /root/TEST1-strip-slash-find-statement.tar.gz `find /root/test -mmin -1450 -print | sed 's|^/||'`

这篇关于在crontab的单行tar语句中找到/SED将绝对路径转换为相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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