A lot of what you’ll do in Linux will be around file management. Here’s a fun fact: In Linux everything is seen as a file!
To get the most of this lesson please make sure you’ve completed the previous lesson Introduction to the Linux Terminal (CLI)
Where am I?
One of the first challenges you’ll face as a new Linux user is the overwhelming feeling of not knowing where you are, what you are looking at or even what to do next. In the previous lesson we covered the “what you are looking at” part.
When you log into a Linux server or when you open the terminal, you get placed into the home directory of the user you logged in as. The path will be something like this
pwd and press enter on the terminal to see the path to the current location you are at (unless stated otherwise, for the rest of this tutorial, always type enter after typing any command). To be sure you are in the home directory type
cd ~ then type
pwd again to see the path of the current directory you are in.
It is important to understand paths. For example let’s look at the path
/home/ali . This is interpreted as the directory named “ali” is in the directory named “home”. “home” is on the root directory which is represented by “/” in Linux. The nesting of directories can go on and on.
Navigation in this case simply means moving around the Linux operation system. The
cd command is used to achieved this and you’ll use this command a lot in your Linux journey. Let’s see how to use it.
cd /usr/local to switch to the /usr/local directory. This directory holds files that don’t belong to the operating system and used for local installations.
Once in this directory type
ls -l to display the contents of the directory.
How to Identify Directories
When viewing the contents of a directory in the long listing format, Linux displays some extra information about the contents. The
drwxr-xr-xin the figure above represents a lot of key information about each file such as type and the permissions each group has on the file. For the sake of this lesson we are only interested in the first character which tells us the file type. Whenever it starts with a
dit means the file is a directory and when the
dis missing, it means it’s just a file. Some Linux distros use a color-code when listing directory contents so files and folders and other attributes can be identified by color. In the figure above
libare both directories while readme is a file.
cd into the
bin directory by typing
cd bin . You’ll notice that the current directory changes to
bin in the command prompt (remember we did a breakdown of the command prompt in the previous lesson).
pwd here displays the following path
/usr/local/bin and this simply means that in terms of hierarchy we are currently in the
bin directory which is in the
local directory which is in the
usr directory which in turn is in the
/ means root directory.
Navigating Up the Directory Hierarchy
To go a level higher, in other words to go back to the local directory, we can simply type
cd .. . Doing so will take you back to the local directory and the reason behind this is that
.. means a level higher in the directory hierarchy.
You can go up several levels at once. Make sure you are in the
local directory and type
cd bin . Once in the
bin directory type
cd ../.. . This will take you two levels up the directory hierarchy and place you in the
Navigating Directly To Directories
cd command takes a relative or absolute path as an argument (as you’ve seen above). This means that if you know the path of a specific directory you want to navigate to, you can supply the full path to the directory and the
cd command will take you there. This is exactly what we did when we moved to the local directory by typing
cd /usr/local at the start of this lesson.
Finding your way around a Linux operating system via the terminal is a core skill. Nearly all you’ll ever do with the operating system would rely on your ability to move around.
The next lesson in this course is Basic Linux File Management.