[1/4] Beginners BASH basics - becoming one with the shell
Hayden Rouille
Posted on June 23, 2020
Part 1 of a 4 part series
View part 2 here and part 3 here
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
?
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
Feel free to ask any questions or if you're interested in how I've customised my environment, head over to my repository below.
Posted on June 23, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.