how to run a command on startup in linux ubuntu or centos 1

how to run a command on startup in linux ubuntu or centos

sudo nano /etc/rc.local   ## add your command 
 #!/bin/bash     ## add this in head file and your any command
 sudo chmod +x /etc/rc.local  ##for change accses file
 sudo init 6    ## for reboot 

Here is what the above code is Doing:
1. The first line is a shebang. It tells the system what program to use to run the script.
2. The second line is a comment. It’s ignored by the system.
3. The third line is a command. It tells the system to change the permissions on the file so that it can be executed.
4. The fourth line is a command. It tells the system to reboot.

Similar Posts