How to use file protocol to access a directory on local system?

五迷三道 提交于 2019-12-21 04:28:12

问题


like /usr/local?

I tried file:///usr/local but failed

[root@www2 robot]# cd file:///usr/local
-bash: cd: file:///usr/local: No such file or directory

回答1:


If you have a requirement to be able to access generic URLs from your shell, try using curl as a replacement for your cat:

curl file:///path/to/file.txt
curl http://www.domain.com/file.txt

But as other posters have pointed out, the shell itself doesn't understand URLs.




回答2:


If you have to deal with file:///usr/local on the command line, you could just remove the "file://" part. And do then a normal your command, e.g.:

echo "file:///usr/local/" |  sed 's/file:\/\///' | cd



回答3:


bash and cd does not function across multiple protocols to my knowledge. If you want to access stuff through other protocols you have to mount them to the local filesystem.

You're not trying to cd to some location provided by a user on some web form are you?




回答4:


file:/// doesn't work on bash or derivative shells.

It will work in most browsers, and possible wget and curl, but bash is not a web browser.




回答5:


The file: protocol only exists in web browsers. Try it in Firefox, it should work. To do it in a shell, just use

cd /usr/local/

Don't use file:. It's the same reason why you can't

cat http://www.google.com

Which would be awesome (but you have to use something like wget or curl).



来源:https://stackoverflow.com/questions/947228/how-to-use-file-protocol-to-access-a-directory-on-local-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!