Bash commands introduction  🧑🏿‍💻
Tags: linux, codenewbie, bash
Published: 2020-09-17 14:01:08

I just learned about some basic terminal commands and it was a great experience! 

It might not be as instinctive as a graphical user interface, still there are some good reasons to start using your terminal.

🔷 High performance

🔷 Real control of what is happening under the hood

🔷 Task automation

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/833frdzkf09zxh4boiy8.gif)

Note: We will only walk through the basic commands of Linux/macOS terminal.

#Get started#

If you are using Linux or macOS as your operating system, you are very likely to use bash shell which is the most widely used shell.

Once you opened up your terminal, should have something that look like this: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5ifff6my170su31441jj.png)

##Navigation##

The cd (change directory) command lets you navigate through your computer's file system.

```bash
# Go to target folder
cd /target

# Go to parent folder
cd ..

# Go to home folder
cd ~
```

##List##

The ls (list) command print files and directories.

```bash
# Print files located in the current directory.
ls

# Print files located in the target directory
ls targetparent/target
```

##Options##

You can add some options to most of existing commands by simply appending your command with -[option]

For example:

```bash
# Print files located in the current directory with more details.
ls -l

# Print every files located in the current directory (hidden files as well).
ls -a
```

##Make/remove file or directory##

The mkdir (make directory) command create a new directory.

```bash
# Make a new directory in current directory.
mkdir directoryName

```
The touch command create a new file.

```bash
# Make a new file in current directory.
touch fileName

```

The rm/rmdir (remove) commands delete file/directory.

```bash
# Delete an empty directory.
rmdir myDirectory

# Delete a file.
rm myFile

# Delete a directory recursively.
rm -r myDirectory

```

##Where am I?##

The pwd (print working directory) command display your current location.

```bash
# Display current location in terminal.
pwd

```

##File management##

The cp (copy) command lets you copy and paste your files.

```bash
# Create a copy of a file to target location.
cp myFile target/

```

The mv (move) command moves a file to another location *OR* rename it if you stay in current directory.

```bash
# move file to target location.
mv myFile target/

# rename file.
mv myFile newName
```

##Read/Edit file from the terminal##

The head/tail commands print a part of the file.

```bash
# Print 10 first lines of a file.
head myFile

# Print 10 last lines of a file.
tail myFile

# Print 30 first lines of a file.
head -n 30 myfile

```

The cat (concatenate) command can print content of a file, concatenate multiple files together, create and edit files, ...

```bash
# Print content of a file in terminal.
cat myFile

# Print content of a file with numbers.
cat myFile -n

# Combine multiple files ogether.
cat fileOne fileTwo > target

```
##Search##

The grep (get regular expression) search for a given expression.

```bash
# Look for a word in a file.
grep word fileName

# Look for a word in a file without case sensitivity.
grep -i word fileName

```

Here is my personal cheat sheet for bash commands!

Thank you for reading 😇