Basic SSH Commands for Linux
1. File and Directory Management
- ls – Lists files and directories.
ls -al
Shows all files, including hidden ones, with details.
cd /usr/local/apache
Moves to the Apache directory.
cd ~
Moves to the home directory.
cd ..
Moves up one directory level.
cat filename.txt
more /etc/userdomains
2. File Permissions and Ownership
- chmod – Changes file permissions.
chmod 644 index.html
Common permission for HTML files.
chmod 755 script.cgi
Common permission for CGI scripts.
chown root file.txt
Sets the owner to root.
chown user.group file.txt
Changes owner and group.
3. File Manipulation
- cp – Copies files.
cp file1.txt file1_backup.txt
mv oldname.txt newname.txt
rm -rf /tmp
Be careful: This deletes the entire directory recursively!
touch newfile.txt
4. Disk Usage and Monitoring
- du – Shows disk usage.
du -sh
Summarizes total disk usage.
wc -l filename.txt
Shows line count of a file.
5. Process and System Monitoring
- top – Displays real-time system processes.
top
Shift + M
Sorts by memory usage.
ps aux
kill -9 PID
Force-kills a process using its PID.
netstat -an
Displays active connections.
6. User and Login Information
- w – Shows currently logged-in users.
w
who
last -20
Displays the last 20 logins.
7. Archiving and Compression
- tar – Creates and extracts tar archives.
tar -zxvf file.tar.gz
Extracts a .tar.gz file.
tar -cf archive.tar directory/
Creates an archive.
gzip file.txt
Compresses file.txt into file.txt.gz.
unzip file.zip
8. Firewall and Security
- iptables – Configures the firewall.
iptables -I INPUT -s 192.168.1.100 -j DROP
Blocks an IP.
iptables -L
Lists firewall rules.
9. Web Server Commands
- Apache Commands
service httpd restart
Restarts Apache.
httpd -v
Displays Apache version.
mysqladmin processlist
Shows active MySQL queries.
mysql -u user -p database < backup.sql
Restores a MySQL database.
mysqldump -u user -p database > backup.sql
Backs up a MySQL database.
10. Advanced Shell Command Combinations
- Piping Data
grep User /usr/local/apache/conf/httpd.conf | more
Filters results and displays them page-by-page.
ls -al > directory_list.txt
Saves output to a file.
ls -al >> directory_list.txt
Appends output to an existing file.
Need a Reliable Linux Server? Choose UnderHost!
If you're managing a Linux server, you'll need a robust hosting provider. UnderHost's dedicated servers come with full root access, advanced security, and 24/7 support. Whether you need Offshore VPS for privacy or high-speed 10Gbps Dedicated Servers, we have you covered.
Get expert support at UnderHost Customer Panel anytime.