Escape a backup date in a file nameConverting a string from a file into a dateHow to append date to backup fileCreate sub-directories and organize files by date from file namecannot create regular file 'filename': File existsHow to append a date to all files in a directory without touching sub-directories via bash scriptadding date to beginning of file name using scriptinserting modified date into filename - 2 casesCan the date command take as argument a date string in a file given by another date command?Set file modification date from date stored as filenameHow to Find and delete File Older than 3 years without scaning on modified date?
Is this apparent Class Action settlement a spam message?
Do all network devices need to make routing decisions, regardless of communication across networks or within a network?
How to safely derail a train during transit?
Two monoidal structures and copowering
What can we do to stop prior company from asking us questions?
Sort a list by elements of another list
Nautlius: add mouse right-click action to compute MD5 sum
How easy is it to start Magic from scratch?
How to Reset Passwords on Multiple Websites Easily?
Purchasing a ticket for someone else in another country?
What happens if you roll doubles 3 times then land on "Go to jail?"
Short story about space worker geeks who zone out by 'listening' to radiation from stars
Where does the Z80 processor start executing from?
Gears on left are inverse to gears on right?
CREATE opcode: what does it really do?
Large drywall patch supports
Avoiding estate tax by giving multiple gifts
Pole-zeros of a real-valued causal FIR system
Term for the "extreme-extension" version of a straw man fallacy?
A particular customize with green line and letters for subfloat
How can a function with a hole (removable discontinuity) equal a function with no hole?
Is there a problem with hiding "forgot password" until it's needed?
How can I kill an app using Terminal?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Escape a backup date in a file name
Converting a string from a file into a dateHow to append date to backup fileCreate sub-directories and organize files by date from file namecannot create regular file 'filename': File existsHow to append a date to all files in a directory without touching sub-directories via bash scriptadding date to beginning of file name using scriptinserting modified date into filename - 2 casesCan the date command take as argument a date string in a file given by another date command?Set file modification date from date stored as filenameHow to Find and delete File Older than 3 years without scaning on modified date?
I have been trying to:
cp file.csv file.$(date +%D).csv
But it fails because the filenames is: file.03/27/19.csv with the slash of separate directories.
And I have been trying again to:
cp file.csv file.$(printf "%q" $(date +%D)).csv
But it still fails.
shell filenames date escape-characters slash
add a comment |
I have been trying to:
cp file.csv file.$(date +%D).csv
But it fails because the filenames is: file.03/27/19.csv with the slash of separate directories.
And I have been trying again to:
cp file.csv file.$(printf "%q" $(date +%D)).csv
But it still fails.
shell filenames date escape-characters slash
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
the problem is your use of thedateformat using the/character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available fromdate. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.
– 0xSheepdog
5 hours ago
add a comment |
I have been trying to:
cp file.csv file.$(date +%D).csv
But it fails because the filenames is: file.03/27/19.csv with the slash of separate directories.
And I have been trying again to:
cp file.csv file.$(printf "%q" $(date +%D)).csv
But it still fails.
shell filenames date escape-characters slash
I have been trying to:
cp file.csv file.$(date +%D).csv
But it fails because the filenames is: file.03/27/19.csv with the slash of separate directories.
And I have been trying again to:
cp file.csv file.$(printf "%q" $(date +%D)).csv
But it still fails.
shell filenames date escape-characters slash
shell filenames date escape-characters slash
edited 26 mins ago
Gilles
544k12811041621
544k12811041621
asked 5 hours ago
tres.14159tres.14159
2612
2612
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
the problem is your use of thedateformat using the/character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available fromdate. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.
– 0xSheepdog
5 hours ago
add a comment |
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
the problem is your use of thedateformat using the/character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available fromdate. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.
– 0xSheepdog
5 hours ago
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
the problem is your use of the
date format using the / character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available from date. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.– 0xSheepdog
5 hours ago
the problem is your use of the
date format using the / character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available from date. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.– 0xSheepdog
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period.
You can use characters that look like / like ⁄ (fraction slash), so you could do:
cp file.csv "file.$(date +%D | sed 's|/|⁄|g').csv"
But you may run into problems like the file name being rendered differently in locales using a different charset.
My advice would be to use the standard non-ambiguous (for most people outside the US, 03/12/18 would be interpreted as the 3rd of December 2018 for instance) YYYY-mm-dd format instead (which also helps wrt sorting):
cp file.csv "file.$(date +%Y-%m-%d).csv"
Which with many date implementations you can shorten to:
cp file.csv "file.$(date +%F).csv"
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509043%2fescape-a-backup-date-in-a-file-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period.
You can use characters that look like / like ⁄ (fraction slash), so you could do:
cp file.csv "file.$(date +%D | sed 's|/|⁄|g').csv"
But you may run into problems like the file name being rendered differently in locales using a different charset.
My advice would be to use the standard non-ambiguous (for most people outside the US, 03/12/18 would be interpreted as the 3rd of December 2018 for instance) YYYY-mm-dd format instead (which also helps wrt sorting):
cp file.csv "file.$(date +%Y-%m-%d).csv"
Which with many date implementations you can shorten to:
cp file.csv "file.$(date +%F).csv"
add a comment |
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period.
You can use characters that look like / like ⁄ (fraction slash), so you could do:
cp file.csv "file.$(date +%D | sed 's|/|⁄|g').csv"
But you may run into problems like the file name being rendered differently in locales using a different charset.
My advice would be to use the standard non-ambiguous (for most people outside the US, 03/12/18 would be interpreted as the 3rd of December 2018 for instance) YYYY-mm-dd format instead (which also helps wrt sorting):
cp file.csv "file.$(date +%Y-%m-%d).csv"
Which with many date implementations you can shorten to:
cp file.csv "file.$(date +%F).csv"
add a comment |
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period.
You can use characters that look like / like ⁄ (fraction slash), so you could do:
cp file.csv "file.$(date +%D | sed 's|/|⁄|g').csv"
But you may run into problems like the file name being rendered differently in locales using a different charset.
My advice would be to use the standard non-ambiguous (for most people outside the US, 03/12/18 would be interpreted as the 3rd of December 2018 for instance) YYYY-mm-dd format instead (which also helps wrt sorting):
cp file.csv "file.$(date +%Y-%m-%d).csv"
Which with many date implementations you can shorten to:
cp file.csv "file.$(date +%F).csv"
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period.
You can use characters that look like / like ⁄ (fraction slash), so you could do:
cp file.csv "file.$(date +%D | sed 's|/|⁄|g').csv"
But you may run into problems like the file name being rendered differently in locales using a different charset.
My advice would be to use the standard non-ambiguous (for most people outside the US, 03/12/18 would be interpreted as the 3rd of December 2018 for instance) YYYY-mm-dd format instead (which also helps wrt sorting):
cp file.csv "file.$(date +%Y-%m-%d).csv"
Which with many date implementations you can shorten to:
cp file.csv "file.$(date +%F).csv"
edited 4 hours ago
answered 5 hours ago
Stéphane ChazelasStéphane Chazelas
311k57588946
311k57588946
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509043%2fescape-a-backup-date-in-a-file-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
5 hours ago
the problem is your use of the
dateformat using the/character. You said it yourself, the shell is seeing them as directory markers. Try one of the many other options available fromdate. You might be able to get the / escaped so the filename uses the character code (like putting a space in a filename), but that is often problematic.– 0xSheepdog
5 hours ago