2.Basic Command of Linux For DevOps  (Day-2 & 3)

2.Basic Command of Linux For DevOps (Day-2 & 3)

$ pwd

It stands for "Print Working Directory. It is used to print the current working directory.

pwd

$ ls

It shows the contents of a directory and it will list the contents of the current directory.

ls

$ uname

It is used to print system information such as the operating system name, version, and release number.

uname

When you entered this command it will display the kernel name

$ cd

It uses for changing the directory.

cd

$ clear

It is used for clearing the terminal or screen.

clear

$ whoami

shows the current login username.

whoami

$ history

It displays the previously used command.

history

$ date

This command prints the date.

date

Creating a File & Directory

Creating a single directory

mkdir /mbubur

Note *: if you are not logged in through the root user use sudo before the cmd.

sudo mkdir /mbubur

Creating Multiple Directory with a single cmd

mkdir dir1 dir2 dir3 dir4

For creating a Directory path ( Directory inside the Directory)

mkdir -p /dev/static/image

Creating several directories

mkdir /dir{1..10}

Creating a File

$ touch

the touch command is used for only creating the empty file.

The command for creating a single file

touch test.txt

For creating the multiple files

touch test1.txt test2.txt test3.txt

For creating several files

touch book{1..20}

Copy and Past cmd

$ cp

This cmd is used for copy & paste files or folder.

syntext : cp <options> <source> <destination>

Options :

-r : recursive

-v : verbose

-f : forcefully

Example :

Copy a file from root directory to home directory

cp -rvf /root/test1.txt/home

Copy all data which start from D alphabet from root directory to home directory

cp -rvf /root/D*/home

Remove File and directory

For deleting all files or directory from this directory

rm -rvf /mbubux/test

For deleting all file in a directory named /home/test1/*

rm /home/test1/*

For moving or renaming files & directory

$ mv [Option] [source] [ Destination]

Move dir1 to dir2 ( Rename dir1 to dir2)

mv dir1 dir2

Move Directory dir1 dir2 dir3 to directory dir4

mv dir1 dir2 dir3 dir4

Task (Day-2)

  • Check your present working directory.

  • List all the files or directories including hidden files.

Create a nested directory A/B/C/D/E

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

Task (Day-3)

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

  2. To change the access permissions of files.

     chmod 777 foldernam
    
  3. To check which commands you have run till now.

history
  1. To remove a directory/ Folder.
#remove file name
rm filename
#remove folder 
rm foldername
  1. To create a fruits.txt file and to view the content.
#create file fruits.txt
vim fruits.txt
# viwe the contents file
cat fruits.txt
  1. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
vim devops.txt

  1. Show only the top three fruits from the file.

  2. To Show only the bottom three fruits from the file.

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

     vim Colors.txt
    

  2. To find the difference between fruits.txt and Colors.txt file.