Find the answer to your Linux question:
Results 1 to 4 of 4
What do these commands do Code: cd \ I get a > after entering this command and come out using cntrl+d and don't understand what it does the other one ...
  1. #1
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    cd \ and cd //

    What do these commands do
    Code:
    cd \
    I get a > after entering this command and come out using cntrl+d and don't understand what it does
    the other one is
    Code:
    cd  //
    This takes me to a dir // and i see the contents of the /
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  2. #2
    Linux Newbie raghaven.kumar's Avatar
    Join Date
    Mar 2008
    Location
    Bangalore, India
    Posts
    209
    Quote Originally Posted by vickey_20 View Post
    cd \
    Actuallty backslash is used override special char commands
    you can use them for files that contain special chars like *,@,! etc.
    you get > because its a linux feature wherein you can enter a long command, meaning the prompt waits for you enter command continuation.
    Quote Originally Posted by vickey_20 View Post
    cd //
    IMO, this is just a typo, linux ignores the second slash

  3. #3
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by vickey_20 View Post
    What do these commands do
    Code:
    cd \
    I get a > after entering this command and come out using cntrl+d and don't understand what it does
    \ scapes the next character so it's not interpreted by bash. In this case, it scape the carry return so, to bash, you haven't terminated the command, and it keeps asking for more.

    You could do

    Code:
    ls -l /my/dir
    Or you could do

    Code:
    ls \
    -l \
    /my/dir
    They are equivalent.


    the other one is
    Code:
    cd  //
    This takes me to a dir // and i see the contents of the /
    The number of slashes doesn't change the meaning of the command. ls / and ls ////////// are the same. This is a particularity that avoids a lot of trouble when concatenating directories.

    For example, imagine that a script has to concatenate a path and a file name. The path is contained in $DIR and the file name is contained in $FILE. Both need to be entered by the user, but the user can choose to enter "/my/path" or "/my/path/". Since you don't know beforehand, it's a tad convenient that you can join both in your script this way:

    Code:
    foo="$DIR/$FILENAME"
    If the user entered "/my/path", $foo will contain /my/path/my_file, if the user entered "/my/path//my_file", and both will be correct. This is used everywhere. If you examine the logs you can probably find lots of paths with more than one consecutive slash in the middle somewhere.

  4. #4
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    thanks now it is clear
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...