There are two ways to run .sh files under Linux systems. For example, I have a datelog.sh file in the root directory.
The first one ( This method requires chmod to make the file meet the execution conditions (x): chmod u x datelog.sh): (Recommended learning: linux operation and maintenance)
1. In any path Next, enter the absolute path of the file /root/datelog.sh to execute the file (of course, if permissions allow)
[root@ubitername ~]# /root/datelog.sh
2. cd to the directory of the datelog.sh file, and then execute. /datelog.sh
[root@ubitername ~]# cd /root [root@ubitername ~]# ./datelog.sh
The second method (this method does not require the file to have executable permissions to run):
1. Under the file path sh plus the file name, sh datelog.sh
[root@ubitername ~]# sh datelog.sh
2. In any path, sh plus the file path and file name: sh /root/ datelog.sh
[root@ubitername ~]# cd /etc [root@ubitername ~]# sh /root/ datelog.sh
The above is the detailed content of How to run .sh file in linux. For more information, please follow other related articles on the PHP Chinese website!