Linux Quick-Start Guide: Getting Around and Changing Things

Joseph Syverson
Dec 3, 2019 · 4 min read
Linux in motion

For personal computing at least, you can program any location on your computer from wherever you’re currently located. But sometimes it’s just easier to go there in person.

If you’ve been reading these tutorials sequentially and have understood that reading, you already know that we can look at what any part of our system is like from any other part. The same is going to apply for manipulating files and directories. However, working with files at a distance increases the complexity and annoyance of doing so. So, whether we move to the directory where the work is to be done or we type longer commands to stay where we are is often a matter of discretion. Is it worth going all the way there to do X amount of things? If it takes more effort to go there, stay where you are. If you plan on working in a particular directory at length, go there. The cd command will take you.

Wherever you are, just typing cd will return you to your <user> directory (described here). To get to the directory you were last in, you can type:

cd -

Add a specific location as an ab path to go to that location: cd <absolute path>. For example:

cd /home/<user>/Pictures

A file’s path is determined by the directories that contain it. For example, Pictures is contained in <user>, which is contained in home, which is contained in the root directory, known to BASh simply as /. Therefore, the absolute path of Pictures is /home/<user>/Pictures.

cd also takes relative paths. If you’re in a directory contains a directory you’d like to navigate to, you do not need to type the absolute path. Say for example you’re in /home and you’d like yo get to your Pictures directory. Typing pwd reveals that you’re in your <user> folder, and ls that Pictures is in that same folder with you.

A move from home

To get there in one motion, you can simply type:

cd Pictures

You can move backward one directory by typing:

cd ..

To move backward muliple directories, continue to feed cd ..s, separated by slashes. For example:

cd ../../..

If you’re still in Pictures, the command above will bring you all the way back to the root directory (/), at the bottom of everything (or the “top” of everything, as computer people like to say for some reason).

Now that we can go where we need, let’s create, read, update and destroy files. To create a file, type touch <file name>. For example:

touch diary

You can pass an entry into your file in a number of ways (discussed in the Programming and Power Tools sections), but the most basic way uses the echo command and a redirection metacharacter (>>). For example:

echo "2019/12/03: Dear Diary, the End is nigh." >> diary

Output the contents of your diary with cat:

cat diary

To update a file name, type mv <file name> <new file name>. For example:

mv diary doomsdaycountdown

To move a file, we also use the mv command. A file, like a people often do, has a common name for quick reference and a longer, proper name. The file above’s common name, or basename, is doomsdaycountdown. I made it in my Documents folder so its full name, or absolute path, is /home/joes/Documents/doomsdaycountdown. When we update a file name, we’re just changing the address so that the computer knows where to look for it.

Let’s say we’re in our Documents folder and we want to move our countdown to the Downloads folder. Using the syntax above (mv <file name> <new file name>), we could type:

mv doomsdaycountdown /home/joes/Downloads/doomsdaycountdown

If you want to retain the same basename (doomsdaycountdown), you can shorten the command above to simply name the directory where it goes, and leave the basename out. For example:

mv doomsdaycountdown /home/joes/Downloads

To destroy a file, type rm <file name>. Let’s say we want to spare our readers the terror of the Apocalypse. We can delete the file like this:

rm /home/joes/Downloads/doomsdaycountdown

If we’re in the Downloads folder, we can shorten the command to:

rm doomsdaycountdown

Note: rm and rmdir below are execute the final destruction of a file. It does not send them to a trash bin folder, like on your graphical interface. Once you delete a file, it’s gone.

Directories take similar but different commands for creation and destruction. To create a directory, type mkdir <directory name>. For example:

mkdir revelations

Remove a directory with rmdir <directory name>:

rmdir revelations

If the directory has contents in it, rmdir will not work. To delete a directory with all of it’s contents, type rm -rf <directory name>.

rm -rf revelations

Moving a directory is as moving a file: mv <directory name> <new location>:

mv revelations Documents/

Joseph Syverson

Written by

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