Escape a mm/dd/YY backup date in a file name The Next CEO of Stack Overflowthe slash (/) after a directory name on shell commandsDate time in Linux bashCreate sub-directories and organize files by date from file nameWhat is the difference between a directory name that ends with a slash and one that does not?How do you put date and time in a file name?adding date to beginning of file name using scripttcsh - echo escape code for escapeConvert date in bash shellHow to adjust the Exif timestamp of a photo using the date in its nameshell script to walk folders and sub-folders, convert timestamp to UTC format and export .csv file
How do I go from 300 unfinished/half written blog posts, to published posts?
Won the lottery - how do I keep the money?
Indicator light circuit
Why do professional authors make "consistency" mistakes? And how to avoid them?
Why does the UK parliament need a vote on the political declaration?
What connection does MS Office have to Netscape Navigator?
WOW air has ceased operation, can I get my tickets refunded?
Received an invoice from my ex-employer billing me for training; how to handle?
MessageLevel in QGIS3
Do I need to enable Dev Hub in my PROD Org?
Complex fractions
Has this building technique been used in an official set?
Non-deterministic sum of floats
How powerful is the invisibility granted by the Gloom Stalker ranger's Umbral Sight feature?
Anatomically Correct Strange Women In Ponds Distributing Swords
How do I make a variable always equal to the result of some calculations?
Why do airplanes bank sharply to the right after air-to-air refueling?
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?
Inappropriate reference requests from Journal reviewers
Novel about a guy who is possessed by the divine essence and the world ends?
Several mode to write the symbol of a vector
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
Escape a mm/dd/YY backup date in a file name
The Next CEO of Stack Overflowthe slash (/) after a directory name on shell commandsDate time in Linux bashCreate sub-directories and organize files by date from file nameWhat is the difference between a directory name that ends with a slash and one that does not?How do you put date and time in a file name?adding date to beginning of file name using scripttcsh - echo escape code for escapeConvert date in bash shellHow to adjust the Exif timestamp of a photo using the date in its nameshell script to walk folders and sub-folders, convert timestamp to UTC format and export .csv file
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
2 days ago
the problem is your use of thedate
format 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
2 days 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 yesterday
Stéphane Chazelas
312k57589946
312k57589946
asked 2 days ago
tres.14159tres.14159
4314
4314
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
2 days ago
the problem is your use of thedate
format 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
2 days ago
add a comment |
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
2 days ago
the problem is your use of thedate
format 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
2 days ago
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
2 days ago
You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…
– tres.14159
2 days 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
2 days 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
2 days 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 ∕
(U+2215 division slash) or ⁄
(U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, includes GBK, BIG5, UTF-8, GB18030):
cp file.csv "file.$(date +%D | sed 's|/|∕|g').csv"
Or with some shells (zsh
, bash
at least):
cp file.csv "file.$(date +%D | sed $'s|/|u2215|g').csv"
(here using sed
instead of tr
as some tr
implementations including GNU tr
still don't support multi-byte characters).
But you may run into problems like the file name being rendered differently in locales using a different charset from the one that was in use at the time you created the file (and of course the confusion of users when they see what looks like a slash in a file name).
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"
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
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');
);
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-mm-dd-yy-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 ∕
(U+2215 division slash) or ⁄
(U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, includes GBK, BIG5, UTF-8, GB18030):
cp file.csv "file.$(date +%D | sed 's|/|∕|g').csv"
Or with some shells (zsh
, bash
at least):
cp file.csv "file.$(date +%D | sed $'s|/|u2215|g').csv"
(here using sed
instead of tr
as some tr
implementations including GNU tr
still don't support multi-byte characters).
But you may run into problems like the file name being rendered differently in locales using a different charset from the one that was in use at the time you created the file (and of course the confusion of users when they see what looks like a slash in a file name).
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"
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
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 ∕
(U+2215 division slash) or ⁄
(U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, includes GBK, BIG5, UTF-8, GB18030):
cp file.csv "file.$(date +%D | sed 's|/|∕|g').csv"
Or with some shells (zsh
, bash
at least):
cp file.csv "file.$(date +%D | sed $'s|/|u2215|g').csv"
(here using sed
instead of tr
as some tr
implementations including GNU tr
still don't support multi-byte characters).
But you may run into problems like the file name being rendered differently in locales using a different charset from the one that was in use at the time you created the file (and of course the confusion of users when they see what looks like a slash in a file name).
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"
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
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 ∕
(U+2215 division slash) or ⁄
(U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, includes GBK, BIG5, UTF-8, GB18030):
cp file.csv "file.$(date +%D | sed 's|/|∕|g').csv"
Or with some shells (zsh
, bash
at least):
cp file.csv "file.$(date +%D | sed $'s|/|u2215|g').csv"
(here using sed
instead of tr
as some tr
implementations including GNU tr
still don't support multi-byte characters).
But you may run into problems like the file name being rendered differently in locales using a different charset from the one that was in use at the time you created the file (and of course the confusion of users when they see what looks like a slash in a file name).
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 ∕
(U+2215 division slash) or ⁄
(U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, includes GBK, BIG5, UTF-8, GB18030):
cp file.csv "file.$(date +%D | sed 's|/|∕|g').csv"
Or with some shells (zsh
, bash
at least):
cp file.csv "file.$(date +%D | sed $'s|/|u2215|g').csv"
(here using sed
instead of tr
as some tr
implementations including GNU tr
still don't support multi-byte characters).
But you may run into problems like the file name being rendered differently in locales using a different charset from the one that was in use at the time you created the file (and of course the confusion of users when they see what looks like a slash in a file name).
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 yesterday
answered 2 days ago
Stéphane ChazelasStéphane Chazelas
312k57589946
312k57589946
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
add a comment |
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
2
2
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
Other characters similar to slash can also be cumbersome to type in terminal.
– gronostaj
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
@gronostaj, I've added a method to specify the character based on its Unicode codepoint.
– Stéphane Chazelas
yesterday
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');
);
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-mm-dd-yy-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');
);
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');
);
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');
);
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
2 days 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 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
2 days ago