Master Linux Boot Autostart, Aliases, and Links with systemctl, alias, and ln
This guide explains how to configure Linux services to start on boot using systemd or rc.local, create permanent command aliases, and understand the differences between soft and hard links with practical examples and step‑by‑step commands.
Boot Autostart: systemd and rc.local
Linux starts services automatically through a built‑in mechanism. The modern approach is systemd , used by CentOS 7+, Ubuntu 16.04+, and Debian 8+. Enabling a service is a single command: systemctl enable nginx This creates a symbolic link in systemd’s configuration directory, marking the service to be started on the next boot. To disable: systemctl disable nginx Check status with: systemctl is-enabled nginx and view runtime state with: systemctl status nginx Note that enable does not start the service immediately; use systemctl start nginx or combine both with systemctl enable --now nginx.
The legacy method rc.local runs a script at boot. Create or edit /etc/rc.local, ensure it is executable ( chmod +x /etc/rc.local) and ends with exit 0. Modern distributions treat rc.local as compatibility mode, so systemd is preferred.
Custom systemd Service
To manage a custom script with systemd, create a unit file such as /etc/systemd/system/myservice.service:
[Unit]
Description=My Custom Service
After=network.target
[Service]
ExecStart=/usr/local/bin/myscript.sh
Restart=always
[Install]
WantedBy=multi-user.targetKey fields:
After=network.target – start after the network is ready.
Restart=always – automatically restart on failure.
WantedBy=multi-user.target – equivalent to the traditional multi‑user run level.
Reload the daemon and enable the service:
systemctl daemon-reload
systemctl enable --now myserviceAlias: Shortcuts for Long Commands
The alias builtin lets you assign a short name to a longer command. Basic syntax:
alias ll='ls -alh --color=auto'
alias grep='grep --color=auto'
alias vi='vim'
alias cls='clear'List current aliases with alias. To make an alias persistent, add it to ~/.bashrc and reload the file with source ~/.bashrc. Removing an alias uses unalias (e.g., unalias ll or unalias -a to clear all). Prefix a command with a backslash (e.g., \rm -rf /tmp/*) to bypass an alias.
ln: Soft Links vs Hard Links
Understanding ln requires the concept of an inode , the filesystem’s unique identifier for a file. The filename is merely a label pointing to an inode.
Soft (symbolic) links are created with -s: ln -s /var/log/nginx/access.log ./access A soft link is an independent file containing the target path. It can cross filesystem boundaries and link to directories, but becomes a “dead link” if the target is removed.
Hard links are created without -s: ln /etc/nginx/nginx.conf ./nginx.bak Hard links add another name to the same inode; they cannot span filesystems or point to directories. Deleting the original name does not remove the data as long as at least one hard link remains.
Practical Scenarios
Redirect a log directory to a larger disk with a soft link.
Switch Python versions by linking /usr/bin/python3 to the desired binary.
Backup a configuration file using a hard link before editing.
Summary
Systemd is the mainstream method for boot autostart; systemctl enable sets the flag, --now starts immediately. rc.local remains for legacy understanding. Aliases shorten repetitive commands; make them permanent via ~/.bashrc. Soft links ( ln -s) act like shortcuts with separate inodes, while hard links share the same inode and cannot cross filesystems. These three topics are frequent interview questions and daily operations tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Agent Super App
AI agent applications, installation, large-model testing, computer fundamentals, IT operations and maintenance exchange, network technology exchange, Linux learning
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
