In Part 1, we covered what the shell is, how it works, and some good habits to build early. In this post, we are getting into the practical side: how to move around your file system, work with files, and use wildcards to handle multiple files at once.
Understanding Your File System
Before diving into commands, it helps to understand how your computer organizes files. Everything lives in a tree structure that starts from a single root directory represented by /. Every file and folder on your system lives somewhere within that tree.
There are three locations worth knowing:
The root directory (/) is the very top of the file system. Everything branches out from here.
The home directory (~) is your personal space. It is where your files, folders, and configurations live. When you open a terminal, this is usually where you start.
The working directory is wherever you currently are in the file system at any given moment.
Navigating the File System
pwd stands for "print working directory." It tells you exactly where you are:
pwdls lists the contents of your current directory:
lsYou can add options to get more detail. ls -l shows a detailed list with permissions, file sizes, and dates. ls -a shows hidden files, which are files whose names start with a dot:
ls -l
ls -acd stands for "change directory." It is how you move around:
cd DocumentsTo go up one level:
cd ..To go back to your home directory from anywhere:
cd ~To jump back to the previous directory you were in:
cd -Working with Files and Directories
Creating a file with touch creates a new empty file:
touch newfile.txtCreating a directory with mkdir creates a new folder:
mkdir projectsCopying files with cp duplicates a file to a new location:
cp sourcefile.txt destination/Moving or renaming files with mv either moves a file to a different location or renames it:
mv oldname.txt newname.txt
mv file.txt projects/Deleting files with rm permanently removes a file:
rm file.txtTo delete a directory and everything inside it:
rm -r foldernameUse this carefully. There is no undo.
Viewing File Contents
less lets you read the contents of a file one page at a time. Use the arrow keys to scroll and press q to exit:
less filename.txtcat prints the entire contents of a file directly in the terminal. Best used for short files:
cat filename.txtfile tells you what type a file is, which is useful when you are not sure what you are dealing with:
file filenameUsing Wildcards
Wildcards let you work with multiple files at once without typing each name individually.
The asterisk * matches any number of characters. For example, to list all text files in a directory:
ls *.txtThe question mark ? matches exactly one character. So file?.txt would match file1.txt or fileA.txt but not file.txt:
ls file?.txtWildcards work with most file commands. For example, to delete all .log files in a directory:
rm *.logHidden Files
Files whose names begin with a dot are hidden by default and will not show up with a regular ls. To see them:
ls -aThese are often configuration files for tools and applications. You will come across them frequently as you work more in the command line.
Final Thoughts
Navigation and file management are the foundation of working in the shell. Once these commands feel natural, everything else builds on top of them. The best way to get there is to practice in a real terminal rather than just reading about it. Open one up, move around, create some files, and get a feel for how it all fits together.