Navigating the File System
In this article, we will be exploring basic shell commands to help you create, display, and navigate directories in your file system. The end of each article should have a list of all the commands that were used.
- Let's start off by figuring which directory we are currently in:
pwd
>> /Users/jadslim
the pwd
command prints the full pathname of the current directory which in my case is /Users/jadslim
- Let's also print the full list of files and folders in our current directory:
ls
>> Applications Movies
Music Pictures
Desktop Public
Documents bin
Downloads build
Library
- Now, this might seem like the full list of files and folders in our directory, however, some directories hold hidden files. Let's display those hidden files and folders:
ls -a
. .. .CFUserTextEncoding
.DS_Store .IdentityService .ServiceHub
.Trash .Xauthority .Xauthority-c
.Xauthority-l .bash_history .bash_profile
Applications Creative Cloud Files Desktop
Documents Downloads Library
Movies Music Pictures
Public. bin build
After using the -a
prefix, other files have been displayed that weren't available to us previously. These files are hidden by adding a dot .
to the beginning of each file or folder. Most of these hidden files and folders hold configurations for certain software that aren't very useful to display for the average user.
- Now let's navigate away from our User directory and into our Desktop directory:
cd Desktop
This shouldn't print anything Now to verify if we are in our Desktop directory simply use the pwd
command:
pwd
>> /Users/jadslim/Desktop
The directory clearly shows that we are in our desktop folder.
- Let's create a folder in our Desktop directory:
mkdir test
let's make sure this folder was created:
ls
>> test
let's also navigate within the folder and verify our directory:
cd test
pwd
>> /Users/jadslim/Desktop/test
We successfully created and navigated to a new folder.
- Now let's try navigating backward to our Desktop file:
cd ..
pwd
>> /Users/jadslim/Desktop/
The alias name for the parent directory is ..
, so when you navigate to it, it will bring you back to the parent directory of the current folder.
- We can also go back to our root user directory:
cd
pwd
>> /Users/jadslim/
This command will always take you to the root user directory, no matter where you are in the file system
- The terminal seems full of commands now, let's clean it up:
clear
your terminal should be completely cleared up.
- Now that we're in our parent directory, let's navigate to our test directory:
cd Desktop/test
pwd
>> /Users/jadslim/Desktop/test