The difference between the forward slash "/" and "\" in CentOS

Source: Internet
Author: User

The difference between the forward slash "/" and "\" in CentOS

Today, I found a file named "\" when checking the root directory. It was strange that I had never seen it before. I just wanted to open it with Vim. Naturally, I entered a command to check it, the result cannot be opened.

[Html] view plaincopyprint?
  1. [Root @ localhost ~] # Ll
  2. Total usage 48
  3. -Rw-r --. 1rootroot July 9 2015 \
  4. -Rw -------. 1rootroot1414 August 22: 51anaconw.ks.cfg
  5. -Rw-r --. 1rootroot30147 August 22: 51install. log
  6. -Rw-r --. 1rootroot780 August 22, June 30: 50install. log. syslog
  7. [Root @ localhost ~] # Vim \
  8. >

After thinking a little bit, you will understand that it is not impossible to open the file. The problem lies in the file name.

The backslash (\) is interpreted as an escape character in Bash to remove the special meaning of a single character. It retains the literal value of the character following it, except for the line break. If a newline character appears immediately after the backslash, The Escape Character enables the line to continue. If a command is used for a long time, the backslash is effective. The backslash is removed from the input stream and ignored effectively.

Example 1:

[Html] view plaincopyprint?
  1. [Root @ localhost ~] # Echo $ HOME
  2. /Root
  3. [Root @ localhost ~] # Echo \ $ HOME
  4. $ HOME

In this example, the backslash removes the special meaning of the "$" character and retains the nominal value, so that the home directory path is not output.


Example 2:

[Html] view plaincopyprint?
  1. [Root @ localhost ~] # Mvtest. c \
  2. > ..
  3. Mv: unable to get the file status (stat) of "test. c": No file or directory

In this example, the backslash enables the line to continue, and the command can be entered normally.

Now you can see how to view the document with the file name "\". Just enter the command

[Html] view plaincopyprint?
  1. [Root @ localhost ~] # Vim \\

This problem has been solved, but I think of the corresponding backslash. I also often use a symbol: forward slash ("/"). Let's take a look at the differences between the two symbols.

On zhihu, we can see that the Backslash "\" is a special Punctuation Point invented after the computer appears to express the special meaning in the program design. That is to say, in addition to the field of programming, there should be no backslash in any place, please always use the forward slash "/".

A rough idea is similar to this, but it immediately comes up with a wonderful idea: in Windows, the Backslash "\" is used to represent the directory, but in Linux, the forward slash "/" is used to represent the directory. It is estimated that many people have made this mistake when switching from Windows to Linux.

Windows:

"/" Indicates the parameter, and "\" indicates the local path.

Linux and Unix:

"/" Indicates the path, "\" indicates the escape, and "-" and "--" indicates the parameter.

Network:

Because the network uses the Unix standard, the network path uses "/".

But why does "/" be used for Windows only to show differences from Linux? Obviously not. The reasons for history are complicated, and the answer is also found.

In Windows, the backslash ("\") is used from DOS, while in DOS, another tradition is to use a slash ("/") to represent command line parameters. For example:

  Cd % SystemDrive %
Dir/s/B shell32.dll

Since the DOS slashes are occupied, we have to find the closest one. That's it. In UNIX, we use minus signs ("-") and double minus signs ("--") to represent the command line parameters.
Using a slash to indicate that the command line parameters are compatible. This problem was originally originated from IBM. IBM contributed a large number of tools when it first joined DOS development, all of which use slashes to process command line parameters. This tradition originated from DEC/IBM. For example, VMS used a slash to process command line parameters. Its Directory separator is the dollar sign ("$ "). By the way, this tradition has been partially inherited into the DOS and Windows systems, and the Japanese version of Windows displays the backslash as "¥" on the screen ", it is actually a backslash.
Currently, the Windows kernel supports both slash and backslash when processing the path. Most of the time we see an error when using a slash because of the application layer. For example, cmd.exe does not support the use of diagonal bars, while powershell.exe does. For this reason, PowerShell starts to use the minus sign as the start character of the command line parameter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.