Using the Bash Shell

This article provides a simple overview of the basic commands executed by a bash shell. This document is aimed towards beginners.

Using the Bash Shell

If you don't know what a shell is, click here. Using a shell for the first time can be difficult; especially to native Windows users. The best way to become comfortable with a shell is by practice. Initially, I hated using a shell. I thought the idea of typing in commands was monotonous. Now I live by the shell! Below you will find several examples of how to navigate through Linux using the bash shell.

Changing Directories

Changing directories is a rather simple process; most people remember it from the days of DOS. Using the cd command, you can navigate through the entire directory tree. Extended commands permit users to skip multiple files directories. Notice the output below:

Create, Delete, and Move

Initially, you will want to create, copy paste, and delete files. Upon logging in, your shell will start in the /home directory. Below I am logged in as the user weaponx. You can always check what directory you are currently working in by using the pwd command. Short for Print Working Directory. Do not get this command confused with the passwd, the command for changing your password.

Using the ls command, the only file in the home directory is the overflow.c file.

[weaponx@roswell weaponx]$ ls
overflow.c
[weaponx@roswell weaponx]$

Red Hat and other distros of Linux will color code the output to help users distinguish between files, folders, and zip files. This is very handy when you have a directory full of files and other folders. Moving on, let's say that we want to created a .txt file named hello. Using the touch command this is very simple.

As you can see the file was created. That might even be faster than doing a right-mouse click and selecting new text document. Although the file has been created, it blank. To edit the file, you must use an editor such as vim. Now, let's say we don't want that file anymore and we want to delete it. This can be done using the rm command.

Easy enough right? However, there is no "un-delete" or "restore" command in Linux. Be careful what you delete! NOTE: NEVER EXECUTE THIS COMMAND, rm -rf / Doing so will delete the entire filesystem without asking any questions! Don't be tricked by advanced users trying to play a trick on you... Now let's re-create the file (for practice) and create another folder named files. After that, we'll move the hello.txt file into the files folder. Use the mkdir to create directories, and the mv command to move files.

Walking through it again, the usage is rather simple. ln is followed by the file name, then the destination. More specifically, like this:

ln filenamedestination

[weaponx@roswell files]$ ln hello.txt/home/weaponx/

The result is simple, it creates a link to the hello.txt files located in the files directory. However, when using the rm command, only the link will be removed. The original file will still reside in the "files" directory.