Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The /etc/rc.d/rc.local
file is a shell script in some Linux systems, particularly those using System V-style init or a hybrid system like SysVinit in combination with systemd
. This script is executed at the end of the boot process after all other init scripts have run. It is used for customizing the system startup by adding custom commands or scripts that should be executed at boot time. Note that many modern Linux distributions with systemd
have replaced this mechanism with systemd units and services.
Here's a tutorial on the /etc/rc.d/rc.local
file:
Check if the file exists:
Before working with the rc.local
file, make sure it exists on your system:
ls /etc/rc.d/rc.local
If the file does not exist, you may create it and make it executable:
sudo touch /etc/rc.d/rc.local sudo chmod +x /etc/rc.d/rc.local
Edit the /etc/rc.d/rc.local
file:
Open the rc.local
file with your preferred text editor as the root user:
sudo nano /etc/rc.d/rc.local
or
sudo vim /etc/rc.d/rc.local
Add custom commands or scripts:
Add your custom commands or scripts to the file, making sure to include the full path to any external scripts. For example, to run a script called myscript.sh
from the /root/scripts
directory at startup, add the following line to the rc.local
file:
/root/scripts/myscript.sh
Remember to include the shebang line #!/bin/sh
at the beginning of the rc.local
file, if it is not already present:
#!/bin/sh
Save and exit the editor.
Test your changes:
After editing the rc.local
file, you can either reboot your system to test your changes or manually execute the rc.local
script:
sudo /etc/rc.d/rc.local
Check that your custom commands or scripts are running as expected.
By understanding the purpose and usage of the /etc/rc.d/rc.local
file, you can effectively customize your Linux system's startup behavior. Remember that modern Linux distributions with systemd
may have replaced the rc.local
mechanism with systemd units and services, so this tutorial may not be applicable to the latest systems.
Configuring /etc/rc.d/rc.local in Linux:
The /etc/rc.d/rc.local
file in Linux is a script executed during the system boot process. To configure it:
sudo nano /etc/rc.d/rc.local
Customize the file to include the desired startup tasks.
Adding custom scripts to /etc/rc.d/rc.local:
Add custom scripts to /etc/rc.d/rc.local
by appending the desired commands. For example:
# Add custom script /path/to/custom_script.sh
Executing commands on system boot with rc.local:
Commands in /etc/rc.d/rc.local
are executed during system boot. For example, to start a service:
systemctl start your_service
Troubleshooting rc.local execution issues:
If commands in rc.local
are not executing, check for syntax errors, file permissions, and ensure that rc.local
is marked as executable:
sudo chmod +x /etc/rc.d/rc.local
Viewing default settings in rc.local file:
View the default contents of /etc/rc.d/rc.local
:
cat /etc/rc.d/rc.local
This may vary depending on the Linux distribution.