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

前端 未结 5 1410
無奈伤痛
無奈伤痛 2021-02-15 23:39

like /usr/local?

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

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


        
相关标签:
5条回答
  • 2021-02-16 00:17

    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.

    0 讨论(0)
  • 2021-02-16 00:20

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

    0 讨论(0)
  • 2021-02-16 00:25

    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.

    0 讨论(0)
  • 2021-02-16 00:32

    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
    
    0 讨论(0)
  • 2021-02-16 00:35

    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?

    0 讨论(0)
提交回复
热议问题