Cannot stat: no such file or directory

Part of my backup script.

Backup_Directory="/media/andy/Maxtor/Backup/Ubuntu_Mate_24.04/"
.
.
.
# 
cd /etc/hosts
tar -cvf hosts.tar hosts
/usr/bin/rsync --progress -r -u hosts.tar $Backup_Directory
/home/andy/bin/Backup_24_04.sh: line 46: cd: /etc/hosts: Not a directory
tar: hosts: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

Added the backslash. :slight_smile: Now I get an empty tar file.

cd /etc/hosts/
tar -cvf hosts.tar hosts
/usr/bin/rsync --progress -r -u hosts.tar $Backup_Directory

Hi, @fixit7 :slight_smile:

I hope you're now feeling better from your pain.

/etc/hosts is a (text) file named hosts that is located in the /etc directory and not a directory itself. So, it's natural that you're getting that cd: /etc/hosts: Not a directory error.

I hope this helps :slight_smile:

4 Likes

Thanks, my pain went to a 6 out of 10.

Your post helped some.

tar: hosts.tar: Cannot open: Permission denied
tar: Error is not recoverable: exiting now

I think that is because hosts is root owned.

I could use a modification of this.

echo UM_rocks | sudo -S thunar /home/andy/ &>/dev/null

2 Likes

Hi again, @fixit7 :slight_smile:

Given that /etc/hosts is a single file, do you have any reason to want to add it to a ".tar" file? If not, you could simply copy that file to the Backup Directory with the following command.

cp -pv /etc/hosts $Backup_Directory

I hope this helps :slight_smile:

2 Likes

Hi again, @fixit7 :slight_smile:

Given that /etc/hosts is a single file, do you have any reason to want to add it to a ".tar" file? If not, you could simply copy that file to the Backup Directory with the following command.

cp -pv /etc/hosts $Backup_Directory

I hope this helps :slight_smile:

3 Likes

It helped a lot. If I have a single file to back up, no need to compress it.

You get a blue ribbon. :slight_smile:

3 Likes