LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   root directory (https://www.linuxquestions.org/questions/linux-newbie-8/root-directory-840089/)

siva balan 10-24-2010 12:16 AM

root directory
 
i am using fedora 13.

if is use the command "cd //".

it changes to root directory.how is it?

what "//" denote?

thanks in advance..

honeybadger 10-24-2010 12:55 AM

Well this is strange. I did not try that command but then I think that should not work. You should try cd /.
For more info about directories try man hier.
Hope this helps.

David the H. 10-24-2010 01:07 AM

The backslash is used in the shell as an escape character. Since some characters, such as spaces, have special meanings, putting a backslash (also a special character) in front of them protects them from interpretation by the shell and makes them literal again. "/ " is a literal space, "/[/]" are literal brackets, and "//" is a literal forward slash.

So in the shell, // = /. But then it's up to the command you're passing it to how to interpret the single literal backslash. The cd command can accept one as a directory separator. You could also use cd "/" or cd '/', which do the same thing.

RootAround 10-24-2010 01:18 AM

I’ve used cd / and cd.. , but never cd //.

cd / puts you in the top directory, wherever you are. If enter an ls after cd / you should see some of these top-level directories:

boot bin dev etc home lib misc mnt net opt root srv usr var

cd .. puts you one directory ABOVE wherever you are.

More info. on the cd command is available here.

Info. on directory on Fedora directories is available here.

onebuck 10-24-2010 07:15 AM

Hi,

Quote:

Originally Posted by siva balan (Post 4137384)
i am using fedora 13.

if is use the command "cd //".

it changes to root directory.how is it?

what "//" denote?

thanks in advance..

'cd' is a 'bash' internal command.

Quote:

excerpt from 'man cd';
NAME
cd - Change working directory

SYNOPSIS
cd ?dirName?
____________________________________________________________________________________

DESCRIPTION
Change the current working directory to dirName, or to the home directory (as
specified in the HOME environment variable) if dirName is not given. Returns
an empty string. Note that the current working directory is a per-process
resource; the cd command changes the working directory for all interpreters
and (in a threaded environment) all threads.

EXAMPLES
Change to the home directory of the user fred:
cd ~fred

Change to the directory lib that is a sibling directory of the current one:
cd ../lib
You should read the following;

Quote:

excerpt 'User Commands (1)';
cd [-L|-P] [dir] Change the current directory to dir. The variable HOME is the default dir. The variable CDPATH defines the search path for the directory containing dir. Alternative directory names in CDPATH are separated by a colon (:). A null directory name in CDPATH is the same as the current directory, i.e., ``.''. If dir begins with a slash (/), then CDPATH is not used. The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command); the -L option forces symbolic links to be followed. An argument of - is equivalent to $OLDPWD. If a non-empty directory name from CDPATH is used, or if - is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard output. The return value is true if the directory was successfully changed; false otherwise.
So from the above definition 'cd //' will indeed place the root/privileged user in '/'.

'man command' is your friend!

:hattip:

eSelix 10-24-2010 08:02 AM

This is intentional action. All consecutive slashes are replaced with one slash to canonicalization. I think this was made for simplify writing scripts.

DaneM 10-24-2010 03:40 PM

Also, trailing slashes in a path only denote that the path is, in fact, a directory (as opposed to another file type). Try "cd /home" and "cd /home/". Same result (you end up in /home). "/" is the name of a directory (the root directory). Therefore, putting a slash after it is just like (redundantly) saying that "/" is, in fact, a directory.

If you're trying to get to a networked path, you'll want to use the distributions SMB/Samba network browser. There, you can enter a path like "//computer/sharedirectory/file", and it will take you to the expected location. You can also do this using smbmount or "mount -t cifs" like this:

Code:

mount -t cifs //computer/sharedirectory/ /place/you/want/to/mount/it/
As mentioned above, in order to type a backslash, "\" on the command line and have it actually actlike punctuation, rather than escape character, you need to type two of them for each backslash you actually want to use, like this:

Code:

mount -t cifs \\\\computer\\sharedirectory\\ /place/you/want/to/mount/it/
(If I recall correctly.)

--Dane

NOTE: The character mentioned in your original post, "/", is NOT a backslash. It is a forward slash (the one on the "?" key, on a QWERTY keyboard). A forward slash, "/", is used in Linux to denote directories, and is not an escape character, although it does have special meaning (namely to denote directories), and thus can BE escaped using a backslash, "\". You do not have to put more than one forward slash to denote a directory or sub-directory. Thus, the following is how to denote a directory/sub-directory:

Code:

cd /home/me/stuff/morestuff/
The slash at the far right is optional.

A backslash, "\", on the other hand, IS an escape character, and also has special meaning (which means that it can be escaped by another backslash). The backslash is on the same key as the pipe, "|", and is usually next to or under the BACKSPACE key.

In the examples above, corrected, "\ " is a literal space, "\[\]" are literal brackets, and "\\" is a literal backslash. A literal forward slash is written, simply, "/". (Examples taken from post #3 by David the H.)


All times are GMT -5. The time now is 06:25 PM.