How to solve the problem of command failure caused by overwriting the original PATH and prompting command not found

How to solve the problem of command failure caused by overwriting the original PATH and prompting command not found

A colleague asked me to help him figure out why many commands on his LINUX server could not be used, with the prompt (command not found). What was even worse was that many system services and scripts could not be run. Let me ask you, what have you done before? He said that I did the same operation, just added export PATH in the /etc/profile file, and asked, how did you set it? The answer is:

[root@localhost ~]# vim /etc/profile 
export PATH=/usr/lib/jenkins/
[root@localhost ~]# source /etc/profile

He said that he just added the default working directory of Jenkins and then used source to make the configuration file effective. In fact, this is exactly where the problem lies!

PATH is the system environment path. All system commands and script executions are searched according to the PATH path. But if export PATH=/usr/lib/jenkins/ , all the directories set by the system before, such as (/bin/; /sbin and other directories storing system commands), will be overwritten and become jenkins work commands. System commands such as ls, pwd, cd will definitely not be found in the jenkins directory. As a result, all commands, scripts, and services will not be able to run. This is the main reason for this bloody incident!

How to set the real system PATH?

If it is a short-term setting:

export PATH=$PATH:/usr/lib/jenkins/

If it is a long-term setting:

[root@localhost ~]# vim /etc/profile 
export PATH=$PATH:/usr/lib/jenkins/
[root@localhost ~]# source /etc/profile

In this case, the new search path is added to the original setting without overwriting the original PATH.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux uses join -a1 to merge two files
  • How to deal with the prompt "Operation not permitted" when deleting files in Linux
  • Linux shell command counts the value of a column after deduplication
  • Tips for viewing History records and adding timestamps in Linux
  • Several ways to run Python programs in the Linux background
  • Creating and executing Linux shell scripts
  • Python uses paramiko to operate Linux
  • Steps to transfer files and folders between two Linux servers
  • Android's implementation method of executing shell scripts in the Linux terminal to directly print the log of the currently running app
  • Use of Zabbix Api in Linux shell environment

<<:  Detailed explanation of CocosCreator Huarongdao digital puzzle

>>:  How to quickly delete all tables in MySQL without deleting the database

Recommend

How to build a drag and drop plugin using vue custom directives

We all know the drag-and-drop feature of HTML5, w...

JavaScript explains the encapsulation and use of slow-motion animation

Implementing process analysis (1) How to call rep...

How to let DOSBox automatically execute commands after startup

Using DOSBox, you can simulate DOS under Windows ...

Detailed explanation of the principles of Vue's responsive system

Table of contents The basic principles of Vue'...

How to install rabbitmq-server using yum on centos

Socat needs to be installed before installing rab...

How are Vue components parsed and rendered?

Preface This article will explain how Vue compone...

MySQL query method with multiple conditions

mysql query with multiple conditions Environment:...

Detailed explanation of Vue options

Table of contents 1. What are options? 2. What at...

Detailed explanation of how to select all child elements using CSS

How to recursively select all child elements usin...

How to solve the problem that Docker container has no vim command

Find the problem Today, when I tried to modify th...

Sample code for cool breathing effect using CSS3+JavaScript

A simple cool effect achieved with CSS3 animation...

Detailed explanation of NodeJS modularity

Table of contents 1. Introduction 2. Main text 2....