There was a problem loading the comments.

Basic SSH Commands

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

🖥️ Basic SSH Commands

Here is a list of essential SSH commands commonly used when working on a Linux server.

 

📂 File & Directory Commands

  • ls: List files/directories
  • ls -al: List all files with details, including hidden ones
  • cd /path: Change to a specific directory
  • cd ~: Go to home directory
  • cd -: Go to the previous directory
  • cd ..: Go up one directory
  • cat filename.txt: Print file contents
  • tail -f /var/log/messages: Continuously view log updates
  • more /etc/userdomains: View file one screen at a time
  • touch filename: Create an empty file
  • rm filename: Delete a file
  • rm -rf folder/: Delete folder and all contents (⚠️ dangerous!)
  • cp source target: Copy files
  • ln -s original linkname: Create a symbolic link

 

📝 Text Editors

  • pico file: Simple editor
  • vi file: Advanced editor (steep learning curve)

 

🔍 Searching & Monitoring

  • grep pattern file: Find text pattern in a file
  • grep -v pattern file: Exclude lines matching the pattern
  • w: Who is logged in and from where
  • last: Recent logins
  • netstat -an: Active network connections
  • Top: Live System Resource Monitor
  • ps aux: List all running processes
  • ps aux --forest: Hierarchical process list
  • kill -9 PID: Force terminate a process

 

💾 Disk & File Info

  • file *: Identify file types
  • du -sh: Total disk usage of the current directory
  • du -sh *: Disk usage by each item
  • wc -l file: Count lines in a file

 

🛠️ Combining Commands

  • command1 | command2: Pipe the output of one into another
  • command > file: Redirect output to file (overwrite)
  • command >> file: Append output to file
  • command < file: Use file as input

 

Examples:

grep User /usr/local/apache/conf/httpd.conf | more
last -a > /root/lastlogins.tmp
tail -10000 /var/log/exim_mainlog | grep domain.com | more
netstat -an | grep :80 | wc -l
mysqladmin processlist | wc -l
mysqldump -u username -ppassword dbname > file.sql
tar -zcvf archive.tar.gz directory/
tar -zxvf archive.tar.gz
mysql -uusername -ppassword database_name
  

 

⚠️ Note: Always double-check before running commands like rm -rf or kill -9 to avoid accidental damage.

 


Share via
Did you find this article useful?  

Related Articles


Comments

Add Comment

Replying to  


Self-Hosted Help Desk Software by SupportPal
© Indichosts.net