DEV Community

Cover image for Shell, navigation
Haile Melaku
Haile Melaku

Posted on • Edited on

Shell, navigation

Hey guys am back today am going to show you something i think is very important for beginners.
well will start with shell navigation, this is very important topic when working with a Linux environment and we are going to see some basic navigation commands.


The first directory in the file system is called the root directory.The root directory contains files and sub directories, which contain more files and sub directories and so on and so on.

Image description
Some of the commands are:


pwd

We use the pwd command to see the name of the working directory

Image description

Image description

Tip: for more info pwd or use the linux command man pwd

Image description

Image description


cd

We use cd to change the working directory.To do this, we type cd followed by the pathname of the desired working directory.

Image description

Pathnames can be specified two different ways; absolute pathnames or relative pathnames.

Absolute path is defined as the specifying the location of a file or directory from the root directory(/).

  • Start at the root directory ( / ) and work down.

  • Write a slash ( / ) after every directory name (last one is optional)

Image description

Relative path is defined as the path related to the present working directly(pwd). It starts at your current directory and never starts with a /.

Image description

Example of Absolute and Relative Path

Suppose you are currently located in home/haile and you want to change your directory to home/haile/h. Let’s see both the absolute and relative path concepts to do this:

Changing directory with relative path concept :

Image description

Changing directory with absolute path concept:

Image description

Moving backward with cd

To move backward with cd command we use cd .. (cd followed by two dots).

Image description

to move backward two levels

Image description

If we type cd followed by nothing, cd will change the working directory to our home directory.

Tip: for more info on cd command cd or use the command *man cd *

Image description

Image description


ls

We use ls command when we want to list the contents of a directory.

Image description

To list the files in the /dev directory
Image description

List the files in the working directory in long format
Image description

List the files in the /bin directory and the /etc directory in long format
Image description

List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format
Image description

Tip: for more info ls or use the linux command man ls

Image description

Image description


less

we use less to view text files.less is a program that lets us view text files. This is very handy since many of the files used to control and configure Linux are human readable.

Image description

Image description

Tip: for more info less or use the command man less

Image description

Image description


touch

we use touch to create a file without content.The file created using touch command is empty

Image description

You can create multiple files with touch.

Image description

Tip: for more info touch or use the command man touch

Image description
Image description


before we get into the other commands we first need to learn about Wildcards

Wildcards
Wildcards allow you to select filenames based on patterns of characters. The table below lists the wildcards and what they select:

Image description
Examples are:

Image description


cp

We use cp command to copy files and directories.

Copy the file content of one file to the other
if b.txt doesn't exist it creates the b.txt file

Image description

Copy the file a.txt to the dir folder
Image description

Copy the content of dir to dir2 and if dir2 doesn't exist it creates it.

Image description

Tip: for more info cp or use the command man cp

Image description

Image description


mv

we use the mv command to moves or renames files and directories depending on how it is used.

Rename the a.txt file to load and if file load exists, its contents are silently replaced with the contents of a.txt.

Image description

The files b.txt and c.txt are moved to directory dir. If dir does not exist, mv will exit with an error.

Image description

Rename the directory dir to lp.If lp exists, the directory dir is moved within directory lp.

Image description

Tip: for more info mv or use the command man mv

Image description

Image description


rm

We use rm to remove (delete) files and directories.

To remove h.txt

Image description
To remove multiple files ha.txt and load

Image description
To remove a directory dir2

Image description

Tip: for more info rm or use the command man rm

Image description

Image description


mkdir

we use the command mkdir to create directories.

Image description

Tip: for more info mkdir or use the command man mkdir

Image description

Image description


rmdir

We use rmdir to remove empty directories.

Image description

Tip: more info rmdir or use the command man rmdir

Image description

Image description

Top comments (0)