Shell, navigation
Tags: shell, linux
Published: 2022-08-25 08:41:00

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4aydlvg5yp9cqpgzohua.jpg)
Some of the commands are:

---


## pwd

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovb9ygk5yncjev4a4q0z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/az8tn45626mlt7cmoq7k.png)

> Tip: for more info [pwd](http://linuxcommand.org/lc3_lts0020.php) or use the linux command **man pwd**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/88d11ttbmvuu5tye5iiq.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtsgzgarut7dav3yj1bg.png)

---


## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04yp9e3qt83cxcsgilr7.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnb7fhprtu8jrnfh1lmh.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0xryvag6xzzcmz5fod3.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1flhrbpckqplp3oj4kh.png)

Changing directory with absolute path concept:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pj8q6ecjl6hvrbqhvdux.png)

**Moving backward with cd**

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/crwnyx4d1od4zkajcfw6.png)

to move backward two levels 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljcm38zvzjbzb322wimj.png)

> 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](http://linuxcommand.org/lc3_lts0020.php) or use the command **man cd **


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nc2u0efgoe2spl9ct20q.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h35gx34qvs6gw3r24362.png)

---


## ls

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/15rt28b673vayxmpz9f3.png)

To list the files in the /dev directory 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rmw07ix75ks4j3504yc.png)




List the files in the working directory in long format
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwtmmwh1opue6103r05p.png)



List the files in the /bin directory and the /etc directory in long format
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ci6mlwejl394d9olbksb.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq63ga2if3a2vxuo754u.png)

> Tip: for more info [ls](http://linuxcommand.org/lc3_lts0030.php) or use the linux command **man ls**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9w2149njo2p8lsty8e7.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgzur3kyvzxfezixrccn.png)

---

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l7lw6izyvl8ikzjn4dqj.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skxqgs86wmnje5wu04xz.png)

> Tip: for more info [less](http://linuxcommand.org/lc3_lts0030.php) or use the command **man less**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1wj6oj769hpfnqdpqgv.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxhqnnq3lr50hadjghuf.png)

---

## touch

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l62spr7dnq2dmy1y1x60.png)
  
You can create multiple files with touch.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ll1d7lb2zkrbah697tzm.png)

> Tip: for more info [touch](https://linuxhint.com/touch-command-linux/) or use the command **man touch**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yce4qedftbze3f6rk0qj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fn3i9tl2teqbbca8f7kv.png)

---

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qq5z468qxg6ievtrrfyx.png)
Examples are:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qf6d9lzzzgokcd9t0ph.png)

---

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4buwab0dam45390pmk7.png)

Copy the file a.txt to the dir folder
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58athda5333sh6pobmqf.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w58l2dqy3g5q936h4y8.png)

> Tip: for more info [cp](http://linuxcommand.org/lc3_lts0050.php) or use the command **man cp**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjzm7peo5s4iwytn0bq5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxb3nwn298xbr6jf981f.png)

---

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezqsnkp9p8ipoyp49plx.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivlov636lfisp7z3bwa9.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9upcpkezp3qlgr1uklpg.png)

> Tip: for more info [mv](http://linuxcommand.org/lc3_lts0050.php) or use the command **man mv**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5nloa52i0qll9900zog.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjhjbonqq9yyr7aijppo.png)

---

## rm 

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

To remove h.txt

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfpown4yt8n2921l3ygi.png)
To remove multiple files ha.txt and load


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iul7rvb8y4ovz9icapif.png)
To remove a directory dir2

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnlz4f9qfctlc6jds4gs.png)

> Tip: for more info [rm](http://linuxcommand.org/lc3_lts0050.php) or use the command **man rm**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8kcks05nlsr5ic2pkhcr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jnbg9n6ot77r6kc9p4va.png)

---

## mkdir

we use the command mkdir to create directories. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl2dyr8tenvguiencd5a.png)

> Tip: for more info [mkdir](http://linuxcommand.org/lc3_lts0050.php) or use the command **man mkdir**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbows7gig147bajfs2bh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d6l02eq2izvyuzefr51d.png)

---

## rmdir

We use rmdir to remove empty directories.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhpqy5f84vxv5tyjq5ar.png)

> Tip: more info [rmdir](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rmdir) or use the command **man rmdir**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1pw5lsqr8rfofxsectm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3gsemoizvuc1d8f786qy.png)