# Basic commands

## Viewing files

### cat

Just displaying the file content

<https://linux.die.net/man/1/cat>

### head

Use head will display the first 10 lines of the file you can just use: `head file.txt`

<https://linux.die.net/man/1/head>

### tail

Works just as the opposite of head and it will display the last 10 lines of the file

<https://linux.die.net/man/1/tail>

### nl

For larger files it may contain crazy long lines so displaying the lines may be helpful so we use `nl file.txt`

<https://linux.die.net/man/1/nl>

### more

Display with whole file content

***“More** is a filter for paging through text one screenful at a time. This version is especially primitive. Users should realize that* [***less***](https://linux.die.net/man/1/less)*(1) provides **more**(1) emulation and extensive enhancements.”*

### less

less is more is real. Less provides more functionality you can scroll through the file and search terms in it using `/` so cool!

<https://linux.die.net/man/1/less>

## Filtering and grabbing texts

### grep

Most useful one of all time, you can do `grep <text>` but often times we will use it with another command let’s say `cat file.txt | grep input` so it will output all lines that has “input”

<https://linux.die.net/man/1/grep>

## Finding and replacing

### sed

Let’s say we have a file.txt and you are going to replace some text like “ti” to “it”

```bash
Hello, lil bro
I'm here to demonstrate the sed command haha, ti will be fun
tell me how you do ti.
```

`sed s/ti/it/g file.txt > file2.txt` so it will have as another file named file2.txt and the change will be made. The `s` flag before the slash ti stands for substitution and the last `g` flag is telling linux to replace globally so `sed s/<text_to_be_replaced>/<text_to_replace>/g file.txt`

But what if we don’t add `g` flag? it will just replace the first occurrence. But what if you want to do the other ones? then you will need to count the occurrences like second one, so `sed s/<text_to_be_replaced>/<text_to_replace>/2 file.txt` and it will only replace the second occurrence

## software handling

### apt

In Debian-based Linux distributions apt is the most common form, we use it for almost everything from download to update.

**Searching packages**

When searching for packages you can use `apt-cache search <keyword>`

**Adding software**

`apt-get install <package_name>` simple as that

**Removing software**

`apt-get remove <package_name>` note that the remove command won’t remove the config files so this is where `purge` comes in simply do `apt-get purge <package>`

Another thing to notice is that when removing a software, if the libraries or dependencies that automatically installed you don’t need to use then simply use the `autoremove` flag `apt autoremove <package>`


---

# 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://vix-w1zzer.gitbook.io/vixwizzer/notes/linux/basic-commands.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.
