Running commands on the Linux terminal allows you to interface with your operating system and do numerous activities easily. The terminal, often known as the command line or shell, is a text-based interface that allows you to communicate with the computer's operating system by typing commands rather than using a graphical user interface (GUI).
Let's dive into some sample commands and see how tasks are accomplished:
Task - 1
Solution: Run the clear command on the terminal
Task - 2
Solution: Run the pwd command
Task - 3
Solution: Run the mkdir devops command first and then run ls to see if the directory was created.
Task - 4
Solution: Run the cd devops first if you are in a home directory and then run the touch command to create the file in the devops directory so below are the three commands to run:
cd devops
touch firstfile.txt
ls
Task - 5
Solution: First perform the directory check if you are in the devops directory using the pwd command. Once this is confirmed, you can now perform the file creation using the touch command. The touch {<start#>..<end#>} command creates the desired number of files. The series of commands to execute are as follows:
pwd
touch file{1..10}.txt
ls
Task - 6
Solution: To create nested directories, you can run the command mkdir command with a "-p" switch. Now, if we just use ls, this will show us the one folder that has been created and that holds the rest of the folders within. But the command "tree", shows us the nested folders created.
PS: You may additionally need to run the commands to use the command tree if you are using Linux or any of its flavors for practice on the AWS console. I had to run sudo yum install tree" which made the tree command available for me on the Linux machine I was using for practice. The series of commands are as follows:
mkdir -p Folder1/Folder2/Folder3/
sudo yum install tree (depends on the flavor, for Linux it will be yum install, ubuntu would be apt install etc..)
tree
Task - 7
Solution: First use the touch command to create the file. Once created, use the vim <filename> to edit this file. Press "i" to enter the insert mode, once done use the "esc" button from the keyboard alongside ":wq". This should save the edit and close the file. Finally, to check if this has succeded, you can execute "cat <filename>" to read the contents of the file on the console.
Below are the series of commands:
touch newfile.txt
vim newfile.txt
i (for inserting the content)
This is a test file to understand the commands.
"esc" (button from keyboard) :wq
cat newfile.txt
Task - 8
Solution: first run the command ls -al which gives the list of all the files and permissions to the file. Review the information mentioned in this article to understand what number can be used. Now once you decide, use the chmod command to change the file permissions. Now use the same ls -al command to verify on the changed permissions. I wanted to change the file permissions to read-only here, so I have used 400. Here is a set of commands to execute the request from the user:
ls -al
chmod 400 newfile.txt
ls -al
Though this was a small demo of what the commands can do, I am pretty sure this blog was interesting to read and understand how the terminal in an OS can be a game changer.
Conclusion
Running commands on Linux can ease our tasks and reduce the time consumption needed to execute the commands manually.
More commands to follow and more illustrations to follow in the next blog! Wait for it!
Happy learning!