{"id":660,"date":"2021-07-23T12:35:00","date_gmt":"2021-07-23T12:35:00","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/getting-started-with-linux-commands\/"},"modified":"2021-07-23T12:35:00","modified_gmt":"2021-07-23T12:35:00","slug":"getting-started-with-linux-commands","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/getting-started-with-linux-commands\/","title":{"rendered":"Getting Started with Linux Commands"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<p>While cPanel &#038; WHM automates many server administration tasks, familiarity with the Linux\u00ae command line interface (CLI) can prove useful for both WHM and cPanel users. This documentation gives a brief overview of some basic Linux commands that you may wish to use as you manage your website or server.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>For steps to access the command line, read our How to Access the Command Line documentation.<\/p>\n<\/p><\/div>\n<\/div>\n<h2 id=\"common-linux-commands\">Common Linux commands<\/h2>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>To execute a command, enter the command with any required options and press <kbd>Enter<\/kbd>.<\/li>\n<li>In the following examples, replace <code>FILENAME<\/code> with the relative path to the file.<\/li>\n<\/ul><\/div>\n<\/div>\n<p>The following lists some basic Linux commands and their functions:<\/p>\n<table>\n<thead>\n<tr>\n<th>\n<div style=\"width:220px\">Command<\/div>\n<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>cat FILENAME<\/code><\/td>\n<td>Print the contents of the specified file to the CLI.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">cat filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>cat \/dev\/vcs1<\/code><\/td>\n<td>View the data that currently displays on your server\u2019s console screen.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">cat \/dev\/vcs1<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>cd LOCATION<\/code><\/td>\n<td>Navigate between directories. Replace <code>LOCATION<\/code> with the path to the directory that you wish to navigate to.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">cd \/usr\/local\/apache\/<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>chmod permissions FILENAME<\/code><\/td>\n<td>Change a file\u2019s octal permissions. For more information, read Wikipedia\u2019s <code>chmod<\/code> command article.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">chmod <span style=\"color:#ae81ff\">755<\/span> myfile.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>chown USER:GROUP FILENAME<\/code><\/td>\n<td>Change a file\u2019s user and group ownership. Replace <code>USER<\/code> with the user to whom you wish to grant ownership of the file, <code>GROUP<\/code> with the group name, and <code>FILENAME<\/code> with the relative path to the file.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">chown user:usersgroup usersfile.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>cp FILE1 FILE2<\/code><\/td>\n<td>Copy a file (<code>FILE1<\/code>) into a new file (<code>FILE2<\/code>).<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">cp original.txt \/copies\/duplicate.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>du<\/code><\/td>\n<td>Show the system\u2019s current disk usage for each directory and subdirectory.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">du<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>file FILENAME<\/code><\/td>\n<td>Guess a file\u2019s type, based on the file\u2019s contents.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">file filename<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>grep string FILENAME<\/code><\/td>\n<td>Search for a string in a specified file and print each line that contains a match to the CLI. Replace <code>string<\/code> with a single word, or multiple words within single quotes (<code>''<\/code>).<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">grep <span style=\"color:#e6db74\">'thisis anexample'<\/span> filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>last<\/code><\/td>\n<td>List which users recently logged in and the timestamp for each login.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">last<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>ln -s file1 file2<\/code><\/td>\n<td>Create a symbolic link between the two specified files. Replace <code>file1<\/code> with the relative path to the existing file, and <code>file2<\/code> with the relative path to the new symbolic link file.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">ln -s \/pointtome\/file1.txt symlink-file2.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>ls<\/code><\/td>\n<td>List files and directories that exist within your current directory. This command resembles the <code>dir<\/code> command in Windows\u00ae.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">ls<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>ls -al<\/code><\/td>\n<td>View dotfiles (filenames that begin with a period) and additional file and directory details.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">ls -al<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>more FILENAME<\/code><\/td>\n<td>Print the contents of a file to the CLI, one screen at a time.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">more filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>netstat<\/code><\/td>\n<td>List all of the server\u2019s current network connections.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">netstat<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>pico FILENAME<\/code><\/td>\n<td>Open the specified file in the pico text editor.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">pico filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>ps<\/code><\/td>\n<td>Return information about the server\u2019s current processes. <\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n        To view all of the running processes add the <code>-auxww<\/code> or <code>-cef<\/code> option to this command.\n    <\/div>\n<\/div>\n<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">ps<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>rm FILENAME<\/code><\/td>\n<td>Delete the specified file. After you run this command, the system prompts you to confirm the file\u2019s deletion.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">rm trash.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>tail -## FILENAME<\/code><\/td>\n<td>Print the last lines of a file to the CLI, where <code>##<\/code> represents the number of lines to print.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">tail -20 filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>touch FILENAME<\/code><\/td>\n<td>Create an empty file in the specified location.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">touch example.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>vi FILENAME<\/code><\/td>\n<td>Open the specified file in the vi text editor.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">vi filename.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>w<\/code><\/td>\n<td>List currently logged-in users and the location from which they logged in.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">w<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>wc FILENAME<\/code><\/td>\n<td>Display the word count for a specific file.<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">wc example.txt<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>whereis NAME<\/code><\/td>\n<td>Query applications that match the <code>NAME<\/code> value. You can find the most common applications in the following locations: <\/p>\n<ul>\n<li><code>\/usr\/sbin\/sendmail<\/code><\/li>\n<li><code>\/usr\/bin\/perl<\/code><\/li>\n<li><code>\/bin\/mail<\/code><\/li>\n<li><code>\/usr\/bin\/php<\/code><\/li>\n<\/ul>\n<\/td>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-BASH\" data-lang=\"BASH\">whereis perl<\/code><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"run-multiple-commands-on-the-same-line\">Run multiple commands on the same line<\/h3>\n<p>Various command-line tasks may require that you use different commands on the same line. Linux includes easy methods to perform these tasks:<\/p>\n<ul>\n<li>Use the pipe character (<code>|<\/code>) to retrieve data from one program and \u201cpipe\u201d it to another program.<\/li>\n<li>Use a single greater-than bracket (<code>&gt;<\/code>) to create a new file if the file does not already exist, or to overwrite any existing content if the file does exist.<\/li>\n<li>Use a double greater-than bracket (<code>&gt;&gt;<\/code>) to create a new file if the file does not already exist, or to append the new data to the file if the file does exist.<\/li>\n<li>Use a single less-than bracket (<code>&lt;<\/code>) to send input from a file to a command.<\/li>\n<\/ul>\n<p>The following are examples of how to combine tasks into a single command:<\/p>\n<table>\n<thead>\n<tr>\n<th>Command<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">grep User \/usr\/local\/apache\/conf\/httpd.conf | more<\/code><\/pre>\n<\/div>\n<\/td>\n<td>This command searches for all of the lines in the <code>httpd.conf<\/code> file that match the <code>User<\/code> search term, and then prints the results to your terminal one screen at a time.<\/td>\n<\/tr>\n<tr>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">last -a &gt; \/root\/lastlogins.tmp<\/code><\/pre>\n<\/div>\n<\/td>\n<td>This command prints all of the current login history to the <code>\/root\/lastlogins.tmp<\/code> file.<\/td>\n<\/tr>\n<tr>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">mysql --skip-column-names --batch -e <span style=\"color:#e6db74\">'show processlist'<\/span> | wc -l<\/code><\/pre>\n<\/div>\n<\/td>\n<td>This command lists the number of MySQL\u00ae threads. If subselect expressions start new threads, the output of the show <code>processlist<\/code> command includes them.<\/td>\n<\/tr>\n<tr>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">netstat -an | grep :80 | wc -l<\/code><\/pre>\n<\/div>\n<\/td>\n<td>This command shows the number of active connections to Apache\u00ae. Apache\u2019s <code>httpd<\/code> daemon runs on port <code>80<\/code>.<\/td>\n<\/tr>\n<tr>\n<td>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-bash\" data-lang=\"bash\">tail -10000 \/var\/log\/exim_mainlog | grep <span style=\"color:#e6db74\">'example.com'<\/span> | more<\/code><\/pre>\n<\/div>\n<\/td>\n<td>This command finds the last 10,000 lines from the <code>\/var\/log\/exim_mainlog<\/code> file, searches those lines for all occurrences of the string <code>example.com<\/code>, and then prints the search results to your terminal one screen at a time. <\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n        The system treats periods (<code>.<\/code>) in a command as wildcard characters. Precede each period with a backslash (<code><\/code>) to instruct grep to interpret the period literally.\n    <\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"common-configuration-files-and-directories\">Common configuration files and directories<\/h2>\n<p>You can find common configuration files and directories in the following locations on your server:<\/p>\n<table>\n<thead>\n<tr>\n<th>Service<\/th>\n<th>Locations<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Exim<\/td>\n<td>\n<ul>\n<li><code>\/etc\/exim.conf<\/code> <\/li>\n<li> <code>\/var\/log\/exim_mainlog<\/code> <\/li>\n<li> <code>\/var\/log\/exim_rejectlog<\/code> <\/li>\n<li> <code>\/etc\/valiases\/<\/code> <\/li>\n<li> <code>\/etc\/vfilters\/<\/code> <\/li>\n<li> <code>\/home\/username\/.forward<\/code><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>MySQL<\/td>\n<td>\n<ul>\n<li><code>\/root\/.my.cnf<\/code> <\/li>\n<li> <code>\/etc\/my.cnf<\/code> <\/li>\n<li> <code>\/var\/lib\/mysql\/<\/code><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>ProFTPD<\/td>\n<td>\n<ul>\n<li><code>\/etc\/proftpd.conf<\/code> <\/li>\n<li> <code>\/var\/log\/xferlog<\/code> <\/li>\n<li> <code>\/etc\/proftpd\/<\/code><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>SSH<\/td>\n<td><code>\/etc\/ssh\/sshd_config<\/code><\/td>\n<\/tr>\n<tr>\n<td>System<\/td>\n<td>\n<ul>\n<li><code>\/var\/log\/messages<\/code> <\/li>\n<li> <code>\/var\/log\/dmesg<\/code><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview While cPanel &#038; WHM automates many server administration tasks, familiarity with the Linux\u00ae command line interface (CLI) can prove useful for both WHM and cPanel users. This documentation gives a brief overview of some basic Linux commands that you may wish to use as you manage your website or server. Note: For steps to &hellip;<\/p>\n","protected":false},"author":1,"featured_media":661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/660"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/661"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}