Day 3: Linux Commands Decoded: Elevate Your Tech Game with Simple and Powerful Basics!
Table of contents
- Introduction
- Tasks
- 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
- Command to create fruits.txt and view to content
- Add conent in devops.txt (one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava
- To show only top 3 fruits from the file
- To show only bottom 3 fruits from the file
- To create another file colors.txt and to display the content
- Add content in colors.txt (one in each line) - Red, Pink, White, Blue, Purple, Black, Orange, Grey
- Find Difference between fruits.txt and colors.txt
- Summary:
Introduction
Linux commands may seem daunting at first, but they're the key to navigating and controlling your system. Let's break down some basic Linux commands in simple language:
Tasks
To view what's written in a file.
In Linux, the cat
command stands for "concatenate" and is used to display the contents of a file.
To display the content of a file:
cat filename.txt
To change the access permissions of files.
the chmod
command in Linux is used to change the access permissions of a file or directory.
To make a script executable:
chmod +x script.sh
before/after changing permission
To check which commands you have run till now.
the history
command in Linux is used to display a list of recently executed commands in the terminal.
- to check history of your commands
history
To remove a directory/folder
the rm -r
command in Linux is used to remove directories (folders) and their contents.
- to remove directory/folder
rm -r foldername/directory_name
rm
: Stands for "remove," and it is used for deleting files or directories.-r
: Stands for "recursive." This option allowsrm
to delete not only the specified directory but also its entire contents, including subdirectories and files.
Command to create fruits.txt and view to content
To create a file named fruits.txt
and view its content, you can use a combination of the touch
and cat
commands.
- Create the
fruits.txt
file:
touch fruits.txt
- Add some contents to fruits.txt
echo "Apple" >> fruits.txt
echo "Banana" >> fruits.txt
echo "Orange" >> fruits.txt
- To view the contents of fuits.txt
cat fruits.txt
Add conent in devops.txt (one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava
You can use a single echo
command with the help of a newline character to add all the fruits to the devops.txt
file at once.
echo -e
: Enables interpretation of backslash escapes, including the newline character."Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava"
: Represents the list of fruits, each separated by a newline character (\n
).> devops.txt
: Redirects the output to thedevops.txt
file, overwriting its content if it already exists.
echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
To show only top 3 fruits from the file
To show only the top 3 fruits from the devops.txt
file, you can use the head
command.
- To show top 3 fruits from devops.txt
head -n 3 devops.txt
To show only bottom 3 fruits from the file
To show only the bottom 3 fruits from the devops.txt
file, you can use the tail
command.
- To show bottom 3 fruits from devops.txt
tail -n 3 devops.txt
To create another file colors.txt and to display the content
You can use the touch
command to create the Colors.txt
file and then use a text editor or the echo
command to add content. Here's a set of commands to achieve this:
Create the
Colors.txt
file:touch Colors.txt
This command creates an empty file named
Colors.txt
in the current directory.Add content to
Colors.txt
: You can use a text editor or theecho
command to add content. Here's an example usingecho
:echo "Red" >> Colors.txt echo "Blue" >> Colors.txt echo "Green" >> Colors.txt echo "Yellow" >> Colors.txt
View the content of
Colors.txt
:cat Colors.txt
The
cat
command displays the content of theColors.txt
file on the terminal.The file shown is blank because I have't wrote anything in the file.
Add content in colors.txt (one in each line) - Red, Pink, White, Blue, Purple, Black, Orange, Grey
You can use a single echo
command with the help of a newline character to add all the fruits to the colors.txt
file at once.
echo -e
: Enables interpretation of backslash escapes, including the newline character."Red\nPink\nWhite\nBlue\nPurple\nBlack\nOreange\nGrey"
: Represents the list of fruits, each separated by a newline character (\n
).> colors.txt
: Redirects the output to thecolors.txt
file, overwriting its content if it already exists.
echo -e "Red\nPink\nWhite\nBlue\nPurple\nBlack\nOreange\nGrey" > colors.txt
Find Difference between fruits.txt and colors.txt
To find the differences between the contents of fruits.txt
and Colors.txt
files, you can use the diff
command.
- To find difference between fruits.txt and colors.txt
diff fruits.txt Colors.txt
Summary:
This comprehensive guide introduces essential Linux concepts and commands in a beginner-friendly manner. Key tasks covered include viewing file contents with the 'cat' command, modifying access permissions using 'chmod,' checking command history with 'history,' and removing directories/folders using 'rm -r.' The guide also explains creating and viewing files, adding content in bulk, and displaying top and bottom lines with 'head' and 'tail' commands. Additionally, it covers creating another file, such as 'Colors.txt,' and finding differences between files using the 'diff' command. Overall, this guide provides a foundational understanding of Linux commands, empowering users to navigate and manage their systems effectively.
"Fuel my passion and support my journey by clicking 'Buy me a coffee' today!"
~Dipen : )