I’m trying to create tar.gz file using the following command:
sudo tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
It then start to create files (many files in folder), but then I get the following error:
tar: dvr_rdk_v1.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
I don’t see any description of this error, what does it mean?
Kusalananda♦
322k36 gold badges637 silver badges939 bronze badges
asked Aug 10, 2014 at 7:34
Remove -
from vcfz
options. tar
does not need hyphen for options.
With a hyphen, the argument for the -f
option is z
. So the command is in effect trying to archive dvr_rdk_v1.tar.gz
and dvr_rdk
into an archive called z
. Without the hyphen, the semantics of the options changes, so that the next argument on the command line, i.e. your archive’s filename, becomes the argument to the f
flag.
Also check your write permission to the directory from which you are executing the command.
Kusalananda♦
322k36 gold badges637 silver badges939 bronze badges
answered Aug 10, 2014 at 7:42
VelnixVelnix
1,1421 gold badge8 silver badges3 bronze badges
6
The -f
option should directly precede the filename. So, use tar -vczf filename.tar.gz
instead of -vcfz
Bernhard
12k4 gold badges59 silver badges69 bronze badges
answered Aug 10, 2014 at 7:56
twan163twan163
5,6004 gold badges14 silver badges17 bronze badges
2
The tar command historically has been one of the few commands that doesn’t follow the Unix utility syntax guidelines.
The standards page for tar says:
f
Use the first file operand (or the second, if b has already been specified) as the name of the archive instead of the system-dependent default
While the syntax guidelines include this:
Guideline 5:
One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one ‘-‘ delimiter.
So while the command you typed, tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
, would be fine on older versions of tar, certain versions of tar that are written to strictly follow the utility syntax guidelines will parse this to mean «use z
as the file argument to -f
«. So you should use the following to be portable:
tar -cvzf dvr_rdk_v1.tar.gz dvr_rdk/
answered Aug 10, 2014 at 8:33
Mark PlotnickMark Plotnick
25k2 gold badges60 silver badges82 bronze badges
Notice that the -f
needs to go immediately before the archive name
but after the --exclude
options in this Makefile multi-line example…
-f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'
#######################
#Backup $HOME/.bitcoin — Makefile usage example
########################
TIME=$(shell date +%s)
export TIME
init:
@echo ''
bash -c 'mkdir -p $(HOME)/.bitcoin'
bash -c 'conf/get_size.sh'
bash -c 'tar czv --exclude=*.log --exclude=banlist.dat \
--exclude=fee_exstimates.dat --exclude=mempool.dat \
--exclude=peers.dat --exclude=.cookie \
--exclude=.lock --exclude=.walletlock \
-f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'
#install current bitcoin.conf
bash -c 'install -v conf/bitcoin.conf $(HOME)/.bitcoin'
@echo ''
Hauke Laging
88.3k18 gold badges125 silver badges174 bronze badges
answered Jul 18, 2020 at 21:16
For future readers, this post was the answer for me. Keep wildcards outside the quotes: tar -zcf archive.tar.gz "file-0"*
answered Nov 2, 2022 at 23:58
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
Using mv
to move files and directories has become an everyday task for every Linux user, regardless of the distro they use. Sometimes, users can come across several common error messages written in weird languages, which causes confusion for beginners. In this article, we want to tackle one of the most popular error when using mv
or cp
in Linux : the “cannot stat” error.
Also see: How to fix “errno 5 input/output error”
What does “cannot stat” means
Stat is a program that obtains information about a file or directory in Linux. Because in Linux, each program should do one thing only and rely on one another to do other things, programs that perform file system operation should use stat as a standard way to retrieve details like metadata, size, modified date, permissions, etc.
Like any other program, before performing any operation, mv
or cp
must know some information about the source file/directory and the destination one. The default way to do that is by using stat.
Calling stat on a directory only requires execute permission of the directory containing the file. No read permission of the files is needed.
With that in mind, _every time you see “cannot stat” when using mv
, you can safely assume that stat failed to obtain information about the file. In this case, the problem should be in the file/directory itself or the storage device.
Fixing cannot stat ‘filename’: No such file or directory
The error usually means the destination file or directory cannot be found by the system, so it cannot retrieve information.
If you come across “cannot stat” with “No such file or directory” message, checks the destination path first and then the source path for their correctness.
To get the correct full path of any directory in Ubuntu, you can cd
to it, then run pwd
to obtain the path. Remember to quote this path in any command to avoid errors caused by whitespaces and special characters.
Fixing cannot stat: permission denied
This error means that stat cannot read information about the file because it was denied by disallowing “execute” permission.
You should check the permission of the directory containing the file and the file itself. A quick and dirty solution is using chmod to recursively change the directory permission and all of its contents to 755.
You may need to elevate to root privileges using sudo if you’re not the owner of the folder. However, any changes to protected directories could cause system instability, and we advise carefully examine the directory before recursively chmod it.
Fixing cannot stat ‘foldername’: Input/output error
Among all “cannot stat” errors, the one with “Input/output error” messages is the hardest to debug and fix. In most of the cases, getting this error means there is some kind of file system corruption.
Input/output error in NTFS partitions
Usually, when beginners encounter “Input/output error”, they are accessing files from NTFS-formatted partitions.
NTFS is Microsoft’s file system standard and has been famous for its complex permission system. Linux is able to manage these partitions thanks to a system program named ntfs-3g
, but sometimes it cannot read the disk because of a minor corruption in data.
In this case, you should consider using running a program bundled in ntfs-3g
called ntfs-fix
. But before performing any fixes to the file system, please be aware that it could result in serious data loss.
If you need an open-source backup solution that could work with cloud storage services, be sure to check out rclone. You can get an easy head start without learning too much about the tool with our guide on rclone common commands.
If you see a “device is corrupted” message, back up your files immediately while you still can, then format the whole drive and check for errors before storing any important data on it.
Input/output error in ext partitions
First, ensure the filesystem is unmounted. If the file system is your root partition then you need to boot into rescue mode or use a live CD/USB flash drive so you can check the filesystem while it is unmounted.
To run a filesystem check, use the command e2fsck
. For example, if you are getting the error on a filesystem that is mounted on the partition /dev/hda4
run the following command:
e2fsck /dev/hda4
If the above command returns with errors about a “bad superblock” then run the following command:
dumpe2fs /dev/hda4
Locate the block number of Backup superblock in the output:
Group 1: (Blocks 8193-16384)
**Backup superblock** at **8193**, Group descriptors at 8194-8194
Block bitmap at 8195 (+2), Inode bitmap at 8196 (+3)
Inode table at 8197-8447 (+4)
7937 free blocks, 2008 free inodes, 0 directories
Run e2fsck again, this time with the backup superblock number:
e2fsck -b **8193** /dev/hda4
Code language: JavaScript (javascript)
If this does not solve your problem, then reboot the system. Upon booting, a filesystem check will probably be forced. If you boot to a shell, run e2fsck on the partition that is reporting the errors.
I’m trying to create tar.gz file using the following command:
sudo tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
It then start to create files (many files in folder), but then I get the following error:
tar: dvr_rdk_v1.tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
I don’t see any description of this error, what does it mean?
Kusalananda♦
322k36 gold badges637 silver badges939 bronze badges
asked Aug 10, 2014 at 7:34
Remove -
from vcfz
options. tar
does not need hyphen for options.
With a hyphen, the argument for the -f
option is z
. So the command is in effect trying to archive dvr_rdk_v1.tar.gz
and dvr_rdk
into an archive called z
. Without the hyphen, the semantics of the options changes, so that the next argument on the command line, i.e. your archive’s filename, becomes the argument to the f
flag.
Also check your write permission to the directory from which you are executing the command.
Kusalananda♦
322k36 gold badges637 silver badges939 bronze badges
answered Aug 10, 2014 at 7:42
VelnixVelnix
1,1421 gold badge8 silver badges3 bronze badges
6
The -f
option should directly precede the filename. So, use tar -vczf filename.tar.gz
instead of -vcfz
Bernhard
12k4 gold badges59 silver badges69 bronze badges
answered Aug 10, 2014 at 7:56
twan163twan163
5,6004 gold badges14 silver badges17 bronze badges
2
The tar command historically has been one of the few commands that doesn’t follow the Unix utility syntax guidelines.
The standards page for tar says:
f
Use the first file operand (or the second, if b has already been specified) as the name of the archive instead of the system-dependent default
While the syntax guidelines include this:
Guideline 5:
One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one ‘-‘ delimiter.
So while the command you typed, tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
, would be fine on older versions of tar, certain versions of tar that are written to strictly follow the utility syntax guidelines will parse this to mean «use z
as the file argument to -f
«. So you should use the following to be portable:
tar -cvzf dvr_rdk_v1.tar.gz dvr_rdk/
answered Aug 10, 2014 at 8:33
Mark PlotnickMark Plotnick
25k2 gold badges60 silver badges82 bronze badges
Notice that the -f
needs to go immediately before the archive name
but after the --exclude
options in this Makefile multi-line example…
-f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'
#######################
#Backup $HOME/.bitcoin — Makefile usage example
########################
TIME=$(shell date +%s)
export TIME
init:
@echo ''
bash -c 'mkdir -p $(HOME)/.bitcoin'
bash -c 'conf/get_size.sh'
bash -c 'tar czv --exclude=*.log --exclude=banlist.dat \
--exclude=fee_exstimates.dat --exclude=mempool.dat \
--exclude=peers.dat --exclude=.cookie \
--exclude=.lock --exclude=.walletlock \
-f $(HOME)/.bitcoin-$(TIME).tar.gz $(HOME)/.bitcoin'
#install current bitcoin.conf
bash -c 'install -v conf/bitcoin.conf $(HOME)/.bitcoin'
@echo ''
Hauke Laging
88.3k18 gold badges125 silver badges174 bronze badges
answered Jul 18, 2020 at 21:16
For future readers, this post was the answer for me. Keep wildcards outside the quotes: tar -zcf archive.tar.gz "file-0"*
answered Nov 2, 2022 at 23:58
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
I have this directory called «mock», which contains 3 directories. I am trying to copy all the items from «mock» directory into the «projweek» directory using the following command:
cp /mock/* ~/projweek
But I get this error:
cp: cannot stat ‘mock/*’: No such file or directory
Any ideas as to why that is?
isapir
21.4k13 gold badges115 silver badges116 bronze badges
asked Dec 13, 2015 at 17:39
2
If your source directory is set in quotes, then make sure that the *
is outside the quotes, i.e.
cp "source/"* dest
or
cp "source"/* dest
answered Jul 9, 2018 at 6:45
isapirisapir
21.4k13 gold badges115 silver badges116 bronze badges
5
It’s an odd thing about the unix system that glob expansion (aka use of the «*
«) is done by the shell, and not by the program you are calling, and furthermore, if the glob doesn’t match anything, instead of expanding to nothing, it expands to itself and passes that to the program. So the cp command sees literally «/mock/*
» which doesn’t exist, because you have no file called «*
«. Somewhat perversely if you had a file called «*
» it would dutifully copy it without complaining.
answered Aug 5, 2020 at 12:46
xpusostomosxpusostomos
1,31311 silver badges16 bronze badges
2
cannot stat
= file/dir does not exist. Check the path first.
And, you say you want to copy /mock
but the error message says mock
. Show the real code first.
When I test in ubuntu, cp (GNU coreutils) 8.28
, I have no problem with copying all files under a dir to another dir, when both paths are correct.
root@DESKTOP-9NHNV2I:~# cp /root/temp/* /root
root@DESKTOP-9NHNV2I:~# ls
temp test.txt test2.txt test3333.txt
answered Aug 5, 2019 at 12:18
WesternGunWesternGun
11.3k6 gold badges88 silver badges157 bronze badges
cp: cannot stat ‘mock/*’: No such file or director
- Check that the files exist on the path.
- Also to copy all the files in a folder to another location, use
.
operator like:cp /source/. /dest/
answered Jul 12, 2021 at 19:30
0
cp is used in unix/linux for copy
cp /mock/* ~/projweek
this means copy from /mock folder all files to folder projweek that resides in root
This means cp: cannot stat ‘mock/*’: No such file or directory
unable to copy all files from mock folder because file or directory not exists on relevant path
answered Dec 13, 2015 at 17:46
2
When I configured shell script on jenkins(See the following lines), I got this error «cp cannot stat … No such file or directory».
ssh user@remoteNode
cd /somedir
cp fromdir/xxfile todir/xxfile
The following command solves my problem.
ssh user@remoteNode "cd /somedir; cp fromdir/xxfile todir/xxfile"
Why?
Double quotation marks are required. If not, the cp command will be executed locally.
Thanks to CDSN blogger Jinking01.
answered Dec 24, 2021 at 3:32
Tansy ZTansy Z
1692 silver badges2 bronze badges
1
In the world of Linux, encountering errors is a common experience. One such error is “cp: cannot stat ‘filename’: No such file or directory”. This error typically occurs when you are trying to copy a file using the cp
command, but the system cannot find the file you are referencing. In this article, we will explore how to fix this error in detail.
To fix the «cp: cannot stat ‘filename’: No such file or directory» error in Linux command line, make sure you are in the correct directory where the file exists, check your permissions to ensure you have read access, and verify that the file or directory actually exists. If all these conditions are met, you should be able to successfully copy the file using the cp
command.
- Understanding the Error
- Common Causes of the Error
- How to Fix the Error
- Step 1: Verify the File or Directory Path
- Step 2: Check Your Permissions
- Step 3: Copy the File
- Conclusion
Understanding the Error
Before we delve into the solution, it’s crucial to understand what the error message means. The cp
command is used in Linux to copy files and directories. The error “cp: cannot stat ‘filename’: No such file or directory” is essentially saying that the system cannot find or access the file or directory you are trying to copy.
The term ‘stat’ refers to the Linux/UNIX system call that returns file or file system status. If the system cannot ‘stat’ a file, it means it cannot access the file’s metadata, which usually happens because the file does not exist.
Common Causes of the Error
The most common causes of this error include:
- Incorrect File or Directory Path: If the path to the file or directory is incorrect, the system will not be able to find it. Remember that Linux is case-sensitive, so ‘File’ and ‘file’ would be considered different.
- Insufficient Permissions: If you do not have the necessary permissions to access the file or directory, you will not be able to copy it.
- Non-Existent File or Directory: If the file or directory you are trying to copy does not exist, you will encounter this error.
Now that we understand the error and its causes, let’s look at how to fix it.
Step 1: Verify the File or Directory Path
First, ensure that you are in the correct directory where the file exists. You can use the cd
command to change the directory. For example, if your file is in a directory named ‘Documents’, you would use:
cd Documents
Next, use the ls
command to list all the files and directories in the current directory:
ls
Look for your file in the list. If it’s there, you should be able to copy it. If not, you may be in the wrong directory or the file may not exist.
Step 2: Check Your Permissions
If you are in the correct directory and the file exists, but you still cannot copy it, you may not have the necessary permissions. You can check the permissions of a file or directory using the ls -l
command:
ls -l filename
This will display the permissions of the file or directory. If you do not have read access, you will not be able to copy the file. In this case, you may need to change the permissions using the chmod
command or copy the file as a superuser with the sudo
command.
Step 3: Copy the File
Once you have verified the file path and ensured you have the necessary permissions, you can attempt to copy the file again using the cp
command:
cp filename /path/to/destination
Replace ‘filename’ with the name of your file and ‘/path/to/destination’ with the path where you want to copy the file to.
Conclusion
The “cp: cannot stat ‘filename’: No such file or directory” error in Linux can be frustrating, but it is usually easy to fix. By checking the file path, verifying your permissions, and ensuring the file exists, you should be able to resolve this error. Remember, Linux is case-sensitive and precise with file paths, so always double-check your commands for accuracy.
If you’re interested in learning more about Linux command line, check out this comprehensive guide. Happy troubleshooting!
If you encounter this error, first verify that you are in the correct directory where the file exists. Use the cd
command to change to the appropriate directory and then use the ls
command to check if the file is present. If it is, ensure that you have the necessary permissions to access the file. You can use the ls -l
command to check the permissions. If you do not have the required permissions, you may need to change them using the chmod
command or copy the file as a superuser with the sudo
command.
There could be a few reasons for this. First, double-check the spelling and case of the filename. Linux is case-sensitive, so «File» and «file» would be considered different. Additionally, ensure that you are in the correct directory where the file is located. If you are in a different directory, the system will not be able to find the file. Finally, check if you have the necessary read permissions to access the file. If not, you will need to change the permissions or copy the file as a superuser.
Yes, the cp
command can be used to copy both files and directories. To copy a directory, use the -r
or --recursive
option with the cp
command. For example, to copy a directory named «my_directory» to a destination directory, you would use: cp -r my_directory /path/to/destination
. This will recursively copy the entire directory and its contents to the specified destination.
Yes, you can copy multiple files or directories at once using the cp
command. Simply list all the files and directories you want to copy, followed by the destination directory. For example, to copy three files named «file1.txt», «file2.txt», and «file3.txt» to a destination directory, you would use: cp file1.txt file2.txt file3.txt /path/to/destination
. All the listed files will be copied to the specified destination directory.
Yes, you can use wildcards with the cp
command to copy multiple files that match a specific pattern. Wildcards are characters that represent other characters or groups of characters. For example, the *
wildcard represents any sequence of characters. To copy all files in a directory that end with «.txt» to a destination directory, you would use: cp *.txt /path/to/destination
. This will copy all files with the «.txt» extension to the specified destination directory.