# Common Commands

##### **Help Commands**

<table border="1" id="bkmrk-%C2%A0" style="border-collapse: collapse; width: 100%; height: 710.4px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**  
</td><td>**Description**  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">compgen -c</td><td style="height: 29.6px;">Show all commands  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">compgen -a</td><td style="height: 29.6px;">Show all alias commands  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">compgen -A function</td><td style="height: 29.6px;">Show available functions  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">man &lt;command&gt;  
</td><td style="height: 29.6px;">Show manual page of a command (more info than --help)  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">&lt;command&gt; --help  
</td><td style="height: 29.6px;">Show help page of a command (less info than man command)  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">&lt;command&gt; --version  
</td><td style="height: 29.6px;">Show version of a command  
</td></tr></tbody></table>

##### **File &amp; Folder Commands**

<table border="1" id="bkmrk-modify-files-%26-folde" style="border-collapse: collapse; width: 100%; height: 769.6px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">ls -lah  
</td><td style="height: 29.6px;">List files/folders in current directory (+infos)  
</td></tr><tr><td>mkdir newdir  
</td><td>Create a new folder  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">cd somefolder  
</td><td style="height: 29.6px;">Change/switch to another directory  
</td></tr><tr><td>cd /mnt/</td><td>change/switch to another drive</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">cp file.txt file-copy.txt  
</td><td style="height: 29.6px;">Copy a file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">mv file.txt file-renamed.txt  
</td><td style="height: 29.6px;">Rename a file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">mv file.txt /tmp  
</td><td style="height: 29.6px;">Move file to another folder  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">rm file.txt  
</td><td style="height: 29.6px;">Remove a file  
</td></tr><tr><td>rm -rf folder  
</td><td>Remove entire folder (recursive)  
</td></tr><tr><td>ln -s original target  
</td><td>Create a symlink  
</td></tr><tr><td style="height: 29.6px;">pwd  
</td><td style="height: 29.6px;">Show path of current folder  
</td></tr><tr><td>chown &lt;arguments&gt; &lt;user&gt;:&lt;group&gt; file.txt</td><td>Change Owner and Group of file (use -R for rekursive)

</td></tr></tbody></table>

##### **Search &amp; String Commands**

<table border="1" id="bkmrk-search-%26-string-comm" style="border-collapse: collapse; width: 100%; height: 710.4px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">find . -name "file.txt"  
</td><td style="height: 29.6px;">Search for a file (recursive)  
</td></tr><tr><td>find . -name "\*.txt"  
</td><td>Search for all txt files  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">grep -rin "search string"  
</td><td style="height: 29.6px;">Search for a string in current folder (recursive)  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">grep -rin "search string" | cut -c 1-100  
</td><td style="height: 29.6px;">Search for a string in current folder + limit output of string  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">sed -Ei 's/someString/newString/g' file.txt  
</td><td style="height: 29.6px;">Replace "someString" with "newString" in a file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">head file.txt  
</td><td style="height: 29.6px;">Show first 10 lines of file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">tail file.txt  
</td><td style="height: 29.6px;">Show last 10 lines of file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">cat file.txt  
</td><td style="height: 29.6px;">Show full content of file  
</td></tr><tr><td>cat file.txt | grep "search string"  
</td><td>Pipe output of "cat" command to grep + filter string  
</td></tr></tbody></table>

##### **Terminal Search, Shortcuts &amp; Autocompletion**

<table border="1" id="bkmrk-command-description-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr><td>Ctrl + a</td><td>Jump to beginning of line</td></tr><tr><td>Ctrl + e</td><td>Jump to end of line</td></tr><tr><td>Ctrl + Arrow Left</td><td>Jump word backward

</td></tr><tr><td>Ctrl + Arrow Right</td><td>Jump word forward

</td></tr><tr><td>Ctrl + w</td><td>Remove word backward</td></tr><tr><td>Alt + w  
</td><td>Remove word forward</td></tr><tr><td>Ctrl + p</td><td>Go through command line history backward

</td></tr><tr><td>Ctrl + n</td><td>Go through command line history forward

</td></tr><tr><td>Ctrl + r</td><td>Reverse Search in command history:

\- Type in something to search

\- Type Enter to execute the searched command

\- Type "Ctrl + r" to search further in reverse

\- Type "Ctrl + s" to search further in inverse

\- Tip: In only a few cases it makes sense to use the inverse search (Ctrl + s) from the beginning, but usually you want to search in reverse from the latest history commands

</td></tr><tr><td>Ctrl + s  
</td><td>Same as "Ctrl + r" but inverse (starts from the beginning of the history)

