Bash,tar“无法统计没有这样的文件或目录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35072074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash, tar "cannot stat no such file or directory"
提问by Cláudio Ribeiro
I'm trying to build a little backup script but I keep getting the following error:
我正在尝试构建一个小备份脚本,但我不断收到以下错误:
tar: Removing leading `/' from member names
tar: /projects: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
The folder /projects exists, but still no tar ball is created. Here is my code:
文件夹 /projects 存在,但仍然没有创建 tar ball。这是我的代码:
#!/bin/bash
backup_files="/projects"
#destination of backup
dest="/"
#Create archive filename
day=$(date +%Y-%m-%d)
hostname=$(hostname -s)
archive_file="$hostname-$day.tar.gz"
#Backup the files using tar
tar -czf $archive_file $backup_files
#Print end status message
echo
echo "Backup finished"
ls -ld /projects shows the following:
ls -ld /projects 显示以下内容:
ls: cannot access /projects: No such file or directory
Any idea on what is wrong?
知道什么是错的吗?
回答by sig_seg_v
Filepaths that start with a leading /
on Linux and other related systems are located at the root directory. This means that "/projects"
usually refers to a different directory than "projects"
.
/
在 Linux 和其他相关系统上以前导开头的文件路径位于根目录中。这意味着"/projects"
通常指的是与"projects"
.
It looks like you probably are trying to access a subdirectory /path/to/projects
from directory /path/to
using the path /projects
. This is incorrect -- if your working directory is /path/to
, you need to access folder projects
by changing backup_files="/projects"
to backup_files="./projects"
-- "."
refers to the current working directory -- or simply backup_files="projects"
.
看起来您可能正在尝试使用 path访问/path/to/projects
目录中的子目录。这是不正确的 - 如果您的工作目录是,您需要通过更改为-指当前工作目录 - 或简单地访问文件夹。/path/to
/projects
/path/to
projects
backup_files="/projects"
backup_files="./projects"
"."
backup_files="projects"
So, while relative filepaths "./projects"
and "projects"
are usually equivalent, they are generally and functionally different from the fully qualified path "/projects"
.
因此,虽然相对文件路径"./projects"
和"projects"
通常是等效的,但它们通常和功能上与完全限定的路径不同"/projects"
。