I use the tar
command a lot, very familiar with it. However, I tried creating an archive using the date command to name the archive file, and it throws an error to the effect that it can't open the file, which is strange because I'm not trying to open the file but create it.
Here's a copy of the directory, the code, and the error:
@MDG /media/VideoCam/Test $ ll
total 468
drwxr-xr-x 3 neo neo 4096 Sep 5 09:55 ./
drwxr-xr-x 4 neo neo 466944 Sep 4 21:54 ../
-rw-r--r-- 1 neo neo 45 Sep 5 08:52 1.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 1.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 2.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 2.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 3.jpg
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 4.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 4.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 5.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 5.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 6.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 6.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 7.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 7.mp4
-rw-r--r-- 1 neo neo 0 Sep 4 19:32 8.jpg
-rw-rw-r-- 1 neo neo 0 Sep 5 08:41 8.mp4
drwxr-xr-x 2 neo neo 4096 Sep 4 19:30 Archive/
neo@MDG /media/VideoCam/Test $ sudo tar -zcvf "archive.$(date '+%D').tar.gz" *.jpg
tar (child): archive.09/05/17.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
6.jpg
7.jpg
8.jpg
neo@MDG /media/VideoCam/Test $
I've tried many different concatenations, with and without quotes, switching up the order of the command options (zcvf), etc. If I leave out the date command and just give it a name, e.g. archive.tar.gz
, it executes perfectly, but introducing the date command causes the error. I've also tried setting the date command as a variable with a similar result.
/
is not allowed in filenames.