{"id":525,"date":"2024-11-11T16:30:02","date_gmt":"2024-11-11T16:30:02","guid":{"rendered":"https:\/\/123webhostingindia.com\/tutorials\/?p=525"},"modified":"2024-11-11T16:30:04","modified_gmt":"2024-11-11T16:30:04","slug":"essential-ssh-commands","status":"publish","type":"post","link":"https:\/\/123webhostingindia.com\/tutorials\/essential-ssh-commands\/","title":{"rendered":"Essential SSH commands"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#h-1-ls-command\">1. ls Command<\/a><\/li><li><a href=\"#h-2-cd-command\">2. cd Command<\/a><\/li><li><a href=\"#h-3-mkdir-command\">3. mkdir Command<\/a><\/li><li><a href=\"#h-4-touch-command\">4. touch Command<\/a><\/li><li><a href=\"#h-5-rm-command\">5. rm Command<\/a><\/li><li><a href=\"#h-6-cat-command\">6. cat Command<\/a><\/li><li><a href=\"#h-7-pwd-command\">7. pwd Command<\/a><\/li><li><a href=\"#h-8-cp-command\">8. cp Command<\/a><\/li><li><a href=\"#h-9-mv-command\">9. mv Command<\/a><\/li><li><a href=\"#h-10-grep-command\">10. grep Command<\/a><\/li><li><a href=\"#h-11-find-command\">11. find Command<\/a><\/li><li><a href=\"#h-12-vi-nano-command\">12. vi\/nano Command<\/a><\/li><li><a href=\"#h-13-history-command\">13. history Command<\/a><\/li><li><a href=\"#h-14-clear-command\">14. clear Command<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"318\" height=\"159\" src=\"https:\/\/123webhostingindia.com\/tutorials\/wp-content\/uploads\/2024\/11\/SSH-commands.jpg\" alt=\"\" class=\"wp-image-526\" srcset=\"https:\/\/123webhostingindia.com\/tutorials\/wp-content\/uploads\/2024\/11\/SSH-commands.jpg 318w, https:\/\/123webhostingindia.com\/tutorials\/wp-content\/uploads\/2024\/11\/SSH-commands-300x150.jpg 300w\" sizes=\"auto, (max-width: 318px) 100vw, 318px\" \/><\/figure>\n\n\n\n<p>List of Basic SSH Commands:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-ls-command\">1. ls Command<\/h3>\n\n\n\n<p>This SSH command is used to list all files and directories. After entering&nbsp;<strong>ls<\/strong>, you will see an output that looks like this:<\/p>\n\n\n\n<p><strong><code>ls<\/code><\/strong>: Lists files and directories in the current directory.<\/p>\n\n\n\n<p>bashCopy code<code>ls           # Basic list\nls -l        # Detailed list with file permissions, sizes, etc.\nls -a        # Lists all files, including hidden ones<\/code><\/p>\n\n\n\n<p>There are also a few useful options that you can combine with it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-l<\/strong>\u00a0\u2014 \u00a0displays the details of the files, such as size, modified date and time, the owner, and the permissions.<\/li>\n\n\n\n<li><strong>-a<\/strong>\u00a0\u2014\u00a0 shows hidden files and directories.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-cd-command\">2. cd Command<\/h3>\n\n\n\n<p><strong>cd<\/strong>&nbsp;(Change Directory) is the command that we use to jump between directories. It\u2019s a pretty simple command \u2014 just type&nbsp;<strong>cd<\/strong>&nbsp;followed by the name of the directory:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd [directory]<\/pre>\n\n\n\n<p>As such, if you want to enter the home directory of your server, you can type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/home<\/pre>\n\n\n\n<p>You may also write the full path of a certain directory if it is a few levels deep. For instance:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/home\/TestDirectory\/AnotherDirectory<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/path\/to\/directory   # Navigate to a specific directory<br>cd ..                   # Go up one directory<br>cd ~                    # Go to the home directory<br><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-mkdir-command\">3. mkdir Command<\/h3>\n\n\n\n<p>You can use&nbsp;<strong>mkdir<\/strong>&nbsp;(Make Directory) command to create a directory. This is the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir [folder name]<\/pre>\n\n\n\n<p>Let\u2019s assume you want to create a new folder named \u201c<strong>myfolder<\/strong>\u201d. You will need to type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir myfolder<br>mkdir new_directory<br><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-touch-command\">4. touch Command<\/h3>\n\n\n\n<p>The\u00a0<strong>touch<\/strong>\u00a0is used in SSH commands to create a new file. Here is the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch [file name]<\/pre>\n\n\n\n<p>If you want to create a&nbsp;<strong>.txt<\/strong>&nbsp;file named \u201c<strong>myfile<\/strong>\u201d, this is what you need to write:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch myfile.txt.<\/pre>\n\n\n\n<p>The file extension could be anything you want. You can even create a file with no extension at all.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-rm-command\">5. rm Command<\/h3>\n\n\n\n<p><strong>rm<\/strong>\u00a0command\u00a0removes a chosen file or directory. To delete a file, enter:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm [file name]<\/pre>\n\n\n\n<p>For instance, if you want to remove&nbsp;<strong>myfile.txt<\/strong>, simply execute:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm myfile.txt<\/pre>\n\n\n\n<p>To delete a folder, you need to use the&nbsp;<strong>-r<\/strong>&nbsp;option to remove all the files and subfolders inside it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm -r home\/hosting\/myfolder<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-6-cat-command\">6. cat Command<\/h3>\n\n\n\n<p>We use\u00a0<strong>cat<\/strong>\u00a0command\u00a0to display the content of a file. Below is the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat [file name]<\/pre>\n\n\n\n<p>It also allows you to create a new file by merging multiple files. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat info.txt info2.txt &gt; mergedinfo.text<\/pre>\n\n\n\n<p>By executing this line, the content of&nbsp;<strong>info.txt<\/strong>&nbsp;and&nbsp;<strong>info2.txt<\/strong>&nbsp;will be saved into&nbsp;<strong>mergedinfo.txt<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-7-pwd-command\">7. pwd Command<\/h3>\n\n\n\n<p><strong>pwd<\/strong>&nbsp;is a simple command that outputs the full path of your working directory. Once entered, you should see a result like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">home\/user\/public_html<\/pre>\n\n\n\n<p><strong>pwd<\/strong>\u00a0command can come in really handy when you are accessing your site hosting account through SSH commands. Oftentimes, shared servers don\u2019t tell you the directory you are in.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-8-cp-command\">8. cp Command<\/h3>\n\n\n\n<p>This SSH command will copy files and folders. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp [options] [source] [destination]<\/pre>\n\n\n\n<p><strong>[source]<\/strong>&nbsp;is the file or folder you want to copy and&nbsp;<strong>[destination]<\/strong>&nbsp;is the duplicate.<\/p>\n\n\n\n<p>Let\u2019s say you have&nbsp;<strong>myfile.txt&nbsp;<\/strong>in your working directory, and you want to make a copy of it. The syntax would be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp myfile.txt myfile2.txt<\/pre>\n\n\n\n<p>If you want to make a copy in a different folder, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp \/home\/hosting\/myfile.txt \/home\/etc\/<\/pre>\n\n\n\n<p>Be careful when writing the name of the destination. If you provide two file names, the cp command will copy the content of the source file into the destination file. Thus, the destination file will be overwritten without any warning. However, if the destination file doesn\u2019t exist, then the command will create a new file.<\/p>\n\n\n\n<p><strong>[options]<\/strong>&nbsp;is not mandatory. However, there are several options that you can use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-f<\/strong>\u00a0\u2014 if you don\u2019t have writing permission to the destination file, it\u2019ll be deleted and the command will create a new file<\/li>\n\n\n\n<li><strong>-u<\/strong>\u00a0\u2014 copy the source file if it is newer than the destination file.<\/li>\n\n\n\n<li><strong>-n<\/strong>\u00a0\u2014 will not overwrite an existing file.<\/li>\n\n\n\n<li><strong>-a<\/strong>\u00a0\u2014 archive the files.<\/li>\n<\/ul>\n\n\n\n<p>Unlike duplicating files, copying folders requires you to use the<strong>&nbsp;-R&nbsp;<\/strong>(recursive) option. The option allows all folders and files inside it to be copied.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp -R \/home\/<a href=\"https:\/\/wordpress.com\/\" target=\"_blank\" rel=\"noopener\">hosting<\/a>\/myfolder \/home\/etc\/<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-9-mv-command\">9. mv Command<\/h3>\n\n\n\n<p>This SSH commands works similarly to\u00a0<strong>cp<\/strong>. However,\u00a0<strong>mv<\/strong>\u00a0command will move the file or folder instead of copying it. This is the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv [source] [destination]<\/pre>\n\n\n\n<p>Let\u2019s say we want to move\u00a0<strong>myfile.txt<\/strong>\u00a0from\u00a0<strong>\/home\/hosting\/ftp<\/strong>\u00a0to\u00a0<strong>\/home\/hosting\/myfolder\/<\/strong>. The command should be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv \/home\/hosting\/ftp\/myfile.txt \/home\/hosting\/myfolder<\/pre>\n\n\n\n<p>Unlike<strong>&nbsp;cp<\/strong>&nbsp;command, you don\u2019t need the&nbsp;<strong>-R<\/strong>&nbsp;option to move a folder. For instance:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv \/home\/hosting\/ftp\/ \/home\/hosting\/myfolder\/<\/pre>\n\n\n\n<p>This will automatically move all files and subfolders inside&nbsp;<strong>ftp<\/strong>&nbsp;to&nbsp;<strong>myfolder<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-10-grep-command\">10. grep Command<\/h3>\n\n\n\n<p><strong>grep<\/strong>\u00a0command\u00a0looks for a given string in files. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">grep 'line' info.txt<\/pre>\n\n\n\n<p>The above command would search for \u2018<strong>line<\/strong>\u2019 in a file named \u201c<strong>info.txt<\/strong>\u201d. What\u2019s great, the command will print the entire line that contains the matched text.<\/p>\n\n\n\n<p>Keep in mind that this command is case sensitive. If you want to ignore letter cases, use&nbsp;<strong>-i&nbsp;<\/strong>option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-11-find-command\">11. find Command<\/h3>\n\n\n\n<p>We enter\u00a0find SSH command\u00a0to search for a file or files that meet the given criteria (name, size, file type, etc). The following is the basic syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">find [starting directory] [options] [search term]<\/pre>\n\n\n\n<p><strong>[starting directory]<\/strong>&nbsp;is where you would like to start your search process. There are three main choices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\/<\/strong>\u00a0(slash) \u2014 search the whole system<\/li>\n\n\n\n<li><strong>.<\/strong>\u00a0(dot) \u2014 search the working directory<\/li>\n\n\n\n<li><strong>~<\/strong>\u00a0(tilde) \u2014 search the home directory<\/li>\n<\/ul>\n\n\n\n<p><strong>[options]<\/strong>&nbsp;is an additional argument that you can use to refine your search. Some of the most popular options are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>-name<\/strong>\u00a0\u2014 look for files based on their names<\/li>\n\n\n\n<li><strong>-user<\/strong>\u00a0\u2014 search for files that belong to a given user<\/li>\n\n\n\n<li><strong>-size<\/strong>\u00a0\u2014 look for files based on their sizes<\/li>\n<\/ul>\n\n\n\n<p><strong>[search term]<\/strong>&nbsp;is the keyword or number that you use to search for files.<\/p>\n\n\n\n<p>Take a look at this example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">find . -name \u201cindex\u201d<\/pre>\n\n\n\n<p>This command will return any files that have the word \u201c<strong>index<\/strong>\u201d on their names. And since we use \u201c<strong>.<\/strong>\u201d (dot), the command will only search the working directory.<\/p>\n\n\n\n<p>We also have a great\u00a0tutorial\u00a0that provides an in-depth explanation about this SSH commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-12-vi-nano-command\">12. vi\/nano Command<\/h3>\n\n\n\n<p><strong>Vi<\/strong>\u00a0and\u00a0<strong>Nano<\/strong>\u00a0are two popular text editors that you can use in the command line. To open a file using\u00a0<strong>Vi<\/strong>\u00a0or\u00a0<strong>Nano<\/strong>, you just need to enter:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi [file name]<\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nano [file name]<\/pre>\n\n\n\n<p>If the specified file doesn\u2019t exist, both text editors will automatically create it for you.<\/p>\n\n\n\n<p>Unfortunately, some Linux distributions don\u2019t offer Nano by default. Don\u2019t worry, you can read our guide on\u00a0how to install and use Nano.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-13-history-command\">13. history Command<\/h3>\n\n\n\n<p>This one is used to display the last used commands. You need to enter a number to limit the displayed results. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">history 20<\/pre>\n\n\n\n<p>As you probably guess, the example will show the 20 most recently entered commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-14-clear-command\">14. clear Command<\/h3>\n\n\n\n<p>The function of<strong>&nbsp;clear<\/strong>&nbsp;command is simple \u2014 it clears all text from the terminal screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>Learning SSH commands is crucial for managing Linux <a href=\"http:\/\/123webhostingindia.com\">server<\/a> or VPS. It is the most effective way to navigate through your system and modify files or folders.<\/p>\n\n\n\n<p>Thankfully, you have learned essential SSH commands that every webmaster should know. Now you can easily perform basic tasks on your remote machine, such as creating files, deleting them, jumping between directories, and so on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>List of Basic SSH Commands: 1. ls Command This SSH command is used to list all files and directories. After entering&nbsp;ls, you will see an output that looks like this:&#8230;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-525","post","type-post","status-publish","format-standard","hentry","category-ssh-commands"],"_links":{"self":[{"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/posts\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":1,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":527,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/posts\/525\/revisions\/527"}],"wp:attachment":[{"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/123webhostingindia.com\/tutorials\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}