How to open files with forward dash in linux

1

I need to open a file with filename that contains forward slashes. I am wondering how I can do that. I have been searching through Google and I can't seem to find a way.

Thanks

Gnator

Posted 2013-06-04T22:29:46.667

Reputation: 11

1Filenames under *nix can't contain forward slashes. – Ignacio Vazquez-Abrams – 2013-06-04T22:32:18.070

Welcome to SO. what OS do you uses? (you tagged UNIX, but under UNIX the files doesn't contains f-slases, so probably it is the full path) in what language want open it? some details will speedup the answer, especially when you show what you already tried. and spend some time reading the http://stackoverflow.com/helpcenter

– jm666 – 2013-06-04T22:35:32.873

1I am using linux but the file I am downloading is from another OS thats why there are forward slashes. I am trying to unzip the file in terminal. I am completely sure the forward slashes are not due to directory / file system and it is the actual name of the file. – Gnator – 2013-06-04T22:46:57.653

1@IgnacioVazquez-Abrams They can, because file names are just byte streams and not aware of the encoding. The restriction is imposed in the Unix kernel function namei. It treats a few values special, one of them is ASCII 0x2f (/). One could use an encoding (encodings are only relevant for user level programs, not kernel functions) which translates / to another value than 0x2f. – Marco – 2013-06-04T23:06:56.147

Answers

2

Turning my comment into a bit of a possibly useful answer. Try renaming the file.

ls -i

Will give you the inode number of the file. You can then use a combination of find and mv to rename the file as follows:

find . -inum "inode-number-from-ls -i" -exec mv {} "newfilename" \;

Give the file a "normal" new file name and you're good to go.

SBI

Posted 2013-06-04T22:29:46.667

Reputation: 771

Why on Earth is this going to work? If find can pass a valid name to mv, then it's not a problem for a user to do the same. – firegurafiku – 2017-04-18T22:55:27.160

Because the name that find passes will be correctly encoded, unlike what the user would type on the terminal. – SBI – 2017-04-19T08:24:49.380

Good one! Should work. – fedorqui – 2013-06-05T08:03:45.123

-1

It must be a Windows file. You have several ways to solve this:

  • Wrap the name with quotes: vi "file/name".
  • Use tab to complete the name. It will give you the proper way to write it.
  • Find a pattern and use *. If the name of the file is file/name, you can do vi fil* and this will be opened (together with others that can have same pattern).

fedorqui

Posted 2013-06-04T22:29:46.667

Reputation: 1 517

The filesystem calls will interpret / as the directory separator regardless of how it's specified on the command line. – Ignacio Vazquez-Abrams – 2013-06-04T22:35:43.947

1Yes, I see. Nevertheless, the fabulous tab can provide a way to escape it, doesn't it? – fedorqui – 2013-06-04T22:37:56.743

1I tried all three methods unfortunately none worked. I am wondering if I can somehow rename the entire file on a program using java or something that isn't as aware of the encoding. – Gnator – 2013-06-04T23:11:14.703

What about mv file* newname? – fedorqui – 2013-06-04T23:15:04.413

Unfortunately it didn't work also. I suspect moving the file around corrupts the file because it is a zip file originally. – Gnator – 2013-06-04T23:34:33.527

You have to rename the file using the inode value. – SBI – 2013-06-05T07:03:36.030