Monday 23 May 2011

chown command


Brief: This command is used to change the owner or group of a file

Syntax: chown username:groupname filename

Command: chown akash newFile.txt

Description:

If a file is owned by a user and needs to be changed to own it by other user then chown command can be used.
chown akash newFile.txt
The above command can be used to assign the ownership of file newFile.txt to a user with name akash.
The chown command can also be used to change the group of a file.
Suppose currently a file can be used by group of 'employeeGroup' and want to change it to be used by  'adminGroup' then below command will do
chmod :employeeGroup newFile.txt

User can also make use of the userid and groupid instead of username and group name.
For ex : chown 987:679 newFile.txt


Arguments:

-R :  This paramter can be used to assign the owner to all the files within the sub directories of a current directory.


Important Examples:

1. changing the  ownership of more then one file.
   chown akash newfile1.txt newFile2.txt
   chown akash:newgroup newfile1.txt newFile2.txt

2.  changing the ownership recursively in all directories of mentioned directory.
    chown -R akash /home/user/

3. Assigning the ownership to no user and no group(Not Recommanded)
  chown nobody:nobody /home/user/newFile.txt
   

id command


Brief: This command is used to know the user id of a current user.
Syntax: id

Command: id

Description:

Each user when created in linux system gets an ID. The root user alsways has id as 0.  To know the id of current user , simply type id.
The id command will also tell the groupid to which the user belongs to  and also list all the different group ids to which user is associated to.
Arguments:

-un : prints the username of current user.
-r : prints the real id of the current user.
-u : prints the effective user id
-g : prints the group id


Important Examples:

1. id command displays below info
 Akash(23) emplyeegroup(616)
Username(userid) groupname(groupid)

2. id NewUser
NewUser(123) NewGroup(223)

3. id -un
Akash
UserName
   

Saturday 21 May 2011

ll command


Brief: This command is used to list the detail information of files and folder of a current directory


Syntax: ll

Command: ll


Description:
ls -l command is equivalent to ll command . This command is used to get detail information about files and directories in present working directory.


Arguments:

-a : This parameter list all the hidden files and directories along with non-hidden files/directories in the present working directory. It also include . and ..

-A : This paramater is same as -a but does not display . and ..

-l : This paramater is used to print the files and directories of present working directory in detail. It displays the permissions, owner, group, created on, last used details along with file name.

-t : This paramater list the files with last modification time.

-r : This paramter list the files in reverse order.

-R : This parameter list the content of sub directories also.

-c : This is the default parameter and list the files in multiple columns.

-1 : This parameter list the file in one column.

-p : This paramter appends a slash character at the end of directories. It can be useful for distinguishing files and directories.


Important Examples

1. ls -l or ll command displays information in following manner.

PermissionsDirectoriesGroupSizeDateDirectory or file
drwx------2users4096Nov 2 19:51mail/
drwxr-s---35www 32768Jan 20 22:39public_html/
-rw-------1users3Nov 25 02:58test.txt



2. ll a*
Displays detail info of all files/directories  with names starting with letter a.

3. ll *.txt
Displays detail info of all files/directories with extension txt. i.e. all text files are displayed.

4. ll -ltr
Displays detail info of files and directories in reverse order of last modification

ls command


Brief: This command is used to list the files and folder of a current directory


Syntax: ls

Command: ls


Description:

The ls command comes up with lots of parameters. By default entering ls command will list the name of files and directories of present working directory.

Important note: ls -l command is equivalent to ll command . This command is used to get detail information about files and directories in present working directory.


Arguments:

-a : This parameter list all the hidden files and directories along with non-hidden files/directories in the present working directory. It also include . and ..

-A : This paramater is same as -a but does not display . and ..

-l : This paramater is used to print the files and directories of present working directory in detail. It displays the permissions, owner, group, created on, last used details along with file name.

-t : This paramater list the files with last modification time.

-r : This paramter list the files in reverse order.

-R : This parameter list the content of sub directories also.

-c : This is the default parameter and list the files in multiple columns.

-1 : This parameter list the file in one column.

-p : This paramter appends a slash character at the end of directories. It can be useful for distinguishing files and directories.


Important Examples

1. ls -l or ll command displays information in following manner.
PermissionsDirectoriesGroupSizeDateDirectory or file
drwx------2users4096Nov 2 19:51mail/
drwxr-s---35www 32768Jan 20 22:39public_html/
-rw-------1users3Nov 25 02:58test.txt


2. ls a*
Displays all file names starting with letter a.

3. ls *.txt
Displays the files with extension txt. i.e. all text files are displayed.

4. ls -ltr
Displays detail information of files and directories in reverse order of last modification

pwd command


Brief: pwd stands for present working directory.This command is used to know in which directory is user working currently.

Syntax: pwd

Command: pwd

Description:

The pwd command does not accepts any argument and shows the complete path of the directory where user is currently working.

For ex: If user is working in /home/user/movies/ directory  then entering pwd command will result /home/user/movies path. 

cd command


Brief: The command cd itself implies change directory. The cd command is used to navigate from one directory to anaother.

 Syntax: cd directoryName

Command: cd movies

Description:
If the user is currently working in /home/user/ directory and want to navigate to a directory name 'movies' then user can use cd movies command

cd ..
The cd command can also be used to navigate to a parent directory of the present working directory.
For ex: User is currently working in /home/user/movies directory and wants to navigate to /home/user/
then cd .. command will do.

Importand Examples

1. User can navigate to a directory by specifying its complete path
cd /home/user/movies/2011/english
cd ../../2010/english

Thursday 19 May 2011

chmod command


Brief: This command is used to give or change permissions to files and directories. This command will set the read, wirte and execute permissions for user, group or others.

Syntax: chmod octalnumber fileName

Command: chmod 764 myFile.txt

Description:

Chmod can be used to set below permissions
-u : User                                 -r  : Read
-g : Group                              -w : Write
-o : Others                             -e  : Execute
-a : All

Numeric Permissions: Numeric permissions can be given by a 3 digit ocatl number. 1st digit specifies the permission of a user, 2nd digit of a group and 3rd digit of others. Each octal digit has a special meaning in chmod command. The sum of the below octal numbers can be used to set read, write and execute permissions.
400 - sets the read permission for user
040 - sets the read permission for group
004 - sets the read permission for others
200 - sets the write permission for user
020 - sets the write permission for group
002 - sets the write permission for others
100 - sets the execute permission for user
010 - sets the execute permission for group
001 - sets the execute permission for others

command: chmod 764 myFile.txt
The above command sets the octal number 7 for the user , 6 for the group and 4 for others. Octal number 764 is a sum of 400+200+100+040+020+002. It means that user has got read, write and execute permissions. Group has got read and write permissions . Others have got only read permissions.

Arguments:

-f : This parameter forces the system to pass through any kind of error messages if any comes while executing chmod command
 -v : Outputs a message for every file processed

-r or -R : It is used to recursively set the permissions of files and directories within the directory.
command: chmod 644 studentDirectory

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