{"id":3501,"date":"2009-02-27T18:02:44","date_gmt":"2009-02-27T23:02:44","guid":{"rendered":"http:\/\/underhost.com\/blog\/?p=3501"},"modified":"2025-03-07T08:17:35","modified_gmt":"2025-03-07T13:17:35","slug":"common-ssh-commands-or-linux-shell-commands-old-version","status":"publish","type":"post","link":"https:\/\/underhost.com\/blog\/common-ssh-commands-or-linux-shell-commands-old-version\/","title":{"rendered":"Updated MARCH 2025: Essential SSH Commands for Linux Server Management"},"content":{"rendered":"<h2><strong>Basic SSH Commands for Linux<\/strong><\/h2>\n<h3><strong>1. File and Directory Management<\/strong><\/h3>\n<ul>\n<li><strong>ls<\/strong> &#8211; Lists files and directories.<\/li>\n<pre>ls -al<\/pre>\n<p>Shows all files, including hidden ones, with details.<\/p>\n<li><strong>cd<\/strong> &#8211; Changes directories.<\/li>\n<pre>cd \/usr\/local\/apache<\/pre>\n<p>Moves to the Apache directory.<\/p>\n<pre>cd ~<\/pre>\n<p>Moves to the home directory.<\/p>\n<pre>cd ..<\/pre>\n<p>Moves up one directory level.<\/p>\n<li><strong>cat<\/strong> &#8211; Displays file contents.<\/li>\n<pre>cat filename.txt<\/pre>\n<li><strong>more<\/strong> &#8211; Views file content one screen at a time.<\/li>\n<pre>more \/etc\/userdomains<\/pre>\n<\/ul>\n<h3><strong>2. File Permissions and Ownership<\/strong><\/h3>\n<ul>\n<li><strong>chmod<\/strong> &#8211; Changes file permissions.<\/li>\n<pre>chmod 644 index.html<\/pre>\n<p>Common permission for HTML files.<\/p>\n<pre>chmod 755 script.cgi<\/pre>\n<p>Common permission for CGI scripts.<\/p>\n<li><strong>chown<\/strong> &#8211; Changes file ownership.<\/li>\n<pre>chown root file.txt<\/pre>\n<p>Sets the owner to root.<\/p>\n<pre>chown user.group file.txt<\/pre>\n<p>Changes owner and group.<\/p>\n<\/ul>\n<h3><strong>3. File Manipulation<\/strong><\/h3>\n<ul>\n<li><strong>cp<\/strong> &#8211; Copies files.<\/li>\n<pre>cp file1.txt file1_backup.txt<\/pre>\n<li><strong>mv<\/strong> &#8211; Moves or renames files.<\/li>\n<pre>mv oldname.txt newname.txt<\/pre>\n<li><strong>rm<\/strong> &#8211; Deletes files.<\/li>\n<pre>rm -rf \/tmp<\/pre>\n<p><strong>Be careful<\/strong>: This deletes the entire directory recursively!<\/p>\n<li><strong>touch<\/strong> &#8211; Creates an empty file.<\/li>\n<pre>touch newfile.txt<\/pre>\n<\/ul>\n<h3><strong>4. Disk Usage and Monitoring<\/strong><\/h3>\n<ul>\n<li><strong>du<\/strong> &#8211; Shows disk usage.<\/li>\n<pre>du -sh<\/pre>\n<p>Summarizes total disk usage.<\/p>\n<li><strong>wc<\/strong> &#8211; Counts words, lines, characters.<\/li>\n<pre>wc -l filename.txt<\/pre>\n<p>Shows line count of a file.<\/p>\n<\/ul>\n<h3><strong>5. Process and System Monitoring<\/strong><\/h3>\n<ul>\n<li><strong>top<\/strong> &#8211; Displays real-time system processes.<\/li>\n<pre>top<\/pre>\n<pre>Shift + M<\/pre>\n<p>Sorts by memory usage.<\/p>\n<li><strong>ps<\/strong> &#8211; Lists running processes.<\/li>\n<pre>ps aux<\/pre>\n<li><strong>kill<\/strong> &#8211; Terminates processes.<\/li>\n<pre>kill -9 PID<\/pre>\n<p>Force-kills a process using its PID.<\/p>\n<li><strong>netstat<\/strong> &#8211; Shows network connections.<\/li>\n<pre>netstat -an<\/pre>\n<p>Displays active connections.<\/p>\n<\/ul>\n<h3><strong>6. User and Login Information<\/strong><\/h3>\n<ul>\n<li><strong>w<\/strong> &#8211; Shows currently logged-in users.<\/li>\n<pre>w<\/pre>\n<li><strong>who<\/strong> &#8211; Lists users connected to the server.<\/li>\n<pre>who<\/pre>\n<li><strong>last<\/strong> &#8211; Shows login history.<\/li>\n<pre>last -20<\/pre>\n<p>Displays the last 20 logins.<\/p>\n<\/ul>\n<h3><strong>7. Archiving and Compression<\/strong><\/h3>\n<ul>\n<li><strong>tar<\/strong> &#8211; Creates and extracts tar archives.<\/li>\n<pre>tar -zxvf file.tar.gz<\/pre>\n<p>Extracts a .tar.gz file.<\/p>\n<pre>tar -cf archive.tar directory\/<\/pre>\n<p>Creates an archive.<\/p>\n<li><strong>gzip<\/strong> &#8211; Compresses files.<\/li>\n<pre>gzip file.txt<\/pre>\n<p>Compresses file.txt into file.txt.gz.<\/p>\n<li><strong>unzip<\/strong> &#8211; Extracts .zip files.<\/li>\n<pre>unzip file.zip<\/pre>\n<\/ul>\n<h3><strong>8. Firewall and Security<\/strong><\/h3>\n<ul>\n<li><strong>iptables<\/strong> &#8211; Configures the firewall.<\/li>\n<pre>iptables -I INPUT -s 192.168.1.100 -j DROP<\/pre>\n<p>Blocks an IP.<\/p>\n<pre>iptables -L<\/pre>\n<p>Lists firewall rules.<\/p>\n<\/ul>\n<h3><strong>9. Web Server Commands<\/strong><\/h3>\n<ul>\n<li><strong>Apache Commands<\/strong><\/li>\n<pre>service httpd restart<\/pre>\n<p>Restarts Apache.<\/p>\n<pre>httpd -v<\/pre>\n<p>Displays Apache version.<\/p>\n<li><strong>MySQL Commands<\/strong><\/li>\n<pre>mysqladmin processlist<\/pre>\n<p>Shows active MySQL queries.<\/p>\n<pre>mysql -u user -p database < backup.sql<\/pre>\n<p>Restores a MySQL database.<\/p>\n<pre>mysqldump -u user -p database > backup.sql<\/pre>\n<p>Backs up a MySQL database.<\/p>\n<\/ul>\n<h3><strong>10. Advanced Shell Command Combinations<\/strong><\/h3>\n<ul>\n<li><strong>Piping Data<\/strong><\/li>\n<pre>grep User \/usr\/local\/apache\/conf\/httpd.conf | more<\/pre>\n<p>Filters results and displays them page-by-page.<\/p>\n<li><strong>Redirecting Output<\/strong><\/li>\n<pre>ls -al > directory_list.txt<\/pre>\n<p>Saves output to a file.<\/p>\n<pre>ls -al >> directory_list.txt<\/pre>\n<p>Appends output to an existing file.<\/p>\n<\/ul>\n<h2><strong>Need a Reliable Linux Server? Choose UnderHost!<\/strong><\/h2>\n<p>\nIf you're managing a Linux server, you'll need a robust hosting provider. <a href=\"https:\/\/underhost.com\/dedicated-servers-offshore.php\">UnderHost's dedicated servers<\/a> come with full root access, advanced security, and 24\/7 support. Whether you need <a href=\"https:\/\/underhost.com\/offshore-vps.php\">Offshore VPS<\/a> for privacy or high-speed <a href=\"https:\/\/underhost.com\/10gbps-dedicated-servers.php\">10Gbps Dedicated Servers<\/a>, we have you covered.\n<\/p>\n<p>Get expert support at <a href=\"https:\/\/customerpanel.ca\/client\">UnderHost Customer Panel<\/a> anytime.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Master Linux server management with this comprehensive list of SSH commands. From file navigation to system monitoring and MySQL operations, these commands will boost your efficiency.<\/p>\n","protected":false},"author":1,"featured_media":5015,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3501","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/comments?post=3501"}],"version-history":[{"count":3,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3501\/revisions"}],"predecessor-version":[{"id":5087,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3501\/revisions\/5087"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media\/5015"}],"wp:attachment":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media?parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/categories?post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/tags?post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}