LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2018, 02:27 PM   #1
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 282

Rep: Reputation: 30
Variable in Filename for 7zip


This is going to be stupid simple but I can't for the life of me figure this out. I ultimately am going to be backing up some files but first am using 7zip to put them in an archive. Whenever I run the following:

Code:
7z a -p -mx=9 -mhe -t7z backup_$(date +%D).7z /home/user/Documents
it gives me a folder for "backup_04" and then a folder inside that with the next part of the date and so on.

I've tried putting it in quotes (both single and double), back-tics, and parentheses. It either does what I said before or it gives the literal string for the date.


**Update**

So I don't think 7zip liked the format for the date. I ended up using this instead and it seems to work:

Code:
7z a -p -mx=9 -mhe backup_$(date +%y%m%d).7z /home/user/Documents

Last edited by snowman81; 04-20-2018 at 03:00 PM. Reason: solved
 
Old 04-20-2018, 03:10 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
From date man pages.
Quote:
%D date; same as %m/%d/%y
Slashes are not valid file name characters. You need to use - or _ or nothing. I prefer for sorting purposes to use date first of the format YYYYMMDD_backup but choose what is best for you. See the date man page for additional information.

Code:
date +%Y%m%d_backup
I see you solved the problem but not the reason. It is a filesystem limitation and not due to 7zip.

Last edited by michaelk; 04-20-2018 at 03:16 PM.
 
Old 04-20-2018, 03:19 PM   #3
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 30
Thank you!
 
  


Reply

Tags
7zip, backup, mint-18



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
get the filename where the variable is set oraenthu@live.com Linux - Newbie 1 02-09-2015 06:37 PM
Make a variable = filename without the extension greengrocer Linux - Newbie 8 04-24-2011 10:16 AM
replace filename with variable Siljrath Programming 2 11-12-2009 12:40 AM
Read filename as a variable kicap Programming 3 08-12-2009 04:27 PM
Using a variable containing a filename in grep TrumpetMan258 Programming 2 03-01-2008 01:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration