"DevOps Odyssey": Day 4 - Advanced Linux Commands

User and Group Permissions
Imagine your computer system is like a big house, and you are the owner of the house. In this house, you have several rooms, each containing valuable items. Now, you don't want everyone to have access to all the rooms and items. So, you give keys to different people based on how much you trust them.
In the computer world, users are like people, and groups are like different circles of friends or family. Each user belongs to at least one group, and each group has its own set of permissions (like keys) that determine what actions they can perform on files and folders.
Check the file/directory permission
ls -l - Allows users to list directory/file contents.

Types of Permissions
There are three main types of permissions for each file or folder
Read(r): This allows users or groups to open and view the content of the file or folder.
Write(w): This allows users or groups to modify the content of the file or folder.
Execute(x): This allows users or groups to run the file (if it's a program or script) or access the contents of a folder.

owner (u) - Permissions used by owner of the file
group(g) - Permissions used by group of the file
others(o) - Permissions used by all other users
Permission with numeric type


Add read permission to user
chmod u+r filename
chmod 444 filename

Add read write permission to group
chmod g+rw filename
chmod 464 filename

Removing write permission from group
chmod g-w filename

Remember, when changing permissions, be careful not to grant more access than necessary, as it could compromise the security of your system.
grep, awk and find commands and usage

grep
grep is a powerful command-line tool used to search for specific text patterns in files. It allows you to find lines in files that contain a particular word or phrase. Think of it as a good detective searching for clues in a pile of documents.
Example: Imagine you have a bunch of recipe written in different files, and you want to find all the recipe that contain the word "fruits" You can use grep like this:
grep -r fruits /home/ubuntu

Explanation:grep searches for the word "fruits" in all text files (*.txt) in the current directory. It will display the lines that contain the word "fruits" from each matching file.
2. awk
awk is a versatile command-line tool used for text processing and data manipulation. It works by processing data line by line and allows you to perform various operations on specific fields (columns) in the data. Think of it as a data magician who can extract and transform information from a table of data.
Example: Let's say you have a list of students with their names and scores in a file. You can instruct AWK to print only certain columns from the input field. The following example demonstrates this. you can use awk like this:
awk '{print $3 "\t" $4}' students.txt

Explanation: awk reads each line of the students.txt file and the code within single quotes performs the operation. After processing all the lines it prints the columns as stated.
3. find
find is a command-line utility used to locate files and directories in a directory hierarchy based on various search criteria. It helps you find files anywhere on your computer system, just like a detective searching for missing items.
Example: Suppose you want to find all the files (files with extensions like .txt, in your ubuntu folder and its subdirectories. You can use find like this:
find *.txt

Explanation:find starts searching from the /ubuntu directory and provides us the result as requested.
grep helps you find text patterns in files, awk allows you to process and manipulate data, and find helps you search for files and directories based on various criteria. Together, these powerful commands make it easier to work with text and files in Linux, whether you're searching for specific information or managing your data efficiently.


