Table of contents
View the content of a file and display line numbers.
cat -n filename
Change the access permissions of files to make them readable, writable, and executable by the owner only.
chmod 700 filename
chmod 700 file1 file2 file3
- for multiple filesCheck the last 10 commands you have run.
history | tail -10
Remove a directory and all its contents.
rm -r /path/to/directory
rm
used to remove and-r
is used to do recursiveCreate a
fruits.txt
file, add content (one fruit per line), and display the content.create file and add fruits in ->
echo -e "Apple\nBanana\nCherry\nDate\nElderberry" > fruits.txt
display the content ->
cat fruits.txt
Add content in
devops.txt
(one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava. Then, append "Pineapple" to the end of the file.creating file and adding initial contents ->
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
appending Pineapple to the end of the file ->
echo "Pineapple" >> devops.txt
verify/display ->
cat devops.txt
Show the first three fruits from the file in reverse order.
getting first three ->
head -n 3 devops.txt
reverse the order ->
head -n 3 devops.txt | tac
Show the bottom three fruits from the file, and then sort them alphabetically.
getting last three ->
tail -n 3 devops.txt
sorting in alphabetical order ->
tail -n 3 devops.txt | sort
Create another file
Colors.txt
, add content (one color per line), and display the content.creating file and adding content into ->
echo -e "Red\nBlue\nGreen\nYellow\nOrange\nPurple\nPink" > Colors.txt
display the content ->
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.creating file and adding colors in it ->
echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
prepend yellow on the top of the file ->
sed -i '1s/^/Yellow\n/' Colors.txt
Find and display the lines that are common between
fruits.txt
andColors.txt
.sorting both the files ->
sort fruits.txt > sorted_fruits.txt
sort Colors.txt > sorted_colors.txt
using 'comm' command to find the common lines ->
comm -12 sorted_fruits.txt sorted_colors.txt
Count the number of lines, words, and characters in both
fruits.txt
andColors.txt
.for fruits.txt ->
wc fruits.txt
for colors.txt ->
wc Colors.txt