5 Useful Linux Commands to make you look like a Pro
Tags: linux, productivity, programming, tutorial
Published: 2022-11-22 19:17:58

The command line can be an intimidating and scary black screen when first introduced to beginners. Where are the fancy buttons? The colors? How can I move files? Where is my mouse!?

These 5 Linux Commands will give you a better handle of the command line and will make you look like a pro.

## 1. "`cp`"
The `cp` command stands for "copy" and the syntax of the `cp` command works like this:
```
$ cp [OPTIONS] SOURCE DESTINATION
```
Where the `SOURCE` is copied over to `DESTINATION`, you can also have multiple `SOURCE` files, so that you can copy over multiple files to `DESTINATION`. A useful flag that you may end up using a lot is the `-R`, `-r`, or `--recursive` command, which allows you to cp entire directories recursively. For example:
![cp command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giym48e5pdsj2galchdt.png)
## 2. "`mv`"
The `mv` command otherwise known as "move" will move files wherever you want them to go, similar to the `cp` command, but instead of leaving a copy the entire file or directory will get moved to the `DESTINATION`. Also, in the `man` docs `mv` it shows, `mv - move (rename) files`. So, not only can you move files, but by using the `mv` command like this:
```
$ mv [FILE] [RENAMED]
```
A useful flag to understand what is going on while using the `mv` command is the `-v` command, which stands for verbose. When you use the `mv` command, use a `-v` before your `SOURCE` input to show a more detailed view of what the `mv` command is doing. For example:
![mv command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6c7fqxdcxsu1xc2yhf4.png)
## 3. "`|`"
The `|` command, aka the "pipe" command is used to combine two or more commands where the first command will be an input for the second command. (And so on so forth) Seeing the "pipe" in action makes it easier to understand.
![Pipe Command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmbfw9q2n99itsdpnawb.png)
In this block of code, the contents of cat are shown, then you would use the `|` command to use the contents of `file.txt` and run the command `sort` on them, which alphabetically sorts the contents of `file.txt` and displays those results on the console. 

## 4. `>`
The right-angle bracket is a way to transform and push data in your terminal from one place to another. Just like the example from the pipe command you can store the data of the sorted `file.txt` to another file called `sorted_file.txt`, so:
![Angle braket command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5u6v8k5kwym2l5silsfc.png)
First, you sorted checked the file contents of `file.txt` and then you used the `pipe` command along with the `sort` command. From above, you saw that this displayed the contents of `file.txt` but alphabetically sorted, now with the `>` command, you take those contents of the alphabetically sorted file and put that data into a new file called `sorted_file.txt`. Neat right?

> The `>` and `|` may not be super useful by themselves, but when used with other commands they are very powerful tools that you can use to your advantage. 

## 5. `grep`
From the `man` docs `grep` prints lines that match a pattern that you specify. The usage is as follows:
```bash
$ grep [OPTION...] PATTERNS [FILE...]
```
A simple usage for the `grep` command could be to find all lines that have an "a" in a file. For example:
![Show all As](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58zgc1l3g5c994rivr0j.png)
You can extend the `grep` command to look for certain files, combining the `grep` command with the `|` command:
![More piping and grepping](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2akbpyda1dkhhw3cw2e8.png)
Using these commands in unison with each other will give you a better grasp at the Linux terminal, and make you look like a pro to your friends and co-workers.

## BONUS: `tree`
The `tree` command is not a preinstalled command available in Linux, although, it is a nifty tool that can help you find files in your system. To install `tree` run
```bash
$ sudo apt install tree
``` 
For Ubuntu systems, although other systems may use different package managers. `tree` lists contents of a directory in a tree-like format. For basic usage you could run
```bash
$ tree folder
```
For example:
![Tree Usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0e96kdkwbyjxv96835r.png)
Then, using your new founded knowledge of the "pipe" command and "grep" you can filter and find specific files that you want, for example, searching for all `.cpp` files.
```bash
$ tree labs | grep .cpp
```

_Hope you found this useful!_