The most frequent tasks that you perform on your PC is creating, moving or deleting Files. Let's look at various options for File Management.

To manage your files, you can either use

  1. Terminal (Command Line Interface - CLI)
  2. File manager (Graphical User Interface -GUI)

In this tutorial, you will learn-

Please be patient. The Video will load in some time. If you still face issue viewing video click here

Why learn Command Line Interface?

Even though the world is moving to GUI based systems, CLI has its specific uses and is widely used in scripting and server administration. Let's look at it some compelling uses -

  • Comparatively, Commands offer more options & are flexible. Piping and stdin/stdout are immensely powerful are not available in GUI
  • Some configurations in GUI are up to 5 screens deep while in a CLI  it's just a single command
  • Moving, renaming 1000's of the file in GUI will be time-consuming (Using Control /Shift to select multiple files), while in CLI, using regular expressions so can do the same task with a single command.
  • CLI load fast and do not consume RAM compared to GUI. In crunch scenarios this matters.

Both GUI and CLI have their specific uses. For example, in GUI, performance monitoring graphs give instant visual feedback on system health, while seeing hundreds of lines of logs in CLI is an eyesore.

You must learn to use both GUI(File Manager) and CLI (Terminal)

GUI of a Linux based OS is similar to any other OS. Hence, we will focus on CLI and learn some useful commands.

Launching the CLI on Ubuntu

There are 2 ways to launch the terminal.

1) Go to the Dash and type terminal

Terminal V/s File Manager &  The CD command

2) Or you can press CTRL + Alt + T to launch the Terminal

Once you launch the CLI (Terminal), you would find something as guru99@VirtualBox(see image) written on it.

Terminal V/s File Manager &  The CD command

1) The first part of this line is the name of the user (bob, tom, ubuntu, home...)

2) The second part is the computer name or the host name. The hostname helps identify a computer over the network. In a server environment, host-name becomes important.

3) The ':' is a simple separator

4) The tilde '~' sign shows that the user in working in the home directory. If you change the directory, this sign will vanish.

Terminal V/s File Manager &  The CD command

In the above illustration, we have moved from the /home directory to /bin using the 'cd' command. The ~ sign does not display while working in /bin directory. It appears while moving back to the home directory.

5) The '$' sign suggests that you are working as a regular user in Linux. While working as a root user, '#' is displayed.

Terminal V/s File Manager &  The CD command

Present Working Directory

The directory that you are currently browsing is called the Present working directory. You log on to the home directory when you boot your PC. If you want to determine the directory you are presently working on, use the command -

pwd

Terminal V/s File Manager &  The CD command

pwd command stands for print working directory

Above figure shows that /home/guru99 is the directory we are currently working on.

Changing Directories

If you want to change your current directory use the 'cd' command.

cd /tem

Consider the following example.

Terminal V/s File Manager &  The CD command

Here, we moved from directory /tmp to /bin to /usr and then back to /tmp.

Navigating to home directory

If you want to navigate to the home directory, then type cd.

Terminal V/s File Manager &  The CD command

cd

You can also use the cd ~ command.

Terminal V/s File Manager &  The CD command

cd ~

Moving to root directory

The root of the file system in Linux is denoted by '/'. Similar to  'c:\' in Windows.

Note: In Windows, you use backward slash "\" while in UNIX/Linux, forward slash is used "/"

Type 'cd /' to move to the root directory.

cd /

Terminal V/s File Manager &  The CD command

TIP: Do not forget space between cd and /. Otherwise, you will get an error.

Navigating through multiple directories

You can navigate through multiple directories at the same time by specifying its complete path.

Example: If you want to move the /cpu directory under /dev, we do not need to break this operation in two parts.

Instead, we can type '/dev/cpu' to reach the directory directly.

cd /dev/cpu

Terminal V/s File Manager &  The CD command

Moving up one directory level

For navigating up one directory level, try.

cd ..

Terminal V/s File Manager &  The CD command

Here by using the 'cd ..' command, we have moved up one directory from '/dev/cpu' to '/dev'.

Then by again using the same command, we have jumped from '/dev' to '/' root directory.

Relative and Absolute Paths

A path in computing is the address of a file or folder.

Example - In Windows

C:\documentsandsettings\user\downloads
In Linux
/home/user/downloads

There are two kinds of paths:

1. Absolute Path:

Let's say you have to browse the images stored in the Pictures directory of the home folder 'guru99'.

The absolute file path of Pictures directory /home/guru99/Pictures

To navigate to this directory, you can use the command.

cd /home/guru99/Pictures

Terminal V/s File Manager &  The CD command

This is called absolute path as you are specifying the full path to reach the file.

2. Relative Path:

The Relative path comes in handy when you have to browse another subdirectory within a given directory.

It saves you from the effort to type complete paths all the time.

Suppose you are currently in your Home directory. You want to navigate to the Downloads directory.

You do no need to type the absolute path

cd /home/guru99/Downloads

Terminal V/s File Manager &  The CD command

Instead, you can simply type 'cd Downloads' and you would navigate to the Downloads directory as you are already present within the '/home/guru99' directory.

cd Downloads

Terminal V/s File Manager &  The CD command

This way you do not have to specify the complete path to reach a specific location within the same directory in the file system.

Summary:

  • To manage your files, you can use either the GUI(File manager) or the CLI(Terminal) in Linux. Both have its relative advantages. In the tutorial series, we will focus on the CLI aka the Terminal
  • You can launch the terminal from the dashboard or use the shortcut key Cntrl + Alt + T
  • The pwd command gives the present working directory.
  • You can use the cd command to change directories
  • Absolute path is complete address of a file or directory
  • Relative path is relative location of a file of directory with respect to current directory
  • Relative path help avoid typing complete paths all the time.
Command
Description

cd or cd ~

Navigate to HOME directory

cd ..

Move one level up

cd

To change to a particular directory

cd /

Move to the root directory

 

YOU MIGHT LIKE: