This article is a gentle introduction to Bash for absolute novice user.

This article will teach you the absolute least you need to know about using Bash. It will teach you how to examine, make, move, copy, rename, and remove files. It will get you started as fast as possible. It is not intended to be a complete course in using Bash. It is not about Bash scripting.

Using a command line interface for the first time can be intimidating. Don’t worry. Take it slow and let these new concepts sink in.

There is also a YouTube video of this article

Warning

The command line is very powerful. It does not hold your hand. Be careful. Be especially careful when copying commands from the Internet. Bad people sometimes post malicious commands. Remember with great power comes great responsibility.

What is Bash

Bash is a Unix shell and command language. Written by Brain Fox as a free alternative to the Bourne Shell. It was first released in 1989. It is usually the default shell for Linux and macOS. And it is even now available for Windows 10.

What is a shell

It is basically the command line. You type commands into a terminal window. Commands are generally structured as someCommand and an often there is one or several someArgumentDon’t worry about what the following does. Just look at the structure.

Just a Command

ls

A Command with an Argument

ls -l

Getting Started

Open a command line terminal

Knowing Where You Are

pwd

“pwd” stands for “Print Working Directory”. This command tells you where you are.

As you can see from the above screenshot, I am in the “/home/jason/demo” directory.

Looking Around

Now that we know where we are, we can look around. What files or subdirectories are in this directory.

ls

There are four items in this directory: “cats.mpg”, “music.mp3”, “notes.txt”, and “pics”

Navigation

We know where we are. We have taken a quick look around. Now we will move to a different directory. We want to move to the “pics” directory that is withing our current working directory. We will use the “cd” command to change directories. The “cd” command takes both relative and absolute paths.

Relative Path

cd pics

The relative is based on our working directory. Our current working directory is “/home/jason/demo”, so we can refer to the “pics” directory simply as “pics”.

We can also move back up one directory with:

cd ..

Absolute Path

cd /home/jason/demo/pics

The absolute is the complete path to the directory. The “pics” directory is within “demo” that is within “jason” and that is within “home”. Thus and absolute path of “/home/jason/demo/pics”.

Making Empty Files

We will make an empty file with the command “touch”. This command creates an empty with the name of the file as an argument. In this case our argument will be “essay.txt”. This will make an empty file named “eassay.txt”

touch essay.txt

Making New Directory

We will make a directory file with the command “mkdir”. This command creates a directory named with an argument. In this case our argument will be “dogs”. This will make a directory named “dogs”.

mkdir dogs

Copying Files and Directories

We can copy a file with the command “cp”. This command requires two arguments. The path of the file being copied and the path of the new file. Remember this path can be absolute or relative. We are using the relative path here. In this case we will be copying the file “notes.txt” and making a new file called “draft.txt”.

cp notes.txt draft.txt

When we copy a directory we should include an extra argument. Giving “cp” the “-r” arguement will tell it to copy directories recursively. This means the directory and is subdirectories will be copied. We will be copying the directory “dogs” and making a new directory called “cats”.

cp -r dogs cats

Moving Files and Directories

We can move a file with the command “mv”. Just like the “cp”, this command requires two arguments. The path of the file being moved and the files new path. We will move the file “cats.mpg” into the directory “cats”.

mv cats.mpg cats/cats.mpg

Renaming Files and Directories

We can rename a file with “mv” too. Changing the path changes the name.

mv notes.txt oldnotes.txt

Removing Files and Directories

Warning: removing files can be permanent! Be careful.

We remove file with the “rm” command. The command is followed by the name of the file to be deleted.

rm draft.txt

Just like the “cp” command, we need to give the “-r” argument to r recursively remove directories and their subdirectories.

rm -r pics

Conclusion

In this article we covered that absolute basics of using Bash. We learned how to move around. And we learned to manipulate files and directories. I hope this tutorial was useful to you.

Jason Rigden

Written by

You may remember me from such projects as The Seattle Podcasters Guild, The Talking Cryptocurrency Podcast, or some of my popular Python tutorials.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade