Table of contents
- To view what's written in a file.
- To change the access permissions of files.
- To check which commands you have run till now.
- To remove a directory/ Folder.
- To create a fruits.txt file and to view the content.
- Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
- To Show only top three fruits from the file.
- To Show only bottom three fruits from the file.
- 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.
- To find the difference between fruits.txt and Colors.txt file.
#90daysofdevops #trainwithsubham
To view what's written in a file.
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
To change the access permissions of files.
some times, we need to change permissions for a file then,
To change directory permissions in Linux, use the following:
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.
What are the three permission groups?
There are three options for permission groups available to you in Linux. These are
owners: these permissions will only apply to owners and will not affect other groups.
groups: you can assign a group of users specific permissions, which will only impact users within the group.
all users: these permissions will apply to all users, and as a result, they present the greatest security risk and should be assigned with caution.
What are the three kinds of file permissions in Linux?
There are three kinds of file permissions in Linux:
Read (r): Allows a user or group to view a file.
Write (w): Permits the user to write or modify a file or directory.
Execute (x): A user or group with execute permissions can execute a file or view a directory.
Changing Linux permissions in numeric code
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.
To check which commands you have run till now.
syntax: history
To remove a directory/ Folder.
syntax: rm filename
If we need to remove a file forcefully. then, rm -f filename
If we need to remove an empty directory rmdir filename
If we need to remove a nested directory forcefully. which is not empty then, rm -r directoryname.
To create a fruits.txt file and to view the content.
syntax: touch fruits.txt
cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
note: after writing in vi editor press :wq
to save and exit
To Show only top three fruits from the file.
To Show only bottom three fruits from the file.
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.
To find the difference between fruits.txt and Colors.txt file.
syntax: diff fruits.txt colors.txt
Thanks for reading. please like this blog.
thank you, trainwithsubham