Friday, December 13, 2024

Linux Admin Commands

Linux Admin Commands 


S/N Command Description
1 ssh -i ubuntu.pem ubuntu@192.168.20.201 Access via PEM file
2 zip -r httpdocs.zip httpdocs --exclude *.svn* --exclude *.git* Zip with exclude some files
3 find . -type d -exec chmod 775 {} \; Apply permission along subfolders excluding files
4 find . -type f -exec chmod 644 {} \; Apply permission along subfiles excluding folders
5 find . -name \*test.txt -type f -exec rm -f {} \; Delete all the matching files with the same name
6 find /home -type f -name "*.tar.gz" -exec du -sh {} \; Find and display size of tar.gz files
7 find . -type f -name "*.zip" -size +1G -exec du -sh {} \; Find zip files larger than 1GB
8 find . -name "*.tar.gz" -type f -mmin +15 -delete Delete files older than 15 minutes
9 find /var/log/apache2/ -name "*.gz" -mtime +5 -delete Delete files older than 5 days
10 find . -exec grep -Rnw 'India' {} \; Find a specific word in a file
11 scp ubuntu@ip/home/ubuntu/pagal /home/administrator Drag file from server
12 rsync -avzh --progress (file) ssh ubuntu@ip:/home/ubuntu Drop file in server
13 rsync -avzh --progress root@127.0.0.1:/root/html.tar.gz . Drag file from server
14 tar -xvf new.tar -C /home/administrator/Desktop/ Change extract location
15 mysqldump -u root -p database_name > database.sql MySQL dump
16 mysqldump -u root -p --all-databases > all.sql Dump all databases
17 mysql -u root -p database_name < database.sql MySQL restore
18 sudo update-rc.d atd disable Enable or disable a service in Ubuntu
19 find /home/USERNAME/public_html -type d -exec chmod 755 {} \; Set permissions for folders/directories
20 find /home/USERNAME/public_html -type f -exec chmod 644 {} \; Set permissions for files
21 traceroute 31.170.123.130 Check connectivity between source and destination
22 nslookup domain_name or ip_address Resolve IP to name and name to IP
23 0 9 * * * /usr/bin/find /home/ubuntu/database_backup -name "*.gz" -type f -mtime +10 -exec rm -f {} \; Delete files older than 10 days
24 telnet (ip_address) (port_no) Check if a port is open or closed
25 nmap -p port_no 100.100.7.32 Check if a specific port is open
26 nmap -sT 100.100.7.32 Check how many ports are open
27 gnome-open https://google.com Open a link in the browser
28 ss Display network socket-related information
29 sudo netstat -tulpn Show currently running open ports
30 passwd --delete user_name Delete a user's password
31 sudo ss -lptn 'sport = :5432' Check all process IDs for a specific port
32 whois IP_address Show hosting details
33 find $HOME -type d -name ".git" Find a specific folder path
34 wget https://example.com/db.sql Download a file from the server
35 sudo service --status-all Check All service status
36 sed -i -e 's/old-text/new-text/g' input.txt (g) is used when you want to replace multiple occurrences on the same line.
37 sed -i -e 's/old-text/new-text/' input.txt If you don't include the g, it will only replace the first occurrence.
38 sed -i '5s/old-text/new-text/' input.txt Change string with specific line number.
39 sed -i '/host/s/^#//g' input.txt To Uncomment.
40 sed -i '/2001/s/^/#/g' input.txt To Comment Out.
41 sudo sed -i '812s/max_file_uploads = 20/max_file_uploads = 200/' php.ini Update max_file_uploads value in php.ini.
42 grep 'max_file\|memory_limit' php.ini Grep one or more strings with \| symbol.
43 rm -rf -v !("filename1"|"filename2") To delete all files with the exception of filename1 and filename2.
44 arp Get the MAC address list.
45 arp-scan -l Get the MAC address list with system names like HP.
46 apt list --installed Check installed packages in Ubuntu.
47 Command in the comment Section, not posted here due to html syntax detaction Calculate load average.
48 ~/.local/share/Trash/files Terminal Trash location.
49 php --ini View PHP version and extensions.
50 password --delete user_name Delete user password.
51 http://tech2towards.tech/?nocache View site without cache (if existing code loading).
52 dpkg -l | grep mysql Check installed packages.
53 sudo deluser --remove-home itadministrator Delete user account with home directory.
54 load_avarage/no_of_cpu*100 (3.56/4*100) = 89% Calculate load average
55 sudo apt-get install glances Glances is a monitoring tool similar to TOP
56 dig google.com ANY dig is similar to nslookup but has advanced features
57 http://server_ip/~cpaneluser Open website without a domain name in a shared hosting server
58 sudo chmod --reference ram syam Apply the same permission of ram to the syam folder (applies only to directories, not recursively)
59 sudo chown --reference ram syam Change ownership of syam to match ram
60 apg -n 1 -MCLN -m 16 -s Generate a secure password using this command
61 dpkg -l *python2.7* Check installed software matching Python 2.7
62 umask Set default permissions for all files/directories
63 chattr +i file.txt Prevent even root user from deleting the file (+ for apply, - for remove)
64 lsattr file.txt Check if chattr is applied
65 grep -i -r "server_name" /etc/nginx/sites-available/ Search case-insensitively (-i) and recursively (-r)
66 /usr/sbin/mysqld --help --verbose View all MySQL details
67 https://www.sslforfree.com/ Install SSL in WHM/Cpanel for Linux or Windows
68 kill -9 PID Kill a process by PID
69 killall firefox Kill a process by name
70 ping www.google.com | while read pong; do echo "$(date): $pong"; done Ping with date and time
71 ping www.google.com | ts Ping with date and time (requires sudo apt install moreutils)
72 dig +short demo.example.com If you receive the CNAME value, it means the CNAME is updated
73 stress --cpu 8 --io 4 --vm 4 --vm-bytes 512M --timeout 10s Testing load on CPU and RAM
74 gzip -d linux.gz Extract .gz file in Linux
75 unzip linux.zip Extract file through unzip
76 /etc/apt/sources.list.d Remove unwanted source list
77 mkdir -p a/b/c/d/e/f Create multiple directories with an absolute path
78 mkdir -p a/b/c/d/e/f/{subhash,sachin} Create multiple directories in the same path
79 ls -R Folder View all content under "Folder" directory recursively
80 :%s/map/gap Replace string in vim editor
81 :%s/\$/#/g Replace special character like $ using "\
82 shutdown -r -f -t 00 Forcefully restart Windows (write in RUN)
83 shutdown -s -f -t 00 Forcefully shut down Windows (write in RUN)
84 appwiz.cpl Open Programs and Features on Windows
85 ncpa.cpl Open Network Connections on Windows
86 msconfig Access Windows 7 startup settings
87 dpkg --status apache2 View detailed info about the installed Apache2 package
88 last reboot See the last reboot log details
89 whereis openssl Locate the OpenSSL installation path
90 iotop, iostat, atop Show advanced process details
91 echo 'HISTTIMEFORMAT="%F %T "' >> ~/.bashrc Show history with date and time
92 sed 's/unix/linux/g' demofile.txt Replace a word in a file
93 du -sh .[^.]* Show all hidden files
94 ps -eo pmem,pcpu,pid,user,args | sort -k 1 -r | head -10 Find out which process is consuming the most CPU and RAM
95 export PS1="\u$" Make the terminal host display shorter
96 sudo sh -c 'apt update && apt install vim' Install multiple services with a single command
97 pkill -u user_name Kill all processes running under a specific user
98 who and w Show information about users currently logged in and their processes
99 pkill -9 -t pts/5 Kill remotely connected user terminal access (after using the w command)
100 cat /sys/block/sda/queue/rotational 1 for hard disks, 0 for SSDs
101 sudo apt-get install trash-cli Install Trash CLI with commands like trash-list and trash-restore
102 grep -Rnw '/home/ubuntu/Desktop' -e 'India' Find a specific word in files
103 grep --exclude=*.csv -Rnw '/home/ubuntu/Desktop' -e 'India' Exclude files while searching for a specific word
104 ssh root@10.10.3.4 'uptime' Execute commands without logging into the terminal
105 locate -b apple.txt Use locate as a reliable and better alternative to the find command
106 sudo adduser user_name sudo Make a user an administrator in Ubuntu via CLI
107 cat /etc/resolv.conf Check name server configuration in Linux
108 nmtui/nmcli connection show Configure IP addresses via CMD
109 runuser -l User-Name -c 'command' Run a command as a specific user
110 csf -g | grep 8000 Check port input/output rules in WHM
111 for user in $(getent passwd | cut -f1 -d: ); do echo $user; crontab -u $user -l; done Get all cron jobs for all users on the server
112 touch /home/ubuntu/demofile:`date '+%d-%m-%y_%H:%M:%S'` Create a file with the current date and time
113 sudo apt-get install lamp-server^ -y Install Lamp Server
114 find /etc -xdev -type f -printf '\n' | wc -l Count all the files in the directory
115 mtr -r -c 100 125.63.73.83 MTR is a network diagnostic tool combining traceroute and ping functionality
116 ./nikto.pl -h https://tech2towards.com/ Nikto web server scanner
117 dig +short myip.opendns.com @resolver1.opendns.com Get public IP address via Linux CLI
118 mysqladmin -u root -p status Get MySQL status, including slow queries
119 * * * * * /usr/bin/bash /home/sh.sh >> /var/log/script.log 2>&1 Save script logs to a specific file
120 curl http://checkip.amazonaws.com/ Get public IP address
121 curl -ISL https://example.com/ Get link information, including server type
122 figlet Create ASCII art from text
123 https://example.com/?nocache=12345 Open URL without cache (replace "12345" with a random string)
124 du -sh .??* Display the total size of all hidden directories
125 sudo apt-cache depends nginx Check package dependencies
126 SOURCE /path/to/your/file.sql; Import a MySQL SQL file from within MySQL

1 comment:

  1. 47) cat /proc/loadavg | cut -c 1-4 | echo "scale=2; ($( Calculate loadavarage

    ReplyDelete

testing