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