[1/4] Beginners BASH basics - becoming one with the shell
Tags: beginners, bash, webdev, productivity
Published: 2020-06-23 00:15:34

## Part 1 of a 4 part series
[View part 2 here](https://dev.to/haydenrou/2-4-beginners-bash-basics-learning-the-way-of-the-shell-3f7b) and [part 3 here](https://dev.to/hayden/3-4-beginners-bash-basics-wait-bash-can-do-that-4oh9)

When I first started using the command line it seemed quite daunting to me. I didn't know what I _should_ know and I didn't know what benefits investing time into learning more would give me. My job required me to learn more Ruby, so why learn `bash`?

![bash who?](https://media2.giphy.com/media/oiJ0Yf3sLucp2/giphy.gif)

I have since learnt that having knowledge of just some basic commands improves your workflow tenfold, and for me in particular increased my confidence when `ssh`ing to a server or even just having to navigate around my own environment.

By the end of this series I hope you'll feel at home when navigating the command line and won't feel a need to use the file manager GUI again!

Here are some of my most commonly used commands:

# man
`man` provides you with the manual documentation for a utility. Use `man` the same way you would when using programming documentation - it will tell you all the available flags for a command and what it can be used for. The main source of truth when questioning how to use a tool!

Example usage: `man ls` (use `q` to exit)

Equally, you could also use `info ls` to view this information too.

# ls
`ls` will list the files in your `cwd` (current working directory).

If you use `man ls`, you can see that `ls` offers many flags. The most common usage however, are (in my opinion) `lah`. Executing `ls -lah` will give you a list of all files in your CWD (current working directory) including hidden (`.files`), with their file-sizes, permissions and dates when they were updated.

Example usage: `ls -lah`

You can then use the `file` command on a file to view the details of it!

# cat
`cat` will spit the contents of a file out to the command line.

Example usage: `cat myfile`

# mkdir
`mkdir` creates a directory at the specified location. As with `ls`, `mkdir` has many useful flags that you can see in the manual. The most notable being `-p`, which will recursively create the directories as specified.

Example usage: `mkdir -p ~/my_directory/my_subdirectory`

# rm
`rm` is used to remove a file or directory.
**Warning:** paired with `sudo`, or even on it's own, this can be a very dangerous command if used incorrectly.

You may want to use the following flags:
`-r` for recursive
`-v` for verbose (it will give feedback to what is happening)
`-f` for force

Example usage: `rm -rvf ~/asd`

# grep
`grep` will allow you to search for specific content from a file or result list.

Example usage: `grep 'my_search' test.md`, you will see all the lines containing `my_search` within `test.md`.

You can view lines around them by using the `-C 3`, or get all lines _not_ containing the match with `-v`.

# sudo
`sudo` will execute the following command as a superuser. You'll often need to use `sudo` to run certain commands, for instance commands that will affect the system.

Example usage: `sudo systemctl status mysql`

## conclusion

And that's it for part 1 of my beginners bash series! If all of the above is below you... stay tuned for some more advanced tips!

[Dive into `curl`, `chmod` and more in Part 2 - here](https://dev.to/haydenrou/2-4-beginners-bash-basics-learning-the-way-of-the-shell-3f7b)

Feel free to ask any questions or if you're interested in how I've customised my environment, head over to my repository below.

{% github https://github.com/haydenrou/dotfiles no-readme %}