Table of contents
- Introduction π
- 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.
- 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.
Introduction π
Welcome to Day 3 of the exciting #90DaysOfDevOps challenge! Today, we're embarking on a fascinating exploration of the world of Linux commands, like enchanted keys that unlock the full potential of every DevOps engineer! With these powerful tools at your disposal, navigating your Linux system becomes as effortless as embarking on a well-charted journey. ππΊοΈπ» So, gear up for a tech-packed adventure! Together, we'll uncover the secrets of essential Linux commands, revealing hidden gems that will elevate your skills to new heights. The air is filled with anticipation as we dive into this epic DevOps quest! Let's set forth on this thrilling journey! ππ»
To view what's written in a file.
To view the contents of a file in Linux, you can use various command-line tools. The most common ones are cat
, less
, and more
.
To change the access permissions of files.
In Linux, you can change the access permissions of files using the chmod command. The chmod command allows you to modify the read, write, and execute permissions for the owner, group, and other users.
To check which commands you have run till now.
To check the commands you have run previously in Linux, you can make use of the command history. The history command allows you to view a list of previously executed commands in the current session. Here's how you can use it:
To remove a directory/ Folder.
To remove a directory (or folder) in Linux, you can use the rm
command with the -r
option. The -r
flag stands for "recursive" and is used to delete directories and their contents.
To create a fruits.txt file and to view the content.
To Create a file we can use various commands such touch, cat, vim, nano but touch is the most widely used command used to create files
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
To add content to a file either we can use cat command or we can just use an editor such as vim,nano etc.
You can use a text editor "vim" or the "echo" command to append each fruit on a new line.
echo [option] [list] > <filename>
Vim - To open a file to add content
Simply type vim filename Press Enter
Inserting Text: To start inserting or editing text within the file, press i for insert mode. You can then type or modify text as needed.
Saving and Exiting: To save the changes and exit vim, press Esc to ensure you are in normal mode, and then type :wq or ZZ (Shift + zz) Press Enter
The echo
command is used in Unix-like operating systems to display text or variables in the terminal. The -e
option in the echo
command enables the interpretation of escape sequences in the text to produce special formatting effects. Escape sequences are sequences of characters that start with a backslash \
In this example, \n
is an escape sequence that represents a newline character, so it causes the text to be displayed on two separate lines.
Here are a few commonly used escape sequences with echo -e
:
\n
: Inserts a newline character.\t
: Inserts a tab character.\\
: Inserts a backslash.\b
: Inserts a backspace.\r
: Inserts a carriage return.
You can use these escape sequences to format the output of the echo
command in various ways.
To Show only top three fruits from the file.
To Show only top three fruits from the file. To show only top three fruits we will use head command. The Linux head command prints the first lines of one or more files to standard output. By default, it shows the first 10 lines. We can pass a -n, where n show the specified number of line Syntax
To Show only bottom three fruits from the file.
To Show only bottom three fruits from the file. To show only the bottom three fruits from the "devops.txt" file, you can use the "tail" command to display the last few lines of the file, like this: tail -n 3 devops.txt
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
To add content to a file either we can use cat command or we can just use an editor such as vim,nano etc.
To find the difference between fruits.txt and Colors.txt file.
To find the differences between two files in Linux, such as "fruits.txt" and "Colors.txt," you can use the diff
command.