What to do if the linux file cannot be found

藏色散人
Release: 2019-11-16 09:15:10
Original
8127 people have browsed it

What to do if the linux file cannot be found

What should I do if the Linux file cannot be found?

When you execute an existing shell script file under a Linux system, you will be prompted that the file does not exist during execution.

The general reason at this time is that the system when you write the shell script is inconsistent with the system where you execute the script. For example, if you write a script in a window system, you will encounter this problem when you copy it to a Linux system. The reason is that the format of the .sh file edited under windows is dos format, while linux can only execute scripts in unix format.

Because pressing the Enter key once under dos/window actually inputs "carriage return (CR)" and "line feed (LF)", while pressing the enter key once under Linux/unix only inputs " Line feed (LF)", so the modified sh file will have an extra CR in each line, so when running under Linux, an error will be reported that the command cannot be found.

In addition, when you use the windows system to download the source file on github that contains a shell script file, this problem may also occur when you decompress and copy it to the Linux system for execution.

Recommended: "linux tutorial"

Solution:

We can edit through vi tool to view the format of the file. The steps are as follows:

1. First use the vi command to open the file

[root@localhost test]# vi test.sh

2. Use: set in vi command mode ff command

can see that the file format is

fileformat=dos

3. Modify the file format to unix

Use vi/vim to modify the file format

Command: :set ff=unix

Or: :set fileformat=unix

Then: wq save and exit, re-execute the script and it will be normal

The above is the detailed content of What to do if the linux file cannot be found. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template