# Command Line

## Scanning network for ip addresees

This does a simple ping scan in the entire subnet to see which hosts │ are online.

### Install **`nmap`**

```shell
sudo apt-get install nmap
```

```shell
nmap -sP 192.168.1.*
```

*or more commonly*

```shell
nmap -sn 192.168.1.0/24
```

***

## Cleaning and clearing logfiles

### journal

Clearing out logs older than 10 days

```shell
journalctl --vacuum-time=10d
```

Clearing out journal more than 2 gigs

```shell
journalctl --vacuum-size=2G
```

### Any log files

Get sizes

```shell
du -h /var/log/
```

Clear logs that are huge

```shell
cat /dev/null > whatever_log.log 
```

## Setting up webservers

See [web\_servers.md](https://github.com/djsnipa1/cheatsheets/blob/master/web_servers.md)

## `diff` files in vim

```shell
nvim -d file1.txt file2.txt`
```

`diff` **online** files in vim

```shell
nvim -d <(curl -sL "https://crap.com/file1.txt") \
<(curl -sL "https://crap.com/file2.txt")
```

## `curl`

See [curl.md](/notes/curl.md)

## Showing Key Codes

```shell
xev -event keyboard
```

*

## Find text in a file

```shell
find . -type f -exec grep "example" '{}' \; -print
```

`f` = file

## Encrypt and Decrypt

**Encrypt:** **EASIEST OPTION**

```bash
gpg -c file.txt
```

Alternative method:

```bash
openssl enc -aes-256-cbc -salt -pbkdf2 -in file .txt -out file.enc
```

**Decrypt:**

```bash
gpg -d file.gpg
```

Alternative Method: add `-d` to the above command

***

## Adding to $PATH

Simply add **`/place/with/the/file`** to the **`$PATH`** variable with the following command:

```bash
export PATH=$PATH:/place/with/the/file
```

***

## Finding directories over/under a certain size

```shell
du -sm * | awk '$1 > 1000'
```

This shows directories larger than 1 gig

***

## Star Wars Asciimation

```shell
telnet towel.blinkenlights.n
```

***

## Umcompress & Compress

### 7zip

#### Unzip zip file

```shell
7z.exe e *.zip
```

#### List files in archive

```shell
7z.exe l -r filename.zip
```

### For tar.gz

To unpack a tar.gz file, you can use the **tar** command from the shell. Here's an example:

```shell
tar -xzf rebol.tar.gz
```

The result will be a new directory containing the files.

### For just .gz (.gzip)

In some cases the file is just a gzip format, not tar. Then you can use:

```shell
gunzip rebol.gz
```

***

## Command Line Notes

**September 3,2019**

[Courses Dashboard | Wes Bos](https://courses.wesbos.com/account/access/5cdc7ba285f96c03c1e44b42/view/195975829)

**zsh** CTRL + R lets you search through recent commands

**History** Example `git` and ⇧ goes through all `git` command history


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chadboyce.gitbook.io/notes/linux_command_line.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
