# DAY-3 Basic Linux Commands

#90daysofdevops #trainwithsubham

## *<mark>To view what's written in a file.</mark>*

First, we need to create a file then, we will add some lines there. then, we will see what is written there.

syntax: `echo hello good morning > hello.txt` `cat hello.txt`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679644100451/2dfbe19c-173d-4d35-994b-9cb9c7e43cdd.png align="left")

## *<mark>To change the access permissions of files.</mark>*

some times, we need to change permissions for a file then,

<mark>To change directory permissions in Linux, use the following:</mark>

* chmod +rwx filename to add permissions
    
* chmod -rwx directoryname to remove permissions. 
    
* chmod +x filename to allow executable permissions.
    
* chmod -wx filename to take out write and executable permissions.
    

*Note that “r” is for read, “w” is for write, and “x” is for execute.* 

*This only changes the permissions for the owner of the file.*

<mark>What are the three permission groups?</mark>

There are three options for permission groups available to you in Linux. These are

* <mark>owners</mark>: these permissions will only apply to owners and will not affect other groups.
    
* <mark>groups:</mark> you can assign a group of users specific permissions, which will only impact users within the group.
    
* <mark>all users:</mark> these permissions will apply to all users, and as a result, they present the greatest security risk and should be assigned with caution.
    

<mark>What are the three kinds of file permissions in Linux?</mark>

There are three kinds of file permissions in Linux:

* <mark>Read (r):</mark> Allows a user or group to view a file.
    
* <mark>Write (w):</mark> Permits the user to write or modify a file or directory.
    
* <mark>Execute (x):</mark> A user or group with execute permissions can execute a file or view a directory.  
    

<mark>Changing Linux permissions in numeric code</mark>

Permission numbers are:

* 0 = ---
    
* 1 = --x
    
* 2 = -w-
    
* 3 = -wx
    
* 4 = r-
    
* 5 = r-x
    
* 6 = rw-
    
* 7 = rwx
    

For example:

* chmod 777 folder name will give read, write, and execute permissions for everyone.
    
* chmod 700 folder name will give read, write, and execute permissions for the user only.
    
* chmod 327 folder name will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679644822479/4bb1ff71-6449-4cc6-a2cb-4c023e3aeaf3.png align="left")
    

## *<mark>To check which commands you have run till now.</mark>*

syntax: `history`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679645060594/cf2d658d-38b3-46c4-8b25-ad97595c0fe9.png align="left")

## *<mark>To remove a directory/ Folder.</mark>*

syntax: `rm filename`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679645500668/ac1a541a-8fc3-41c2-b3bb-2476f38151be.png align="left")

If we need to remove a file forcefully. then, `rm -f filename`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679645595043/954f4338-20d7-4124-ad5f-04bf09ae6824.png align="left")

If we need to remove an empty directory `rmdir filename`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679645732645/2e7204b1-2436-418a-aad0-a55153e5cb0e.png align="left")

If we need to remove a nested directory forcefully. which is not empty then, `rm -r directoryname.`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679645843220/b26a6822-f32c-4ff7-b73b-76d8fc2723a5.png align="left")

## *<mark>To create a fruits.txt file and to view the content.</mark>*

syntax: `touch fruits.txt`

`cat fruits.txt`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679646187090/7de0de14-4c5d-40fa-a439-1039506ef0fb.png align="left")

## *<mark>Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.</mark>*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679648176476/5ce99745-63ca-46e6-a9f6-ac72f5fa4491.png align="left")

*note: after writing in vi editor press* `:wq` *to save and exit*

## *<mark>To Show only top three fruits from the file.</mark>*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679648507048/44ee0f89-57f2-497c-a96f-5096c55b47d5.png align="left")

## *<mark>To Show only bottom three fruits from the file.</mark>*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679648571975/d5023e67-906b-4425-b10b-b312efa2e6e5.png align="left")

## *<mark>To create another file Colors.txt and to view the content. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.</mark>*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679649011968/0d4b909f-e2a0-48dd-8dff-6fb26ace964d.png align="left")

## *<mark>To find the difference between fruits.txt and Colors.txt file.</mark>*

syntax: `diff fruits.txt colors.txt`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679649110876/1341cda4-ea65-40cc-9d61-f38a2de1c54f.png align="left")

Thanks for reading. please like this blog.

thank you, **trainwithsubham**
