Thursday, 19 May 2011

rm command


Brief: This command is used to delete an existing file without taking confirmation. By default it does not delete directories but rm command can also be used with -r parameter to delete folderes/files recursively in a directory.

Syntax: rm filename.extension

Command: rm NewFile.txt

Description:

The rm command will delete an existing file in present working directory. If the user is working in /home/username/ directory then NewFile.txt file can be deleted using below command.
rm NewFile.txt

User can also specify the path where the existing file needs to be deleted in the rm command.
For ex: Assume that user is presently working in  /home/username/newfolder , but  wants to delete a file with name log.txt in /home/class/ then following command will do.
rmdir /home/class/log.txt
Here it is assumed that home and class directory already exist. If any folder in the path mentioned does not exist then an error will be shown.

Important Note: rm command can be used to recursively delete the directories/files from a leading directory.


Arguments:

-f : rm command cannot be used to delete the write-protected files and this is where -f paramater comes into the picture
If a file is write-protected then this command can be used to force the deletion of a file.
command: rmdir -f  marks.txt
The above command will make sure that file mkdir.txt is deleted.
If a directory is write-protected and we attempt to delete the file using -f parameter then file will not be deleted and no error message will be displayed.
command: rmdir -f /mysql/databasefile.txt
if mysql is write-protected directory then the databasefile.txt will not be deleted

-i : This parameter makes sure that linux system takes the confirmation from the user before deleting the file.
Command: rmdir -i myFile.txt
After the command is entered linux prompts the confirmation message on command prompt. If user enters 'Y' or 'y' value then file is deleted. Any other value entered will not delete the file.

-r or -R : It is the most important paramter in this command and is used to delete directories and sub-directory within an existing directory.
command: rmdir -r class
Assume that directory name 'class' contains directory name 'test' and test contains file 'myfile.txt'. Then above command will delete directory 'class', ' test' and 'myfile.txt'.


Important Examples:

1. Delete one or more file in a single command. Try below command
    rm /home/user/myfile1.txt /home/user/teacher.txt
    output: student and teacher file gets deleted

2. Delete all file starting with  name a in present working directory
    rm a*

3. Delete all files with extension .txt in present working directory
    rm *.txt

Wednesday, 18 May 2011

rmdir command


Brief: This command is used to delete an existing directory/folder in a linux system.

Syntax: rmdir directoryname

Command: rmdir newfolder

Description:

The rmdircommand will delete an existing directory in present working directory. If the user is working in /home/username/ directory then newfolder directory can be deleted using below command.
rmdir  /home/username/newfolder .

User can also specify the path where the existing directory needs to be deleted in the rmdir command.
For ex: Assume that user is presently working in  /home/username/newfolder , but  wants to delete a directory with name student in /home/class/ then following command will do.
rmdir /home/class/student/
Here it is assumed that home and student directory already exist. If any folder in the path mentioned does not exist then an error will be shown.

Note: rmdir command will not work if the directory to be deleted contains some files or directories. But can be achieved by rm -r command.

Arguments:

-p : This argument deleted the existing parent directories also along with the leading directory.
Command :  rmdir -p class/student/result
In above command if class and student directory will also be deleted along with result directoy.

-v : Displays the log message for each directory deleted. This parameter is mostly used -p parameter to get information about the directories deleted.

Important Examples:

1. Delete one or more directory in a single command. Try below command
    rmdir /home/user/student /home/user/teacher/
    output: student and teacher directory gets deleted

2. Delete parent directories along with leading directory and print message against each directory deleted.
   rmdir -pv student/classes/bca
   output: deletes 3 directories student,classes,bca 

mkdir command


Brief: This command is used to create a new directory/folder in a linux system.

Syntax: mkdir directoryname

Command: mkdir newfolder

Description:

The mkdircommand will create a new directory in present working directory. If the user is working in /home/username/ directory then new folder will be created in  /home/username/newfolder .

User can also specify the path where the new directory needs to be created in the mkdir command.
For ex: Assume that user is presently working in  /home/username/newfolder , but  wants to create a new directory with name student in /home/class/ then following command will do.
mkdir /home/class/student/
Here it is assumed that home and student directory already exist. If any folder in the path mentioned does not exist then an error will be shown and directory will not be created.

What if the directory already exists in present working directory?
User will get an error message saying that directory already exists.

Arguments:

-p : This argument creates the non existing parent directories also along with the leading directory.
Command :  mkdir -p /home/class/student/result
In above command if class and student directory does not exist then they will be created along with result directoy.

-v : Displays the log message for each directory created. This parameter is mostly used -p parameter to get information about the new directory created.

Important Examples:

1. Create one or more directory in a single command. Try below command
    mkdir /home/user/student /home/user/teacher/

2. Create parent directories and print message against each directory created.
   mkdir -pv /home/user/student/classes/bca
   

Linux Tutorials

About the tutorial

This tutorial will help all the people who need to learn linux command from scratch. The best way to improve on linux commands is by reading, understanding and practising  at least one command per day.

What is command?

A command is nothing but a program in your linux system. When we enter a command , linux identify the class path set for the command and execute the program.

Help for each command (info command)

To understand a command or to get more information about a command . A user can make use of info command.
Syntax : info <command>
Example: info mkdir
The above command in the example will provide detail information about mkdir command which is used to create a new directory. It will describe about all the options which we can use along with mkdir command.


Below are the list of important commands. Click on the command name to view its detail description
mkdircdrmdirrm
chmodlsllpwd
idchownuseraddusermod