Using a Linux machine for beginners.
Tags: webdev, azureapril, beginners, bash
Published: 2023-06-30 17:44:59

Linux is an open source operating system, unlike windows, its environment, is constantly being updated by contributors. Developers can easily access the Linux source code for customization. Linux offers a higher degree of security, stability , and require little disk space. It has powerful networking capabilities and gives the user power over the machine. Linux is so popular that Android used on mobile are built on its framework.

In this guide I will show you some of the few basic commands to know to get started.
To begin, you will need to download and install Linux on your workstation. Be reminded that Linux comes in different distributions such as Ubuntu, CentOS, Debian, Fedora, Xubuntu, Arch etc.

**1 sudo su** - This is the first command that gives you root access over you machine , without it you cannot not run any command on you machine. Depends on the configuration it may require you for password.  `sudo su`

![ubuntu02](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t23oobks8pg9dvjhkeqe.png)
You will see we do not have permissions to install a web server nginx without doing **sudo su**.

![ubuntu04](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70ydka2ggvimfahwbn3j.png)
**2 apt update** - It is used to update the package index files in the system which contains information about available packages and their version. `apt update`

![ubuntu05](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svetxyox4hkw7n2xch1o.png)
**3 mkdir** - The function creates a new empty directory /folder in windows machine, whose name is defined by path. You supply the name as an argument. The **rmdir** is used to remove directories, only when there is no file inside it. To remove dir classrep,

![ubuntu06](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzc8o4x59y0zxxxuqy48.png)
 

![ubuntu09](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t837npzdheowengmfwtg.png)
 
**4 list**: This is a very powerful and commonly used command. `ls`, without any options list files and directories in plain format without displaying much information, like file types, permissions, modified date and time etc. Some of these options includes:

4.1 list in reverse order : `ls -r`
4.2 To list permission of files and other attributes such as folder name, size and modified date and time. `ls -l`
4.3 Using this syntax further modifies your listing to become human readable.it becomes easy to understand. `ls -lh `,To learn more about more,[click](https://www.digitalocean.com/community/tutorials/ls-command-in-linux-unix)
![ubuntu08](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0i6alwapo2100larx1w1.png)

**5 Print working directory** : This command displays the [path of the working directory](https://www.geeksforgeeks.org/pwd-command-in-linux-with-examples/) starting from the root. Its a shell in-built command.`pwd`
**Pwd [options]**
5.1 "L": Path resolves symbolic link and prints the path of the target
5.2 "P": Displays the actual path without resolving the symbolic link.

**6 Creating text files(touch)**: When we want to create text files , use the command `touch file_name`'. It is used to creates a file without any content. to create a file with a content, use 'cat command'.
The [touch](https://www.geeksforgeeks.org/touch-command-in-linux-with-examples/) command can also create multiple files in one command

```
touch file1.txt file2.txt file3.txt
```
**Note**
use one space as the separator.

![ubuntu10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/luo70oflc6l5efvd8qzj.png)
**7 concatenate (cat)** - This is a very useful command in Linux, it helps us view, create and concatenate files. Concatenate is reading data from file and giving their content as output.
**Some useful cat commands are below** 
7.1 View the content of filename1: 

```
cat file_name1
```
7.2 This is used to view multiple files: 

```
cat file_1 file_2 
```
7.3View content of a file preceding by number line : 

```
cat -n file_1
```
7.4 This command creates a new file :

```
 cat > file_1 
```

![ubuntu11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tabtp7kqq4x198px0vrk.png)
In the next graphic we can see how we view content of a file, click the [link](https://www.geeksforgeeks.org/cat-command-in-linux-with-examples/) to learn more 

![ubuntu12](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7i7ekmynahrjli1439yb.png)

**8 copy (cp)** - This is the copy command in Linux, used to copy files and directories from one location to another.
`cp [source] [destination]`,to do this navigate to the folder where the file to be copied is located , and specify its filename and the path where it is to be stored.

![ubuntu13](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54yew1uh022jpxu1gira.png)

![ubuntu14](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtzfl2ytvpzkosizud6u.png)
8.1 copying  multiple files - We do this using the command 

```
cp text1.txt text2.txt text3.txt /home/user/destinationfolder/

```

![ubuntu15](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvcakl7hb6zmnfcww2h6.png)
The above diagram shows us when we are copying the files ,file1txt,file2.txt,file3.txt from their source folder "Businessclass" to destination folder "learn".

**9 Change directory cd** - This command changes the current working directory to another one specified `cd`
9.1 changing to previous: Adding a dash(-) returns you to your previous directory. `cd -`

9.2 Home directory: The absence of the current directory path shows you are at the home directory. Use the command `cd` to go to home, also when you use the command `cd ~`  it takes you to the home directory.

![ubuntu16.1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fki33d2ldkygbpa15oqy.png)
As you see above there is no path. Using cd ~ does the same thing as above.

![ubuntu16.2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dh8u84y3wk0l7y2t9lwq.png)
We can use the cd command to do a lot in Linux [workspace ](https://phoenixnap.com/kb/linux-cd-command)
10** exit** : It takes a parameter[N], and return the status as [N], if it is not provided, it returns back to its previous status.
![ubuntu17.1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfhipakeo56zmn0lci5v.png)

**File Editors in Linux**
We have many text editors in Linux like vi, vim, GNU Nano, gEdit and more. In this exercise we will focus on using vi.

#### To create and edit a file using vi
On your machine follow this step
1 type vi filename , It opens a file with the name specified or creates a new file .

![ubuntu18](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8p8vl15y6izlh5qv11mh.png)
2 Press **i** on your keyboard to start editing ,

![ubuntu19](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2ol7k3tdmc9ronprjg3.png)
3 After editing Press ESC to exit insert mode.
Then use “:wq!” to save and exit editor or “:q!” to exit editor without saving.
**Using vi to create a text file and saved in a folder Hagital**
1 Create the directory "Hagital" with mkdir  command.

![ubuntu18](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g12lw64i2sca1cqhkvkh.png)