# Network Linux Commands

## tail

Print the last N number of data of given input. By default, it will print the last 10 lines of the specified file.

Syntax: tail \[OPTION] \[FILE]

<table><thead><tr><th>Short Option</th><th>Long Option</th><th width="200">Syntax</th><th>Description</th></tr></thead><tbody><tr><td>-n</td><td>--lines</td><td>tail -n [number] [filename]</td><td>Specify number of lines</td></tr><tr><td>-c </td><td>--bytes</td><td>tail -c [+/- number] [FILENAME]</td><td>Prints the last 'num' bytes (pos or neg number)</td></tr><tr><td>-q</td><td>--quiet</td><td>tail -q [FILENAME] [FILENAME]</td><td>Data from each file is not preceded by its file name.</td></tr><tr><td>-v</td><td>--verbose</td><td>tail -v [FILENAME]</td><td>Data from specified file is always preceded by filename.</td></tr><tr><td>-f</td><td>--follow</td><td>tail -f [FILENAME]</td><td>Follow live updates to file.</td></tr></tbody></table>

## Curl

## &#x20;grep

Grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern.

Syntax: grep \[OPTION] \[pattern] \[FILENAME]

| Options | Description                                                                           |
| ------- | ------------------------------------------------------------------------------------- |
| -c      | Prints count of the lines that match a pattern.                                       |
| -h      | Display the matched lines, do not display the filenames.                              |
| -i      | Ignores, case for matching.                                                           |
| -l      | Displays list of filenames only.                                                      |
| -n      | Display the matched lines and line numbers.                                           |
| -v      | Prints out all the lines that don't match the pattern.                                |
| -e      | <p>Specifies expression with this option (Can be </p><p>used multiple times)</p>      |
| -f      | Takes patterns from file, one per line.                                               |
| -E      | Treats patten as an extended regular expression.                                      |
| -w      | Match whole word.                                                                     |
| -o      | Print only the matched parts of a matching line, with each on a seperate output line. |
| -A n    | Prints searched line and n(lines) after the results.                                  |
| -B n    | Prints searched line and n(lines) before the result.                                  |
| -C n    | Prints searched line and n(lines) after before the results.                           |

## dig

Finds DNS Information

Syntax: dig \[SERVER] \[NAME] \[TYPE]

| Option         | Description                                            |
| -------------- | ------------------------------------------------------ |
| +short         | Displays short answer option                           |
| +noall +answer | To access detailed info on the answers section.        |
| +trace         | Displays each different server the query goes through. |
| -x             | Look up using IP Address                               |

## cd&#x20;

Change directory

Syntax: cd \[DIRECTORY]

| Option                   | Description                                |
| ------------------------ | ------------------------------------------ |
| /                        | Change to the root directory.              |
| \~                       | Change to the home directory.              |
| ..                       | Move to the parent directory.              |
| "dir name"  or dir\ name | Navigate to a directory with white spaces. |

## telnet

call IP address with a specific port

Syntax: telnet \[IP Address] \[PORT]

## cat

Displays file content on output.

Syntax: cat \[filename]

## &#x20;wget&#x20;

Stands for Web Get. It downloads a file from the internet.

wget \[OPTION] \[URL]

| Option | Description                 |
| ------ | --------------------------- |
| -b     | Download in the background. |
| -o     | Overwrite the log while     |
|        |                             |

## PWD&#x20;

Prints current working directory

Syntax: pwd \[Options]

| Option | Description                      |
| ------ | -------------------------------- |
| -L     | Prints logical directory.        |
| -P     | Prints actual working directory. |

## echo

Echo is used to display of line of text/string that is passed as an argument.

Syntax: echo\[OPTION] \[STRING]

#### Backslash escapes

\b: removes all spaces

\c: suppress trailing new line

\n: create new line

\t: adds tab

\r: Returns everything after r

\v: add vertical tab&#x20;

| Option | Description                                     |
| ------ | ----------------------------------------------- |
| -e     | Enables the interpretation of backslash escapes |
| \*     | works the same way as ls                        |
| -n     | used to omit trailing newline                   |

## cp

CP stands for copy. Used to copy files or groups of files or directory.

Syntax:&#x20;

cp \[OPTION] \[SOURCE] \[DESTINATION]

cp \[OPTION] \[SOURCE] \[DIRECTORY]

cp \[OPTION]\[SOURCE1] \[SOURCE2]-n \[DESTINATION]

| Option   | Description                                                                                                                                   |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| -i       | Systems first warns user before overwriting the destination file.                                                                             |
| -b       | This option creates the backup of the destination file in the same folder with a different name and in a different format.                    |
| -f       | Used if user doesn't have writing permission. It will delete destination file first then copy of  content is done from source to destination. |
| -r or -R |                                                                                                                                               |

## df&#x20;

check disk space

Syntax: df \[option]

-h: human readable format

## free -mh

check ram

## htop&#x20;

check cpu

## top -c

check cpu (old version)

## awk

find specific columns&#x20;

Syntax: awk '{print \_\_}' \[file]

## sed&#x20;

FInd and replace, insertion or deletion. Most common use of sed is find and replace.

Syntax: sed \[OPTIONS] \[Script] \[INPUTFILE]

\1: first occurance&#x20;

\2: second occurance

\g: global replace

sed 'n s/word1/word2/' \[FILE]

## netstat

netstat -p IP output: list of all connections for the PHv4 protocol

netstat -s -p icmpv6 output: list all statistics on the ICMPv6 protocol.

netstat -ano output: display all open ports and active connections (numeric and process ID included)

netstat -a | less output: shows all the connected and waiting sockets in a easier way to read

netstat -at | less output: see only the TCP sockets.

netstat -au | less output see only UDP sockets.

netstat -l | less out output: sockets that are in the listening state. (can be combined with -t and -u)

netstat -st | less output: statistics for TCP&#x20;

netstat -su | less output: statistics for UDP

netstat -r output: routing table&#x20;

## &#x20;mtr \[Domain]&#x20;

live traceroute

## strace -p \[PROCESSID]

## alias \[alias]="\[command]"

You can also nano into&#x20;
