Some More Basic Linux Commands :

Some More Basic Linux Commands :

In my last blog i have mentioned about how we can use ls and the various options and how we create directories/sub directories how we can remove them.

Today lets see how we create a file in linux how we can write content in the file, how we can read the content from top and bottom in the file ,how we can redirect the content in the file what is VIM editor in Linux how we can write contents in any file using VIM and some other useful commands for day to day activities.

1) How to create a file in linux

touch : command is used to create an empty text file in linux.

2) Echo : echo command is used to display line of text/string that are passed as an argument

Syntax : echo [option] [string]

Displaying a text/string : Syntax :

echo [string]

how we can overwrite the file with the echo command?

The “\>” operator is used to replace the content of a file with the text that is returned by the echo command. The text itself is wrappen in double quotes.

Syntax : echo "some text here" > /path/to/file

ubuntu@ip-172-31-8-126:~$ echo "Welcome to Linux Family" > file1.txt

ubuntu@ip-172-31-8-126:~$ cat file1.txt Welcome to Linux Family ubuntu@ip-172-31-8-126:~$

3) cat - command is used to display the contents of the file .

ubuntu@ip-172-31-8-126:~$ echo "Lets learn Devops" > file2.txt ubuntu@ip-172-31-8-126:~$ cat file2.txt Lets learn Devops

4) VIM: Vim is an advanced and highly configurable text editor built to enable efficient text editing.

You can open vim by running vim command on the terminal.

To open a file in vim editor just write the file name after the vim command in the terminal as follows:

It will open the text editor like this:

To write some content in the file you need to go to insert mode To go into write mode type i. After going into insert mode you will see INSERT in the status bar. After that, we can write any data in it.

We have written the data into a file now the task is to save and close the file to do that first exit from insert mode by pressing the Esc key. To write a command first type semicolon ( : ) and then type the command wq! or x! (both do the same thing) And then hit ENTER.

5) Sort: This command is used to sort the results of search either alphabetically or numerically. It also sorts files and directories.

sort -r: the flag returns the results in reverse order.

sort -f: the flag does case-insensitive sorting.

sort -n: the flag returns the results as per numerical order

6) tail: This command prints the last N number of data of the given input. By default, it prints 10 lines.We can specify the number of lines, that we want to display.

7) Head : It is the complementary of Tail command. The head command, as the name implies, print the top N number of data of the given input. By default, it prints the first 10 lines of the specified files.

8) diff: command is used to find the difference between two files.

9) history : This command is used to view the previously executed command.

10) Find : It can be used to find files and directories and perform subsequent operations on them.

Syntax :

find [where to start searching from] [expression determines what to find] [-options] [what to find]

11) Free: This command displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.

12) df,dh : Df (disk free) command will have an account of available disk space, used by file system.Du (disk usage) command reports the size of directory tree including all the content.

Apart from this there are several commands you can try out which can be helpful in you day to day activities as Linux Admin/Devops Engineer

Thats all for today in the next blog we will learn the User Management concepts and also see the File Permissions in Linux.

Thanks for Reading & Happy Learning. Looking forward for the feedback!

#Devops#TrainWithShubham#LinuxisLove