Common Linux System Administration Commands and Scripts: Installation, Removal, Networking, MySQL, and Shell Examples
This article provides a collection of practical Linux and Windows system‑administration Q&A, covering software installation and removal, remote connection tools, IP and hostname configuration, backup scripts, iptables rules, MySQL security and replication, network utilities, and various shell command examples.
1. Common methods for installing and uninstalling software on Linux. A. rpm package removal: rpm -e XXX.rpm (add --nodeps to ignore dependencies). B. yum remove xxx.rpm (not recommended because it may remove dependent packages). C. Source package removal: navigate to the installation directory and run make uninstall or simply delete the directory.
2. Frequently used remote connection tools for Windows and Linux. Command‑line tools: Xshell, SecureCRT, PuTTY, SSH Secure Shell Client. Graphical tools: Xmanager (requires service configuration and port 177), VNC‑Viewer (install vncserver on Linux), Windows Remote Desktop (requires xrdp and VNC on Linux).
3. How to modify Linux IP address, gateway, and hostname. A. Edit /etc/sysconfig/network-scripts/ifcfg-eth0, set IPADDR=192.168.1.100 and GATEWAY=192.168.1.1, ensure BOOTPROTO=static. B. Edit /etc/sysconfig/network and change HOSTNAME (e.g., HOSTNAME=mysql).
4. Shell script to back up /var/mylog daily at 5 AM, compress it, and upload to a remote FTP server.
#/root/mylogbak.sh
#!/bin/bash
# scripts for dir backup and upload to ftp server.
# author by haojiu
bakdir=mylog
date=`date +%F`
cd /var
tar zcf ${bakdir}_${date}.tar.gz ${bakdir}
sleep 1
ftp -n <<-EOF
open 192.168.142.129 # remote ftp server IP
user aaa bbb
put mylog_*.tar.gz
bye
EOF
rm -rf mylog_*.tar.gz # optionally remove after successful uploadAdd to crontab:
crontab -l
00 05 * * * /bin/bash /root/mylogbak.sh # run daily at 5 AM5. Common iptables commands (example to allow HTTP from a specific host). iptables -A INPUT -p tcp -s 192.168.1.2 --dport 80 -j ACCEPT 6. Enhancing MySQL security after a fresh installation. A. Change the default port. B. Use iptables to restrict access to the MySQL port. C. Set strong passwords and bind accounts to specific IPs. D. Harden the root account (strong password, local‑only login). E. Enable binary and slow query logs. F. Set proper directory permissions for the MySQL installation and data directories. G. Remove unused accounts and databases (e.g., the default test database).
7. MySQL master‑slave replication principle and configuration steps. A. Master writes changes to the binary log. B. Slave copies binary log events to its relay log. C. Slave replays the relay log to apply changes. Detailed steps include establishing IO and SQL threads, recording bin‑log file names and positions, and ensuring data consistency.
8. Adding a MySQL user with limited privileges. Example:
grant select,insert,update,delete on book.* to test2@localhost identified by "abc";9. Display all directories under /test using four different commands.
ls -d */ find . -type d -maxdepth 1 ls -F | grep '/$' ls -l | grep '^d' | awk '{print $9}'10. Compress all files in /etc/a except b into /home/a/a.gz . tar --exclude /etc/a/b -zPcvf /home/a/a.gz /etc/a 11. Grant execution permission to a script. chmod +x a.sh 12. Meaning of umask 022 . It sets default file creation permissions to 755 for directories and 644 for files (subtracting 022 from the base 777/666).
13. View all files opened by a specific process. Obtain the PID (e.g., ps -ef | grep crond | awk '{print $2}') and run lsof -p PID.
14. Capture packets on eth0 port 80. tcpdump -i eth0 port 80 15. Delete all files and directories under /a/b . rm -rf /a/b/* 16. Common network management tools. Windows: ipconfig, ping, tracert, nslookup. Linux: ifconfig, ping, traceroute, dig, nslookup.
17. Standard service ports. FTP (20/21), HTTPS (443), SMTP (25), POP3 (110), SSH (22).
18. Enable PAE on Windows Server 2003/2008 to support 3‑4 GB memory. Add /PAE to the last line of boot.ini and reboot.
19. Shell script to create a group class and users std01 ‑ std30 belonging to that group.
# adduser.sh
#!/bin/bash
# script for adduser.
groupadd class
user=std
for i in {01..30}
do
useradd -G class ${user}$i
done20. Show all current MySQL connections. show full processlist; 21. Delete old MySQL binary logs. Set expire-logs-days=7 in my.cnf and restart MySQL, or run PURGE BINARY LOGS TO 'mysql-bin.000003'; to remove logs before the specified file.
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.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
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.
