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

Can a PhD from a non-TU9 German university become a professor in a TU9 university?

Find a path from s to t using as few red nodes as possible

How to unfasten electrical subpanel attached with ramset

Another proof that dividing by 0 does not exist -- is it right?

Ising model simulation

How to implement Comparable so it is consistent with identity-equality

What steps are necessary to read a Modern SSD in Medieval Europe?

How seriously should I take size and weight limits of hand luggage?

Planeswalker Ability and Death Timing

Prodigo = pro + ago?

Are British MPs missing the point, with these 'Indicative Votes'?

Is a linearly independent set whose span is dense a Schauder basis?

Compilation of a 2d array and a 1d array

Why does freezing point matter when picking cooler ice packs?

Incomplete cube

How to find if SQL server backup is encrypted with TDE without restoring the backup

Could you use a laser beam as a modulated carrier wave for radio signal?

Could a dragon use its wings to swim?

A hang glider, sudden unexpected lift to 25,000 feet altitude, what could do this?

Does int main() need a declaration on C++?

Direct Implications Between USA and UK in Event of No-Deal Brexit

Find the majority element, which appears more than half the time

Mathematica command that allows it to read my intentions

What is the difference between 'contrib' and 'non-free' packages repositories?



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










6















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.










share|improve this question
























  • You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

    – tres.14159
    Mar 27 at 17:31











  • 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
    Mar 27 at 17:32
















6















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.










share|improve this question
























  • You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

    – tres.14159
    Mar 27 at 17:31











  • 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
    Mar 27 at 17:32














6












6








6








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 9:27









Stéphane Chazelas

312k57591948




312k57591948










asked Mar 27 at 17:27









tres.14159tres.14159

4314




4314












  • You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

    – tres.14159
    Mar 27 at 17:31











  • 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
    Mar 27 at 17:32


















  • You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

    – tres.14159
    Mar 27 at 17:31











  • 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
    Mar 27 at 17:32

















You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

– tres.14159
Mar 27 at 17:31





You can not set a filename with slash characters: stackoverflow.com/questions/9847288/…

– tres.14159
Mar 27 at 17:31













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
Mar 27 at 17:32






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
Mar 27 at 17:32











1 Answer
1






active

oldest

votes


















20














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"





share|improve this answer




















  • 2





    Other characters similar to slash can also be cumbersome to type in terminal.

    – gronostaj
    Mar 28 at 8:49











  • @gronostaj, I've added a method to specify the character based on its Unicode codepoint.

    – Stéphane Chazelas
    Mar 28 at 16:37











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
);



);













draft saved

draft discarded


















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









20














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"





share|improve this answer




















  • 2





    Other characters similar to slash can also be cumbersome to type in terminal.

    – gronostaj
    Mar 28 at 8:49











  • @gronostaj, I've added a method to specify the character based on its Unicode codepoint.

    – Stéphane Chazelas
    Mar 28 at 16:37















20














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"





share|improve this answer




















  • 2





    Other characters similar to slash can also be cumbersome to type in terminal.

    – gronostaj
    Mar 28 at 8:49











  • @gronostaj, I've added a method to specify the character based on its Unicode codepoint.

    – Stéphane Chazelas
    Mar 28 at 16:37













20












20








20







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"





share|improve this answer















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"






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 16:52

























answered Mar 27 at 17:33









Stéphane ChazelasStéphane Chazelas

312k57591948




312k57591948







  • 2





    Other characters similar to slash can also be cumbersome to type in terminal.

    – gronostaj
    Mar 28 at 8:49











  • @gronostaj, I've added a method to specify the character based on its Unicode codepoint.

    – Stéphane Chazelas
    Mar 28 at 16:37












  • 2





    Other characters similar to slash can also be cumbersome to type in terminal.

    – gronostaj
    Mar 28 at 8:49











  • @gronostaj, I've added a method to specify the character based on its Unicode codepoint.

    – Stéphane Chazelas
    Mar 28 at 16:37







2




2





Other characters similar to slash can also be cumbersome to type in terminal.

– gronostaj
Mar 28 at 8:49





Other characters similar to slash can also be cumbersome to type in terminal.

– gronostaj
Mar 28 at 8:49













@gronostaj, I've added a method to specify the character based on its Unicode codepoint.

– Stéphane Chazelas
Mar 28 at 16:37





@gronostaj, I've added a method to specify the character based on its Unicode codepoint.

– Stéphane Chazelas
Mar 28 at 16:37

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Triangular numbers and gcdProving sum of a set is $0 pmod n$ if $n$ is odd, or $fracn2 pmod n$ if $n$ is even?Is greatest common divisor of two numbers really their smallest linear combination?GCD, LCM RelationshipProve a set of nonnegative integers with greatest common divisor 1 and closed under addition has all but finite many nonnegative integers.all pairs of a and b in an equation containing gcdTriangular Numbers Modulo $k$ - Hit All Values?Understanding the Existence and Uniqueness of the GCDGCD and LCM with logical symbolsThe greatest common divisor of two positive integers less than 100 is equal to 3. Their least common multiple is twelve times one of the integers.Suppose that for all integers $x$, $x|a$ and $x|b$ if and only if $x|c$. Then $c = gcd(a,b)$Which is the gcd of 2 numbers which are multiplied and the result is 600000?

Ingelân Ynhâld Etymology | Geografy | Skiednis | Polityk en bestjoer | Ekonomy | Demografy | Kultuer | Klimaat | Sjoch ek | Keppelings om utens | Boarnen, noaten en referinsjes Navigaasjemenuwww.gov.ukOffisjele webside fan it regear fan it Feriene KeninkrykOffisjele webside fan it Britske FerkearsburoNederlânsktalige ynformaasje fan it Britske FerkearsburoOffisjele webside fan English Heritage, de organisaasje dy't him ynset foar it behâld fan it Ingelske kultuergoedYnwennertallen fan alle Britske stêden út 'e folkstelling fan 2011Notes en References, op dizze sideEngland

Հադիս Բովանդակություն Անվանում և նշանակություն | Դասակարգում | Աղբյուրներ | Նավարկման ցանկ