Basics Linux Commands, 
Part 2

Basics Linux Commands, Part 2

Command to Create a Directory

mkdir <directory-name>
mkdir -v <directory-name>

mkdir command is used to create directory in Linux

-v, --is used to print the action that is performed

Command to Create a Nested Directory (A/B/C/D/E)

mkdir -p A/B/C/D/E

mkdir command is used to create directory in Linux and -p makes parent directories as needed

-p, --makes parent directories as needed

Command to remove Directory/Folder in Linux?

To remove an empty directory,

rmdir <directory-name>

To remove empty directories,

rm -r <directory-name>

Here, -r means recursively, Or, it is used to delete the directory which consits of files inside it

Command to create a color.txt file and to view the content?

To create a file "touch" command is used,

touch <filename>

To view the content of a file, the "cat" command is used,

cat <filename>

Command to Add content in color1.txt

First create a file with "touch" command,

Example: touch color1.txt

Open color1.txt file with nano editor,

vim, nano editors are used to add content to a file.

Example: nano color1.txt

After adding content to the file press ctrl+x and y to save the file

Command to show only top three fruits from the file?

head -3 <filename>

In the above command, the "head" command gives us first part of a file.

-3, --shows the top 3 lines of a file.

Command to Show only bottom three fruits from the file.

tail -3 <filename>

In the above command, the "tail" command gives us last part of a file.

-3, --shows the bottom 3 lines of a file.

Command to find the difference between two files in Linux

Let's create one file named color.txt

nano color.txt

add content to this file

Now, to find the difference between these files we simply run diff command

 diff color.txt color1.txt