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

10 very good CSS skills collection and sharing

Here, clever use of CSS techniques allows you to g...

Implementation of MySQL master-slave status check

1. Check the synchronization status of A and B da...

Server concurrency estimation formula and calculation method

Recently, I need to stress test the server again....

Vue+Openlayer uses modify to modify the complete code of the element

Vue+Openlayer uses modify to modify elements. The...

Quickly install MySQL5.7 compressed package on Windows

This article shares with you how to install the M...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

VMware ESXi 5.5 deployment and configuration diagram process

Table of contents 1. Installation requirements 2....

Raspberry Pi msmtp and mutt installation and configuration tutorial

1. Install mutt sudo apt-get install mutt 2. Inst...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

A brief discussion on logic extraction and field display of Vue3 in projects

Table of contents Logical Layering Separate busin...

MySQL log settings and viewing methods

MySQL has the following logs: Error log: -log-err...

How to use js to communicate between two html windows

Scenario: When page A opens page B, after operati...

Nginx implements dynamic and static separation example explanation

In order to speed up the parsing of the website, ...

Let's talk about the characteristics and isolation levels of MySQL transactions

The Internet is already saturated with articles o...