</td></tr><tr><td>Ctrl + f</td><td>Autocomplete a suggestion ([Fish Shell](https://fishshell.com/ "Fish Shell") only)

</td></tr></tbody></table>

##### **OS Helper Commands**

<table border="1" id="bkmrk-os-helper-commands-d" style="border-collapse: collapse; width: 100%; height: 769.6px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">du -csh .  
</td><td style="height: 29.6px;">Show size of current folder  
</td></tr><tr><td>df -h  
</td><td>Show partitions / drives  
</td></tr><tr><td>lsb\_release -a  
</td><td>Show OS Version / Informations  
</td></tr></tbody></table>

##### **Remote / Host Commands**

<table border="1" id="bkmrk-other-helpful-comman" style="border-collapse: collapse; width: 100%; height: 207.2px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">wget https://www.somewhere495848.com/test.txt  
</td><td style="height: 29.6px;">Download a file  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">curl -LI https://www.google.com  
</td><td style="height: 29.6px;">Show Header Informations of URL  
</td></tr><tr><td>  
</td><td>  
</td></tr><tr><td>whois &lt;host&gt;  
</td><td>Show NS, DNS, Register about a host (e.g.: whois google.com)  
</td></tr><tr><td>host &lt;host&gt;  
</td><td>DNS Lookup of a host (e.g.: host google.com)  
</td></tr><tr><td>dig &lt;host&gt;  
</td><td>DNS Lookup of a host (verbose) (e.g.: dig google.com)  
</td></tr><tr><td>  
</td><td>  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">rsync -avz myfolder somehost:/var/www/  
</td><td style="height: 29.6px;">Sync a folder to a remote host and specific path  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">rsync -avz somehost:/var/www/ .  
</td><td style="height: 29.6px;">Sync from remote host and specific path to local folder  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">rsync -avz &lt;dirSource&gt; &lt;dirTarget&gt;</td><td style="height: 29.6px;">Sync entire Folder (locally)  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">rsync -avz &lt;dirSource&gt;/ &lt;dirTarget&gt; </td><td style="height: 29.6px;">Sync only contents of folder (locally)  
</td></tr></tbody></table>

##### **Command-Line Operators**

<table border="1" id="bkmrk-command-line-operato" style="border-collapse: collapse; width: 100%; height: 710.4px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr><td>&lt;command&gt; &gt; file.txt  
</td><td>Write output of a command into a file (creates/overwrites file)  
</td></tr><tr><td>&lt;command&gt; &gt;&gt; file.txt  
</td><td>Write output of a command into a file (appends at end of file)  
</td></tr><tr><td>&lt;command1&gt; &amp;&amp; &lt;command2&gt;  
</td><td>Do command2 only if command1 succeeds  
</td></tr><tr><td>&lt;command1&gt; || &lt;command2&gt;  
</td><td>Do command2 only if command1 fails  
</td></tr><tr><td>&lt;command1&gt; | &lt;command2&gt;  
</td><td>Pipe command1 output into command2  
</td></tr><tr><td>!  
</td><td>Negation Operator (e.g. find . ! -user "root")  
</td></tr><tr><td>More about operators: [linux-command-operators](https://www.makeuseof.com/linux-command-line-chaining-operators/)  
</td><td> </td></tr></tbody></table>

##### **Other helpful Commands**

<table border="1" id="bkmrk-other-helpful-comman-1" style="border-collapse: collapse; width: 100%; height: 710.4px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr><td>**Command**</td><td>**Description**</td></tr><tr><td style="height: 29.6px;">bash myCustomScript.sh  
</td><td style="height: 29.6px;">Execute a bash script  
</td></tr><tr><td style="height: 29.6px;">history | tail  
</td><td style="height: 29.6px;">Show last 10 lines of your history (commands)  
</td></tr><tr><td>htop  
</td><td>Very helpful utility to show all process, cpu, ram, ..  
</td></tr><tr><td>ps aux | grep http  
</td><td>Show processes who accesses http  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">which &lt;command&gt;  
</td><td style="height: 29.6px;">Show path location of a command  
</td></tr><tr><td>  
</td><td>  
</td></tr><tr><td>tar -cvf myfolder.tar myfolder  
</td><td>Create a compressed tar file of a folder  
</td></tr><tr><td>tar -xvf myfolder.tar  
</td><td>Extract a compressed tar file  
</td></tr><tr><td>zip -r myfolder.zip myfolder  
</td><td>Create a compressed zip file  
</td></tr><tr><td>unzip myfolder.zip  
</td><td>Extract a compressed zip file  
</td></tr><tr><td>  
</td><td>  
</td></tr><tr><td>EDITOR=nano crontab -e</td><td>Set Editor for current shell only (temporarily)</td></tr><tr><td>select-editor</td><td>Set Editor for user (usually permanently)</td></tr><tr><td>vim file.txt</td><td>Edit a file in the Vim Editor</td></tr><tr><td>nano file.txt</td><td>Edit a file in the Nano Editor</td></tr><tr><td>  
</td><td>  
</td></tr><tr><td><div>sudo su - www-data -s /bin/bash</div></td><td>Switch User to example "www-data"</td></tr></tbody></table>