Skip to main content

Day 3 Task: Basic Linux Commands

Day 3 Task: Basic Linux Commands




Task: What is the linux command to



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.

To create another file Colors.txt and to view the content.

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

Solution:-

ls - The ls is the list command in Linux. It will show the full list or content of your directory.

ls -a - you can see the whole list of files, including the hidden files.

ls -l - The ls command will only display the files.

ls -d */ - If you only want to display the sub-directories excluding all other files, you can

use this command

ls -g - If you don't want to display the owner information in your list

ls -lg - f you don't want to display the group information in your list

ls --color=[VALUE] - This command is used to colourize and decolourize the list.

**ls ~ -**it shows the contents of the home directory.

ls ../ - This command contains the list of the parent directory.

sudo - The Linux sudo command stands for Super User Do.

Sudo -V - It stands for version.

sudo -l - It stands for list.

sudo -h - The h stands for help in this option.

pwd - stands for Print Working Directory. It prints the path of the working directory, starting from the root.

$cat filename

it will show the content of the given file

cat file1 file2

This will show the content of file1 and file2

cat -n filename

It will show content with line number

cat > newfile

Will create a file named newfile

$cat "filename1" "filename2" "filename3" > "merged_filename"

The content will be copied in destination file

$cat file1 >> file2

Will append the contents of one file to the end of another file

$tac filename

Will display content in reverse order

$cat "filename1" "filename2" "filename3" > "merged_filename"

Will merge the contents of file in respective order and will insert that content in "merged_filename".

$cat *.txt

Will show the content of all text files present in the folder.

$cat >> safia.txt

The newly added text.

Will append the text "The newly added text." to the end of the file.

1.To view what's written in a file.

cat - This is the simplest and perhaps the most popular command to view a file in Linux.

nl - The nl command is almost like the cat command. The only difference is that it prepends line numbers while displaying the text in the terminal.

less - Less command views the file one page at a time.

**head-**head command is another way of viewing text files but with a slight difference. The head command displays the first 10 lines of a text file by default.

tail - it is similar and yet opposite to the head command. While the head command displays the file from the beginning, the tail command displays the file from the end.

2.To change the access permissions of files.

chmod +rwx filename to add permissions

chmod -rwx directory name to remove permissions.

chmod +x filename to allow executable permissions.

chmod -wx filename to take out write and executable permissions.

To check which commands you have run till now.
history - command is used to view the previously executed command.

To remove a directory/ Folder.
Use the rmdir or rm -d command to remove empty directories.

Use the rm -r command to remove non-empty directories.

5.To create a fruits.txt file and to view the content.

vim fruits.txt

apple

banana

mango

pineapple

guava

:wq

6.
Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

vim devops.txt

apple

mango

banana

Comments

Popular posts from this blog

Day 04 — Basic Linux Shell Scripting

Explain in your own words and examples, what is Shell Scripting for DevOps. What is #!/bin/bash? can we write #!/bin/sh as well? Write a Shell Script which prints I will complete #90DaysOofDevOps challenge Write a Shell Script to take user input, input from arguments and print the variables. Write an Example of If else in Shell Scripting by comparing 2 numbers Was it difficult? 1. What is Kernel The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. 2. What is Shell A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal. 3. What is Linux Shell Scripting? A shell script is a

NGINX Web App Deployment for DevOps

  Step 1: Create AWS instance. Step 2: Install NGINX Step 3: Install docker and create a Container for note-app. Step 4: Set up a reverse proxy. Step 5: Copy the code to the root folder. Step 6: Connect the database nginx specification Step 1: Create AWS instance. Log in to the AWS account and create an ec2 server. Nginx is a web server that will serve you static web files. So we require a server. - Create an EC2 instance and name it 'nginx-project-demo'. Also, don't forget to allow HTTP and HTTPS traffic. ( For sake of practice, let's select an Ubuntu machine with t2.micro instance type) Update your server using the command.   sudo apt-get update Step 2: Install NGINX Now install Nginx using the command below. sudo apt install nginx Check the status of nginx. systemctl status nginx Restart the nginx server with root user permission. sudo systemctl restart nginx To check further nginx is successfully installed on your server is to use the server IP and paste it into the

Day 2 Task: Basics Linux command

 Day 2 Task: Basics Linux command Task: What is the linux command to  1. Check your present working directory. 2. List all the files or directories including hidden files. 3. Create a nested directory A/B/C/D/E Ans:- 1. "pwd" is command to check present working directory on linux machine. 2. "ls -la" is command to list all the files or directories including hidden files. in above command, "-l" is use for list the files and directories in long list format with extra information and "a" is use for list all including hidden files and directory in linux machine. 3. To create a nested directory use following command :- "mkdir -p A/B/C/D/E"  "-p" stands for "no error if existing, make parent directories as needed" showing the nested directory in linux machine use "tree" command.. Listing commands - ls -l --> list the files and directories in long list format with extra information - ls -a --> list all inclu