Escape a mm/dd/YY backup date in a file namethe slash (/) after a directory name on shell commandsDate time...

Number of words that can be made using all the letters of the word W, if Os as well as Is are separated is?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Why not increase contact surface when reentering the atmosphere?

Why doesn't table tennis float on the surface? How do we calculate buoyancy here?

Class Action - which options I have?

Roman Numeral Treatment of Suspensions

Pole-zeros of a real-valued causal FIR system

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Return the Closest Prime Number

How does the UK government determine the size of a mandate?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How long to clear the 'suck zone' of a turbofan after start is initiated?

Do the temporary hit points from the Battlerager barbarian's Reckless Abandon stack if I make multiple attacks on my turn?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

Avoiding estate tax by giving multiple gifts

Abbreviate author names as "Lastname AB" (without space or period) in bibliography

Increase performance creating Mandelbrot set in python

Why escape if the_content isnt?

Is the destination of a commercial flight important for the pilot?

How can I quit an app using Terminal?

Is HostGator storing my password in plaintext?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

How do scammers retract money, while you can’t?

How to be diplomatic in refusing to write code that breaches the privacy of our users



Escape a mm/dd/YY backup date in a file name


the 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













5















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
    16 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
    16 hours ago


















5















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
    16 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
    16 hours ago
















5












5








5








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 17 mins ago









Stéphane Chazelas

312k57589946




312k57589946










asked 16 hours ago









tres.14159tres.14159

3814




3814













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

    – tres.14159
    16 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
    16 hours ago





















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

    – tres.14159
    16 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
    16 hours ago



















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

– tres.14159
16 hours ago





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

– tres.14159
16 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
16 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
16 hours ago












1 Answer
1






active

oldest

votes


















16














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"


Or with some shells (zsh, bash at least):



cp file.csv "file.$(date +%D | sed $'s|/|u2044|g').csv"


(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


























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

    – gronostaj
    55 mins ago











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









16














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"


Or with some shells (zsh, bash at least):



cp file.csv "file.$(date +%D | sed $'s|/|u2044|g').csv"


(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


























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

    – gronostaj
    55 mins ago
















16














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"


Or with some shells (zsh, bash at least):



cp file.csv "file.$(date +%D | sed $'s|/|u2044|g').csv"


(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


























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

    – gronostaj
    55 mins ago














16












16








16







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"


Or with some shells (zsh, bash at least):



cp file.csv "file.$(date +%D | sed $'s|/|u2044|g').csv"


(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 (fraction slash), so you could do:



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|/|u2044|g').csv"


(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 19 mins ago

























answered 16 hours ago









Stéphane ChazelasStéphane Chazelas

312k57589946




312k57589946













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

    – gronostaj
    55 mins ago



















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

    – gronostaj
    55 mins ago

















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

– gronostaj
55 mins ago





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

– gronostaj
55 mins ago


















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

is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...