Day 3 : DevOps ❤️
Table of contents
Let's Discuss some more questions on Linux
To view what's written in a file.
cat file_name
- Change the access permissions of files to make them readable, writable, and executable by the owner only.
chmod 700 file_name
permission_code :
Read: 4
Write: 2
Execute: 1
\=> Users:Groups: Others
For Ex: chmod 700 file.sh
The above command means that users have all the 3 permissions (i.e. read, write, execute) on the other hand groups, and others have no permissions.
Check the last 10 commands you have run.
history | tail -n 10
To remove a directory/ Folder
rm -r folder_name
-r = recursively (used if the folder is not empty)
Create a
fruits.txt
file, add content (one fruit per line), and display the content.touch fruits.txt cat fruits.txt
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava
echo "Apple" > devops.txt echo "Mango" >> devops.txt echo "Banana" >> devops.txt echo "Cherry" >> devops.txt echo "Kiwi" >> devops.txt echo "Orange" >> devops.txt echo "Guava" >> devops.txt
Show the first three fruits from the file in reverse order.
head -n 3 devops.txt | tac
Show the bottom three fruits from the file, and then sort them alphabetically.
tail -n 3 devops.txt | sort
Create another file
Colors.txt
, add content (one color per line), and display the content.touch Colors.txt cat Colors.txt
Add content in
Colors.txt
(one in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey. Then, prepend "Yellow" to the beginning of the file.echo "Yellow" | cat - devops.txt > temp && mv temp devops.txt
Find and display the lines that are common between
fruits.txt
andColors.txt
.sort file1.txt -o fruits.txt sort file2.txt -o Colors.txt comm -12 fruits.txt fruits.txt
Count the number of lines, words, and characters in both
fruits.txt
andColors.txt
.wc fruits.txt wc Colors.txt