Mkdir: Cannot Create Directory No Such File or Directory
I Can't Find a Solution for This Problem. I Am Trying to Write a Script That Creates a Folder, Which Name Is the Current Date, with All Content of the Current...
I can't find a solution for this problem. I am trying to write a script that creates a folder, which name is the current date, with all content of the current directory so I can backup a bunch of files. I tried following things already that doesn't work:
- use "mkdir -p" to create parent directories
- not using relative path with "pwd"
But when I try and create a directory out of an script in the terminal(also bash) I can create perfectly fine directories with the date inside. (following command)
mkdir backup$(date +%d-%m-%Y_%H:%M)
My Code
#!/bin/bash
DATE=$(date +%d-%m-%Y_%H:%M)
PWD=$(pwd)
FILENAME=backup$DATE
if [ -d "backup/" ]; then
mkdir -p backup/$FILENAME
cp -r * backup/$FILENAME
else
mkdir -p backup/
mkdir -p backup/$FILENAME
cp -r * backup/$FILENAME
fi
Must Read
Error thrown
mkdir: cannot create directory ‘backup/backup18-01-2022_12:43’: No such file or directory