-1

Recently, I come across creating a file name with date format as below example by using bash shell

touch 22/04/2017

It throws error, which means you can't create file name with this format.

touch: 22/04/2014: No such file or directory

Does any one know?

codeforester
  • 39,467
  • 16
  • 112
  • 140
jits_on_moon
  • 827
  • 6
  • 10
  • 2
    1) Please add a link to the place where you read that files can be saved with names including the `/` character. 2) Please show the contents of the directory where you issued the command `touch 22/04/2017` (hint: there won't be any such file..., since `22` and `04` here are interpreted as sub-directories of the current directory). 3) Please elaborate as to **why** you want to want a file with a date format like "dd/mm/yyyy" instead of, say "dd-mm-yyyy" or "dd_mm_yyyy" – Vladislav Martin Apr 22 '17 at 17:48
  • While this is not a direct answer, I would strongly consider using format YYYY-MM-DD instead. It produces character sequences valid for file names, is easy to read, and also sorts well. – Fred Apr 22 '17 at 19:07

2 Answers2

5

You cannot use / for filenames. It is interpreted as folder separator.

Using touch 22/04/2017 indicates you want to create file 2017 in subtree 22/04.

You can use other separator like _, or -

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
3

Warning: This is a way to do it just for the sake of doing it, it's not actually recommended nor used. There are reasons such characters are not allowed in the first place.

If you need to do that, you could use this character which looks exactly like the / but is not. Generally, as Guillaume Jacquenot said, such filenames are not allowed.

Kostas Andrianos
  • 1,551
  • 2
  • 16
  • 21
  • While this may be technically OK, it would be very confusing for a human looking at the path displayed on screen. I would try to avoid that. – Fred Apr 22 '17 at 19:06
  • 1
    Sure, it's not recommended at all, but it is there if you feel like doing it. This is like the ability of java to use non-english variable names. It's not recommended and it's very difficult to find the bug if you do it by accident, but it's there. – Kostas Andrianos Apr 22 '17 at 19:09
  • 1
    There's also `╱`, `⁄`, `⧸`, or `/`. – Socowi Apr 22 '17 at 19:16
  • My question is, how would anyone make use of such filenames? Imagine wanting to `find` something with any of these characters in it's name. Pain. – Kostas Andrianos Apr 22 '17 at 19:19
  • @Dinos_12345 I understand, but as these forums are read by people of varying grasp of the issues, it is always useful to add a bit of a warning when a proposal, while technically correct, might have some unpleasant aspects not immediately obvious to some readers. – Fred Apr 22 '17 at 19:20
  • @Fred Thanks for pointing that out, I added a warning just to be safe :) – Kostas Andrianos Apr 22 '17 at 19:24