Sign in to follow this  
Followers 0
TESLA.COIL

RHCE-Tutorial

37 posts in this topic

Hello,everyone ! I’m starting this small linux tutorial which will benefit all RHCE aspirants and those who are new to linux operating system and its command line interface. You may consider this as a tutorial or as ”my Rhce diary”,if there are any errors or spelling mistakes e.t.c please let me know.

 

To being with, id be starting module wise. There are 3 modules that are to be completed before sitting for the RH302 exam. The modules are:

 

-RH033

-RH133

-RH253

 

RH033 contains the Basic unix\linux commands that one is supposed to know before moving to other modules.RH033 module is called as Linux Essentials.Its The main objective of this module is to get a thorough grip on the command line interface of the operating system.

 

RH133 contains the System Administration part.The main objective of this module is to become a system administrator.This module is called as ”System Administration”.

 

RH253 contains the information and the knowledge required to better understand the networking services and security implementation in a Redhat linux environment.The main objective of this module is to set up networking services and implement security. This module is called as ”Linux network and Security Administration”.

 

• To appear for the RHCT exam you are required to complete RH033+RH133 modules

• To appear for the RHCE exam you are required to complete RHCT+RH253 modules.

 

Note: RH033, 153, 253 are modules or courses that one must complete.RHCE exam Is called RH302.

 

I’ll be starting with RH033 module and I’ll be following the syllabus prescribed by the Redhat in their Redhat prep guides.I think it would be useful to stick to the Redhat prepguides,since it would be beneficial for other who are appearing for RHCE exam without attending the official Redhat training.

 

 

 

 

 

RH033: Redhat Linux Essentials

 

 

 

COURSE CONTENT

 

1.Origins of Linux ( completed)

 

2.First look at Linux ( completed )

 

3.Looking for help in Linux ( completed )

 

 

 

4.Understanding the file system and Hierarchy ( completed)

4.1- File System hierarchy click <<here>>

 

4.2- File System Commands click <<here>>

4.2.1- Understanding path names & navigating using cd click <<here>>

4.2.2- Creating files & directories using cat, touch & mkdir and understanding the od command click <<here>>

4.2.3- Listing the contents of a directory using the ls command click <<here>>

4.2.4- Reading files using cat, less, more, head ,tail & using vi click <<here>>

4.2.5- Copy,moving,renaming & deleting files and directories click <<here>>

4.2.6- File conversion from UNIXtoDOS & DOStoUNIX <<click here>>

4.2.7- Understanding Hardlinks & Softlinks click <<here>>

4.2.8- Learning to mount a cd\dvd-rom click <<here>>

4.2.9- Using the history & script command click <<here>>

4.2.10- Something about the inode table & Understanding how cp, mv ,rm and ls work? click <<here>>

4.2.11- The seven fundamental file types in unix \linux. click <<here>>

4.2.12- Archiving and compressing files click <<here>>

 

 

 

• User Account administration & File permissions

 

 

• Using the shell and its configuration

 

• Using the vi and vim editor

 

• Using Pipes & Text processing tools

 

• Searching for files

 

• Understanding Processes

 

• Basic System and Network configuration & maintenance

 

 

 

 

Firstly,I will start with the Basic installation procedure.Advance features and options like kickstart ,LVM & RAID e.t.c will be covered in the later part.This is just the basic set up to get the system running.

• Insert the Redhat Cd\Dvd in the drive.

• Select Cd-rom as bootable device from the Boot options of your system.

• Select Graphical mode as type of installation

• If asked fo testing of the cd \dvd select skip.

• Select Your preferred language.

• Select keyboard type as US english.

• If you have the key enter it or else select skip entering the key.

• After that you may get a screen regarding the partitions to set up before carrying out the installation.

 

 

PARTIONTING

 

Partitioning your hard drive can be done in two ways,either in Automatic or manual .For manaual we will use disk-druid partitioning manager ,so click the drop-down menu and select Custom layout as partition mode.

 

image1.jpg

 

 

/hda represents – First,Master IDE device

/hdb represents-First,Slave IDE device

/hdc represents-Second,Master IDE device

/hdd represents - Second,Slave IDE device

 

Since ,we have only 1 hard disk it will be represented as /had.Now If you already have windows installed on your system,that partition information under which windows is installed will be displayed by the druid and the filesystem type will be shown as NTFS.Keep existing partitions as it is if required.

 

 

image2.jpg

 

 

• To create linux partitions highlight over the free space and select new and select boot from the first drop down menu which says mount-point and select the space between 100-200 mb. Select file system type as ext3 and size as fixed.

 

• Now,select new again and select / from the drop-down menu and allocate around a minimum of 5 GB disk space.Select file system type as ext3 and size as fixed.

 

• Lastly,we need to mention some space for the virtual memory which is called as swap memory.Its used by extending the physical memory to the disk space especially, when the physical memory ( RAM ) is full. Swap memory is not a replacement to physical memory since its much slower ( depends on ur hard-disk speed and other factors) than the physical memory.

 

BOOTLOADER CONFIGURATION

For basic,setup configuring the boot-loader options is not required.You may leave it as it is ,as it will be discussed in advanced chapters.If you have dual-booting make sure that the GRUB is selected as default bootloader.

 

NETWORK CONFIGURATION

 

Specify what Ethernet devices you want to be active after booting up and also select if you would like to assign the ip address to these devices manually using static ip address or by using a DHCP server,this can also be done after the installation.

 

FIREWALL CONFIGURATION

 

Mention what type of security you seek for your network and also specify the trusted devices and services.If you are getting the Ip from the DHCP server make sure that DHCP is checked under ‘Allow incoming’ option.

 

• Next,you may be asked to enter your time zone.Enter the time zone of your choice.

• Next,you will be prompted to enter the root password .Root is the administrator\super-user of any linux\unix system and he enjoys many privileges that no other user enjoys like access to the entire file system,creating users,enabling\disabling of services e.t.c.It is always advised to login as a normal user and switch to root only to perform administrative or system maintenance tasks. More about this will be covered later.

• Next,you may be prompted to setup authentication configuration,since it’s a basic workstation setp its best to skip it.

 

 

PACKAGE SELECTION

 

Here,you can specify what exactly goes into your system.If you want to install GNOME or KDE as your Desktop environment,check GNOME or KDE and select DETAILS to install or uninstall additional packages, same applies with other options like EDITORS,APPLICATIONS,SERVERS,GRAPHICS e.t.c

 

At this point the installation has not started yet.You may be prompted with a screen that says installation will begin and you are given a choice to cancel the installation,or press ctrl+alt+del to restart your machine .The complete log of your installation can be found under /root/install.log.

 

This should conclude the basic installation and your system should be ready to reboot.

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

CHAPTER-1

 

Origins of linux

 

 

 

Objectives

 

• Understanding the history of unix and linux.

 

• Various Distributions in linux

 

• Understanding what is open-source

 

 

 

 

The first objective deals with the history of unix and linux and the ideas and principals behind the open source movement .I’m sure more about this can be easily obtained from the web.I’ll trying covering this briefly.

 

TOPIC 1 : Understanding the history of Unix and linux

 

 

1969- Unix was developed by Dennis Ritchie and ken Thompson at AT&T labs.

1969-Linus Torvalds is born.

1971-First edition of Unix released .

1972-Second edition of Unix was released

1972-Ritchie rewrote B and called the new language C.

1973-Third and fourth editions of unix were released

1974-Fivth edition of unix was released.

1975-Sixth edition of unix was release and also bourne shell was added to it.

1975-1980s – Sees various BSD releases along with the seventh edition of unix

1983-Richard M. Stallman announces the GNU Project, an attempt at creating a completely free operating system.

1985-86- Eigth & ninth edition of unix were released & Free Software Foundation established as a non-profit organization to promote the development of Free Software

1987- Larry wall releases perl.

1987-Andrew S.Tannenbaum releases MINIX a unix-like operating system for academic use.

1988-1990 - Sees development of HP-UX and AIX along with 10th version of Unix.

 

1991- Linux is introduced by Linus Torvalds, a student in Finland. Who posts to the comp.os.minix newsgroup with the words:

Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.

 

1994-Redhat Linux is introduced.

Linus Torvalds began to work on a non-commercial replacement for MINIX while he was attending the University of Helsinki. This eventually became the Linux kernel. Linux was dependent on the Minix userspace at first. With code from the GNU system freely available, it was advantageous if this could be used with the fledgling OS. Code licensed under the GNU GPL can be used in other projects, so long as they also are released under the same or a compatible license. In order to make the Linux kernel compatible with the components from the GNU Project, Torvalds initiated a switch from his original license (which prohibited commercial redistribution) to the GNU GPL. Linux and GNU developers worked to integrate GNU components with Linux to make a fully functional and free operating system.

 

2001-Linus Torvalds releases version 2.4 of the Linux Kernel source code on January 4th.

 

 

LINUX KERNEL + GNU UTILITIES = GNU\Linux operating system.

 

 

 

TOPIC 2 : Distributions in Linux

 

 

• A distribution or a distro is nothing but a member operating system from the family of unix –like operating systems which uses the linux kernel.

• A distribution consists of the Linux kernel,set of utilities and libraries from the GNU project, along with graphics support from the X window system.It provides support for Desktop environments like GNOME,KDE or Xfce e.t.c

• Distributions can be either commericial distribtutions or community driven distribution.

• Popular distributions are provided by Redhat ( Fedora and RHEL),canonical( Ubuntu,edbuntu,kubuntu e.t.c),novell( Open suse),Mandriva,Gentoo,Slackware e.t.c

• Distributions can also be classified on the basis of package management.

 

The redhat distributions include the Fedora project and Redhat enterprise linux.

 

Fedora project

- Community driven project

- Its free of cost

- No Redhat support available

- Release cycle is of 6-8 months

- Contains newer features and frequent updates

- Meant mostly for personal use

- Not completely tested

 

Redhat enterprise Linux

- Professional Support given by Redhat

- Stable and thoroughly tested

- Meant for large enterprises.

 

 

 

 

TOPIC3: What is open-source?

 

• As the name suggests the source code is open to all.

• Freedom to look at the code,modify\edit the code according to ones needs

• Freedom to share or distribute the software and the also the source code.

 

To read more about regarding the GNU\Opensource\freesoftware foundation philosophy refer the links mentioned below.

 

http://www.gnu.org/philosophy/philosophy.html

http://www.opensource.org/docs/definition.php

 

 

 

End of chapter 1

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

CHAPTER-2

 

First look at linux

 

Objectives:

 

• Logging into the system

 

• Starting the graphical mode

 

• Understanding the root user

 

• Executing some basic commands

 

 

TOPIC1:Logging into the system

 

There are 2 types of login-screens. One being the text mode and other graphical mode. Text mode login screens can be accessed via teletype terminals also called as virtual consoles. There are a total of 6 virtual consoles ( more than 6 is possible) out of which 5 are text and 1 is graphical.

 

The Text consoles can be accessed by pressing :

 

Ctrl+alt+F1 for first Virtual console

Ctrl+alt+F2 for second Virtual console

Ctr+alt+F3 for the third virtual console till ….Ctrl+alt+F6

Ctrl+alt+F7 -Graphical console

 

• Unix and Linux are multi-user operating system compared to Windows which is single user operating system ,and hence you can open a maximum of 6 different consoles and log in with 6 different users on the same machine.

• To switch to the Graphical consoles use ctrl+alt+F7.

 

To login as a super-user type root as the username as root and the password that you have set,here am using the password as redhat

 

 

login as: root

root@192.168.1.3's password:

Last login: Sun Mar 15 10:06:36 2009 from client1.tesla.com

[root@client1 ~]#

 

To log out type logout and try logging in as a normal user and observe the difference

 

login as: jax

jax@192.168.1.3's password:

Last login: Sun Mar 15 09:34:57 2009

[jax@client1 ~]$

 

The text before @ symbol here in our case root and jax represent the the name of the user who is currently logged in. The text after @ represents your system name or also called as hostname here the system name is set to client1 and the text after your hostname ,here in our case ~ represents our current working directory or our correct location in the system,just like if your are in C:/windows/system32 or C:\Users\user1 in windows operating system e.t.c and the symbol # in the first example denotes that you are logged in as a super user and in second example the symbol $ denotes you are logged in as a normal user who has very few powers compared to the root, who is the admin of the system.

 

To see the 1) hostname 2) who you are logged in as and 3)current location type the following commands:

 

[jax@client1 ~]$ hostname

client1.tesla.com

 

The command hostname provides the your system name or also called as FQDN name

 

[jax@client1 ~]$ whoami

Jax

 

The command whoami shows who you are currently logged in as

 

[jax@client1 ~]$ pwd

/home/jax

 

 

The command pwd (Print Working Directory)shows your current location,here am currently present in /home/jax which is my home directory or my work space . More about this will be covered in file system & hierarchy part.

 

 

 

TOPIC 2:Starting the graphical mode

 

If you are in text mode ,that is in any of those 6 virtual consoles,type the command startx or init 5 to start the Xserver and switch to the graphical console using ctrl+alt+F7 and soon you will be prompted with the graphical login menu.

 

 

 

Topic 3:Understanding the root user

 

 

 

Root user is the System administrator or super-user of the entire operating system,when compared to a normal user enjoys more privileges.The root owner has complete authority over the system and also has the power to destroy the system. Its recommended not to use the root user very often but use it only when required. In redhat linux Root can be used to login via both graphical as well as text mode in redhat enterprise linux where as the same cannot be done in Fedora, where roots operation is only confined to the text mode.

 

To change the password of root or any other user use the command. The syntax is

 

passwd <username>

 

[root@client1 ~]# passwd root

Changing password for user root.

New UNIX password: < enter password>

BAD PASSWORD: it is based on a dictionary word

Retype new UNIX password:< retype the password>

passwd: all authentication tokens updated successfully.

 

Note: Only Root has the power to change the passwords of his as well as accounts of others!!

 

 

Switching between normal user and root can be done by using the command su ( Switch User).

 

The syntax is su - < username >

 

[root@client1 ~]# su - jax

[jax@client1 ~]$ su -

Password:

[root@client1 ~]#

 

The - after su provides the user with his\her own shell that is,when root uses the command su – jax to switch to the jax user, the current location of the user root will change from /root ( which is roots home directory) to /home/jax ( which is the home directory of the user jax).Similarly when user jax uses the command su - ( Since no username is provided after -,the system considers it as root),the user jax will be prompted with a password ,since jax a normal user is switching to root who is a superuser.

 

If – is not provided by root in the example su – jax ,that is if the command entered by the root is su jax then the root will switch to the user jax but his current location will be /root not /home/jax.

 

Without using -

 

[root@client1 ~]# pwd

/root

[root@client1 ~]# su jax

[jax@client1 root]$ pwd

/root

[jax@client1 root]$

 

By Using –

 

[root@client1 ~]# pwd

/root

[root@client1 ~]# su - jax

[jax@client1 ~]$ pwd

/home/jax

[jax@client1 ~]$

 

 

Note the differences in line 5 of both the examples.

 

 

There are other commands like sudo ( superuser do ),that will let a normal user run commands that only a superuser can issue. This will be covered later.

 

 

 

 

Topic 4:Executing some basic commands

 

 

 

This topic explains how to execute the basic linux commands.Commands can be executed either in virtual consoles or also by using an an application called as terminal for GNOME and Konsole for KDE desktop environment. Terminal can be found under applications > system tools> terminal in the graphical mode.

 

 

 

The general syntax of any unix or linux command consists of 3 parts and is as follows:

 

Command < options > <arguments >

 

 

Note: there can be multiple options as well as multiple arguments

 

Ex:

 

date - shows current date

 

cal - show calender

 

bc - shows calculator

 

An example for single option and single argument.

 

[jax@client1 ~]$ cat -n helloworld

1 Hi this is Linux

2 Hello world

[jax@client1 ~]$

 

In the above command I’m trying to read a file using the command cat which forms the command, and am reading the file called helloworld ,which forms the argument part and the –n options read the file along with numbering the lines in the file. The command outputs the data “hi this is linux “ present in first line and “ hello world” in second line.

 

An example that follows multiple options with multiple arguments.

 

[jax@client1 ~]$ cat -nE helloworld foo

1 Hi this is Linux$

2 Hello world$

3 Hi,this is foo$

4 This is redhatlinuxbye$

5 bye$

 

The above command uses E as an additional option besides n to show end of line using the symbol $ at the end of every character,and foo as an additional argument which is a file name.The command cat reads both the files helloworld and foo.

 

 

 

This same out put can be achieved by using

 

[jax@client1 ~]$ cat -nE helloworld

1 Hi this is Linux$

2 Hello world$

[jax@client1 ~]$ cat -nE foo

1 Hi,this is foo$

2 This is redhatlinux$

3 bye$

 

Multiples commands can be given in a single line using the separator ; that is,the command cat can be followed by another command or multiple commands seprated by ;

For example

[jax@client1 ~]$ cat -n foo ; date

1 Hi,this is foo

2 This is redhatlinuxbye

3 bye

Sun Mar 15 11:23:37 IST 2009

 

The command cat -n foo will read the file,which is the first command and the second command is date which prints the date and is separated by using ;

 

[jax@client1 ~]$ hostname;whoami;pwd

client1.tesla.com

jax

/home/jax

 

; is being used to mention all the 3 commands in one line instead of using 3 different lines.

 

 

End of chapter 2

0

Share this post


Link to post
Share on other sites

CHAPTER-3

Looking for Help in linux

 

 

Objectives

 

• Using the whatis command

 

• Using other commands like man,apropos,info and –help

 

• Locating commands with whereis and which

 

 

One of the advantages of using command mode in linux is the availability of multiple options to look for help,along with tab completion.

 

 

Topic 1:Using the whatis command

 

To get a short and a very brief information about any command,use the command whatis. But before using the command whatis on a newly installed system,you may be required to create the whatis database . This can be done by using the command makewhatis.The database file is located in /var/cache/man/whatis.

 

Syntax of the command is makewhatis <command name>

 

For example:

 

[root@client1 ~]# whatis date

date [] (1) - print or set the system date and time

date [] (1p) - write the date and time

Date::Manip [] (3) - date manipulation routines

 

 

[root@client1 ~]# whatis whatis

whatis [] (1) - search the whatis database for complete words

[root@client1 ~]#

 

 

[root@client1 ~]# whatis poweroff ; whatis reboot

poweroff [] (8) - reboot or stop the system

reboot [] (2) - reboot or enable/disable Ctrl-Alt-Del

reboot [] (8) - reboot or stop the system

[root@client1 ~]#

 

 

Topic 2 :Using other commands like man,apropos,info

 

The manual command or for short the man command provides not only what the command does like whatis command but also it provides the documentation,details on what the options that can be used and also their use,almost every command in linux has a manual command.

 

The syntax is man < command >

 

• The man page describes,the title or the name of the command

 

• Summary of the command

 

• Options of the command

 

• A detailed description of the command

 

• Any other command that may be similar to the above command

 

• Information regarding the bugs

 

• Examples on how to use the command and its options

 

The information in man is arranged in sections from 1 -8.

 

1-usercommands 3-library calls 5-file formats 7-miscellaneous

2-system calls 4-Special file 6-games 8-Administrative commands

 

 

Use whatisdate

 

[root@client1 ~]# whatis date

date [] (1) - print or set the system date and time

date [] (1p) - write the date and time

Date::Manip [] (3) - date manipulation routines

 

Now ,use the commands

 

Man 1 date and man 1p date separately.

 

 

Also try,

 

Whatis partprobe

[root@client1 ~]# whatis partprobe

partprobe [] (8) - inform the OS of partition table changes

 

and issue the command man 8 partprobe or simple try man partprobe

 

 

Navigation in man pages

 

After opening the man page,use pgup and pgdn to navigate and also you can type /<keyword> to look for any keyword in the man page, for example after opening the man page for the command zip type / and type password as the keyword.This will search the entire man page for the keyword password. The result of this would be the keyword password being highlighted at -e option of zip,which is used to password protect the .zip file.

 

• Use the arrows marks and pgup and pgdn to navigate.

 

• Pressing n and N will move you forward and backward one match at a time.

 

• Type q to quit the man pages

 

 

man -f <keyword> is equal to the command whatis

 

man -k <keyword> is equal to the command apropos

 

 

 

 

Apropos or man -k can be used to look for a command on the basis of your keyword. These commands are useful in case you dont know what command to look for to do a certain task.

 

For example :

If you do not know what is the command to see,since how long your system has be running ,you can try the apropos or man –k.

 

[root@client1 ~]# apropos "how long"

uptime [] (1) - Tell how long the system has been running

 

 

or try apropos “ memory”

 

[root@client1 ~]# apropos "memory"

<…removed output…>

cfree [] (3) - free allocated memory

cpuset [] (7) - confine processes to processor and memory node subsets

fmemopen [] (3) - open memory as stream

free [] (1) - Display amount of free and used memory in the system

free [] (3) - Allocate and free dynamic memory

free [] (3p) - free allocated memory

<…removed output…>

 

 

 

 

Info pages

 

Similarly you have commands like info and - - help that pretty much do the same job as the man pages. The info command are more in depth compared to the man pages and they are divided into nodes. The nodes are preceeded by an *.

 

Running info with out any arguments will present you with info to all the commands arranged in their respective nodes.

 

• Navigation in info pages can be done using arrow keys and pgup and pgdn

• Press enter to select the node.

• Press tab to select the next node

• / or s can be used to search for the keyword in the info page

• q to quit the info page.

 

 

Using - -help command

 

The --help command is useful to see what a command does,its options and its usage.The information provided by the above command is brief but very useful compared to lengthy man and info pages. The syntax is the command followed by the --help.

 

 

Additional help

 

Additional help could be found under /usr/share/doc.It contains the information that couldn’t be found using man or info commands. Any documentation that doesn’t fit the format of man of info can be found under /usr/share/doc.

 

 

Example:

 

[root@client1 ~]#man date

 

SYNOPSIS

date [OPTION]... [+FORMAT]

date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

 

• Here [ ] straight braces represent,any thing in them is optional

 

• … represents multiple options can be used

 

• The pipe ( | ) represents that only any of those options would work,that is either date –u OR date –utc.

 

• In the above information both OPTION and FORMAT are optional thus they are placed in straight braces,so the command date will work with out options and format.

 

 

Locating commands

 

 

The whereis command is used to locate the source-code,the man page of the command and the binary of a particular command. Firstly,run whatis date.

 

 

[root@client1 ~]# whatis date

date [] (1) - print or set the system date and time

date [] (1p) - write the date and time

Date::Manip [] (3) - date manipulation routines

 

then.......

 

[root@client1 ~]# whereis date

date: /bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz

 

In the first part the whatis commands shows what the date command does,and in the second part whereis commands shows:

 

 

1) date: /bin/date : The location of the command (binary). The command date is stored in /bin

2) /usr/share/man/man1/date.1.gz : Location of the (1) man page, try man 1 date.

3) /usr/share/man/man1p/date.1p.gz : shows the man page of (1p) try man 1p date.

 

Now,use the command which date

 

[root@client1 ~]# which date

/bin/date

 

The above command just provides the full path to the location of the command date. Similarly try running whereis and which for the command passwd

 

whereis provides more detailed information regarding the passwd command ,it shows both the location of the command passwd as well as the location to the file /etc/passwd and their respective man pages.

 

You can even use the command type to achieve similar results.

 

 

 

 

 

 

 

End of chapter 3

0

Share this post


Link to post
Share on other sites

CHAPTER-4

 

Linux file system & hierarchy

 

 

Objectives

 

• Understanding the unix\linux filesystem & hierarchy

 

• File system commands

 

• Archiving and compressing files

 

 

Key points:

 

• Everything under unix and linux is treated as a file,including the kernel and the shell.

• File system starts at the root directory,which is represented with a forward / ,which is a inverted –tree structure. Root user and / ( root ) both are different things.

• File,directories and devices like cdroms,usb devices and even directories e.t.c are treated as files and are organized under the /.

• Names in linux are case-sensitive.

• Paths are delimited using a / for ex: /home/jax/Desktop

 

 

 

 

 

 

TOPIC 4.1 : File system hierarchy

 

 

 

 

image1.jpg

 

 

[jax@client1 /]$ ls

bin dev home lib64 media opt raid sbin srv tmp var

boot etc lib lost+found mnt proc root selinux sys usr

 

 

• / or the root is the the top level directory,it consists of other directories as shown in the above image.Every file,directory and devices are present under the /.

 

• /home: Every user in linux has a home-directory or his\her own workspace. he main use of home directory is to store a users personal documents,pictures,application and data e.t.c. The home directory of the superuser root is /root, and the home directory of normal users come under /home/<username>.

 

For example, the home directory of the user jax will be /home/jax. To see your current working directory use the command pwd. If you login as root,you will be taken to /root and similarly if u login as a normal user you will be taken to your home directory under /home,from there u can navigate to other directories.

 

• /root: /root is the home directory of the administrator of the system. A normal user cannot navigate to /root or create or edit any files present inside /root,with out the permission of the super user. More about this in file permissions.

• /boot: /boot contains the kernel and the bootloader and other important configuration files ,which startup the system.

 

 

[jax@client1 boot]$ ls -l

total 7396

-rw-r--r-- 1 root root 84992 2008-11-18 22:40 config-2.6.27.5-117.fc10.x86_64

drwxr-xr-x 3 root root 4096 2009-03-12 09:16 efi

drwxr-xr-x 2 root root 4096 2009-03-12 09:53 grub

-rw------- 1 root root 3414153 2009-03-12 09:22 initrd

-rwxr-xr-x 1 root root 2637056 2008-11-18 22:40 kernel

-rw-r--r-- 1 root root 1406155 2008-11-18 22:40 System.map-2.6.27.5-117.fc10.x86_64

 

The command ls lists the contents of /boot.

 

• /bin ,/sbin, /usr/sbin and /usr/local/bin : Contains the system executables or also called as system binaries. /bin contains the binaries or the commands for the user and /sbin contains the binaries for the system which can only be used by the root.

 

/bin contains the shells like bash, csh etc. as well as much used commands like cp, mv, rm, cat, ls. There also is /usr/bin, which contains other user binaries. These binaries on the other hand are not essential for the user. The binaries in /bin however, a user cannot live without.

 

•/sbin - This directory contains all the binaries that are essential to the working of the system. These include system administration as well as maintenance and hardware configuration programs. Find lilo, fdisk, init, ifconfig etc here. These are the essential programs that are required by all the users. Another directory that contains system binaries is /usr/sbin. This directory contains other binaries of use to the system administrator. This is where you will find the network daemons for your system along with other binaries that only the system administrator has access to, but which are not required for system maintenance, repair etc.

 

• /dev: This directory contains the devices.Under /dev you will come across hda1 ,hda2 that represents your partitions on the first master device. /dev/cdrom or dvd represents your cd rom./dev/tty that present the virtual consoles. /dev/dsp represents your speaker. Try this , read a file using cat and redirect the output to the /dev/dsp ( cat file1 > /dev/dsp )

 

/dev/ttyS0 represents the first communications port, COM1

/dev/lpo represents the first parallel port LPT1

/dev/USB represents the usb devices

/dev consists of two types of devices ,one is character device and other is block device.Block devices are those devices that store the data like hardrives,cdroms e.t.c and character devices are those that transfer data,like serial ports,printers e.t.c

 

 

 

 

• /etc: Consists of all system configuarion files under various sub directories. A configuration file is a simple file that controls the operation of a programe.Most configuration files under have the suffix .conf.

 

• /lib : This directory contains all the libraries that provide the code shared by many linux applications,it also contains the kernel modules that is required to boot the system and run various commands in the root filesystem.

 

• /mnt: Represents the mount point,under which filesystems and various devices are mounted.By mounting the device is made accessible to the system. /media consists of mostly the removable media like Cd-rom .

 

• /opt & /proc: /opt represents optional,and it contains all the software and packages that are not the part of the default installation. /proc contains all the system information.It contains files with information regarding system memory,mount points,hardware information,cpu information e.t.c,Most of the files under this directory are the run-time files and thus are always 0 in size except few files.

 

• /tmp & /usr: /tmp is used for temporary storage of data by applications.Most of the files that are required process are stored in /tmp,the contents of the directory are usually deleted at reboot. /usr usually contains by far the largest share of data on a system. Hence, this is one of the most important directories in the system as it contains all the user binaries, their documentation, libraries, header files, etc.... X and its supporting libraries can be found here./usr stands for user system resources.

 

• /var : contains the variables,that is the files that keep changing like logs,printer spools e.t.c and even email spools.It also stores cached data and backups.

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

The second topic of chapter 4 will be slightly long so, for easy navigation i have divided it into sub-topic

 

 

TOPIC 4.2 : File system commands

 

 

 

Topic 2 deals with the file system commands. The commands are required for file management and navigation in the file system. This topic extensively covers:

 

• Understanding path names & navigating using cd

 

• Creating files & directories using cat ,touch and mkdir & using od command.

 

• Listing the contents of directories using ls.

 

• Reading files using cat, less, more, head & tail

 

• Copying, moving, renaming, deleting files & directories & determining file type using cp, mv ,rm ,rmdir & file.

 

• File conversion from unix to DOS and DOS to unix

 

• Understanding Symbolic & hardlinks

 

• Learning to mount a cdrom\dvdrom

 

• Using the history & script command

 

• Something about the inode table & How cp, mv ,rm and ls work?

 

• The seven fundamental file types in unix \linux.

 

 

 

 

Topic 4.2.1 : Understanding path names & navigating using cd

 

 

 

 

A path name is like a road-map. It is used to give the exact path to access the file that may be present anywhere in the file system. There are 2 types of paths:

 

1) Relative pathname

 

2) Absolute pathname

 

 

After logging in as user tom our current location will be /home/tom,which is the home directory of the user tom. It can be verified by using the command pwd.

 

[tom@client1 ~]$ pwd

/home/tom

[tom@client1 ~]$ ls

hello user

 

In the example above the directory /home/tom ( where the directory tom is present under the directory home,and home is present under the directory / (root )), consists of 2 files hello & user,this is verified by using the command ls ( more about this later) to list the contents of the directory tom. To read this file there are 2 ways to mention the path to the files.

 

 

ABSOLUTE PATHNAME

 

Firstly ,by using the ABSOLUTE PATHNAME we read the files.

 

[tom@client1 ~]$ cat /home/tom/hello

Hello this is tom

 

Here cat is being used to read the file and /home/tom/hello is the path to reach the file. By specifying the Absolute pathname we are providing the FULL pathname starting from the / ( root of the file system tree). Absolute pathname is the exact path to reach the file hello.

 

Also, note that we are currently present in the directory tom and we are using the full pathname to read the file.

 

 

The same thing can be done by being elsewhere and reading the same file.

 

[tom@client1 dev]$ pwd

/dev

[tom@client1 dev]$ cat /home/tom/hello

Hello this is tom

 

 

Our current location is /dev, and we are using the Absolute pathname to read the file hello which is outside /dev directory.

 

• So, All absolute pathnames begin with a /

 

• Provides the complete path to reach the file

 

• It can be used anywhere,even when you are present the in the directory contain the file to be read.

 

 

 

 

RELATIVE PATHNAME:

 

The advantage of Absolute pathname is ,that a file can be read from anywhere in the filesystem. The same cannot be said regarding the Relative pathname.

To read the file hello which is present in /home/tom directory,we need to navigate to the directory tom and read it.

[tom@client1 dev]$ pwd

/dev

[tom@client1 dev]$ cd /home/tom/

[tom@client1 ~]$ cat hello

Hello this is tom

 

Firstly, I’m verifying our current location as /dev and then navigating all my way to the directory that has the file hello using the command cd ( more abt it later) and then reading the file using the command cat.

 

If the file to be read or edited is present in the current working directory ,that is when RELATIVE PATHANME is used.

 

[tom@client1 ~]$ pwd

/home/tom

[tom@client1 ~]$ ls

hello user

[tom@client1 ~]$ cat user

I'm a normal user

 

• The relatives pathnames can be considered as a shortcut compared to the relative pathnames.

 

• The relative pathnames do not begin with a /

 

• Relative pathnames specify the path that is relative to your present working directory, verified using pwd .

 

 

 

 

Navigating using the cd command:

 

 

 

The cd (change directory) command is used to navigate between directories in the linux\unix file system. The concept of relative & absolute pathnames is applicable for cd as well. Press tab to auto-complete the path for you.

 

The syntax of cd command is

cd <relative or absolute pathname>

 

examples:

 

 

Using relative pathaname

 

 

[tom@client1 /]$ pwd

/

[tom@client1 /]$ ls

bin dev home lib64 media opt raid sbin srv tmp var

boot etc lib lost+found mnt proc root selinux sys usr

 

[tom@client1 /]$ cd home

[tom@client1 home]$ ls

jax tesla tom

[tom@client1 home]$ cd tom

[tom@client1 ~]$ ls

hello user

 

In the above example.to reach the directory of tom from the directory / ( root) we are verifying the contents of / by using the command ls. After finding the directory home under / we have used the command cd followed by the directory name home. After getting into the directory home we ls to list the contents of the directory home and then after finding the directory tom along with other home directories of users jax and tesla we cd to the directory tom,and finally we ls to list the contents of the directory /home/tom.

 

We have used cd to change the directory twice.

 

 

Using absolute pathname

 

 

The same thing can be done with a single absolute command instead of using multiple relative commands.

 

[tom@client1 /]$ pwd

/

[tom@client1 /]$ cd /home/tom/

[tom@client1 ~]$ pwd

/home/tom

 

Here cd /home/tom is the absolute path to reach the directory tom.

 

We have come all the way from / to the directory tom. Now to go one level back we use the command

 

cd ..

 

 

Note: There is a white space between cd and ..

 

 

A single . ( dot ) represents the current directory and a .. ( double dot ) presents a parent directory.

 

• cd .. Represents one level up

 

• cd ../.. Represents two levels up

 

• cd ../../.. Represents three levels up

 

• cd Takes you to your home directory

 

• cd - Takes you to the previous working directory

 

Examples

 

 

[tom@client1 test]$ pwd

/home/tom/Desktop/test

 

We are in the directory test, which is present under the directory Desktop, where Desktop is the parent directory for test.The directory Desktop is present under tom,where directory tom is the parent directory for Desktop,and similarly tom directory is present under the directory home,where home directory becomes the parent for the directory tom.

 

[tom@client1 test]$ cd ..

[tom@client1 Desktop]$ pwd

/home/tom/Desktop

 

Now by using cd .. we move one up to the parent directory of test which is the directory Desktop.

 

[tom@client1 Desktop]$ cd ../..

[tom@client1 home]$ pwd

/home

 

Now by using cd ../.. we move 2 levels up from the directory Desktop to the directory home, there by skipping the directory tom.

 

[tom@client1 home]$ cd -

/home/tom/Desktop

 

By using cd - we jump back to our previous working directory, which was the directory Desktop. Using cd - again should takes us back to the our previous working directory which was the directory home.

 

[tom@client1 Desktop]$ cd -

/home

 

Now keep using tab to auto complete the path for you,and reach the the test directory .

[tom@client1 test]$ cd ../../../..

[tom@client1 /]$ pwd

 

Should takes us 4 levels up the hierarchy to the / directory,by using cd - we can jump back to the test directory.

 

 

 

Navigating between home directories using ~(tilde) & $HOME

 

 

If you are logged as user root, and your present working directory is /usr/share/ typing only cd should take you to your home directory which is /home/tom.If you wish to navigate all your way to a directory called for-root created by user jax in his home directory from your present working directory.

 

[root@client1 share]# pwd

/usr/share

 

To reach the for-root directory from /usr/share with minimum effort use the commands

 

[root@client1 share]# cd ~jax/Desktop/for-tom/ ( use tab for auto-completing the path )

 

Similarly if you wish to reach the home directory of user user100

 

[root@client1 share]# cd ~user100

 

 

If you wish to reach your home directory,you can use the command cd or

 

[root@client1 share]# pwd

/usr/share

[root@client1 share]# cd $HOME

[root@client1 ~]# pwd

/root

 

$HOME will take you back to your home directory and ~ followed by a username will take you to the home directory of the that respective user.

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.2: CREATING FILES AND DIRECTORIES USING CAT,TOUCH,MKDIR AND OD COMMAND

 

 

There are number of file types in a unix\linux file system. In total there are a total of 7 file types. The type of file can be found out by using ls –l ( more about ls later).

 

[root@client1 ~]# ls -l

total 97952

-rw-r--r-- 1 root root 78888897 2009-03-16 01:09 hello

drwxr-xr-x 2 root root 4096 2009-03-16 07:17 test

 

 

In the first line of the output the ‘ ‘before rw for the file hello represents that the file hello is an ordinary file, and the ‘d’ before rw in the second line conveys that the test is a directory.More about the other fields from the above output will be covered in ls chapter.

 

Ordinary files like hello can be created by using the commands cat,touch and vi\vim.

 

 

cat

 

The command cat stands for concatenate. It can be used to create,view or concatenate files. The syntax of the command is

cat <options > <filename>

 

 

Options

 

> Overwrites the existing contents of the file

 

>> Appends to the existing contents of the file,with out overwriting

 

.<filename> Creates a hidden file i.ee a dot followed by a filename

 

 

To create a file for the first time enter the command cat > foo or you may even use cat >> foo , which creates an empty file foo. After entering the above commands you are prompted to enter the contents of the file,press enter to get to the next line. After you are finished writing into the file press ctrl+D to close the file.

[root@client1 test]# cat > foo

hi this is

linux

[root@client1 test]# ls

foo

[root@client1 test]#

 

To read the file use cat again. To over write the file use cat > foo , using > will wipe off all the existing data by over writing and where as using >> will append to the existing data thus saving the existing data from being lost.

 

 

 

[root@client1 test]# cat foo < to read the file foo >

hi this is

linux

[root@client1 test]# cat > foo < will overwrite the existing data>

this is unix

[root@client1 test]# cat foo

this is unix

[root@client1 test]# cat >> foo < will append to the existing data>

this is linux

[root@client1 test]# cat foo

this is unix

this is linux

 

To create a hidden file add . (dot) before the filename

cat >> .hidden_file

 

With cat you don’t have the option of editing your text,for example if your are in line number 2 and you have made a mistake in line 1.You cannot go back to the previous line to edit it. Its possible in vi editor to edit your previous lines.

 

 

Using the od command

 

 

[root@client1 test]# cat >> test

hi This is a test

file

 

The cat command only shows the visible characters. In the above example the file contains the visible characters from A-Z along with invisible characters, i.ee…..it contains 4 spaces and 1 enter key to reach the next line.

 

To view the invisible characters use the command od ( octal dump ) ,it displays the invisible or non-printable characters along with the octal values of each character.

 

[root@client1 test]# od -a test

0000000 h i sp T h i s sp i s sp a sp t e s

0000020 t nl f i l e nl

0000027

 

The above command reveals the hidden characters like spaces ( sp) and next line is represented by a nl.

 

Similarly,the below command reveals the octal values as well where \n presents a new line after you type the enter key.

 

[root@client1 test]# od -bc test

0000000 150 151 040 124 150 151 163 040 151 163 040 141 040 164 145 163

h i T h i s i s a t e s

0000020 164 012 146 151 154 145 012

t \n f i l e

 

 

 

Touch

 

Touch command can be used to create empty files as well as changing the time stamps of a file ( more about this later ). Touch command can also be used to create a complex pattern of multiple files.

 

The Basic syntax is

 

Touch < filename 1>…<filename n>

 

Usage :

 

 

[root@client1 test]# touch file1 file2 file3

 

The above command creates 3 files named file1 file2 and file3

 

[root@client1 test]# ls

file1 file2 file3

 

 

Instead of typing the word file thrice ,the same thing can be achieved by using the touch command with a pattern,as shown below.

 

[root@client1 test]# touch file{1..3}

 

 

Since,the keyword ”file” is common in all the 3 files, its kept out of the the braces and {1..3} prints the sequence from 1 to 3.

 

[root@client1 test]# ls

file1 file2 file3

 

 

 

 

To create a Sequence of files,use the flower braces { } .

 

 

[root@client1 test]# touch {1..100}

 

Creates a sequence of files from 1 to 10

 

 

[root@client1 test]# touch {a..z}

 

Creates a sequence of files from a to z

 

 

 

 

 

 

[root@client1 test]# touch {a..z} {A..Z}

[root@client1 test]# ls

a b c d e f g h i j k l m n o p q r s t u v w x y z

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 

 

Creates a sequence of files from a-z and A-Z

 

 

 

 

 

Making Directories using mkdir

 

 

To make directories in unix\linux the command mkdir ( make directory) is used.

 

The syntax of the command is

mkdir <options> <Directory names>

 

Options:

 

-v : Stands for verbose,prints the message after creating a directory

 

-p : Makes parent directories or makes Nested directories

-m : Can be used to set permissions

 

Usage:

 

 

1) The below command makes a directory called test

 

 

[root@client1 test]# mkdir test

[root@client1 test]# ls

test

 

 

2) The command given below makes a directory called test2 and the prints that the directory has been created successfully.

 

[root@client1 test]# mkdir -v test2

mkdir: created directory `test2'

 

3) The command given below creates multiple directories

 

[root@client1 test]# mkdir jan feb march

[root@client1 test]# ls

feb jan march

 

 

 

 

Creating Nested Directories

 

 

1) The command given below creates a directory 2009 and under it,it creates 3 directories called jan ,feb and march.

 

[root@client1 test]# mkdir 2009 2009/jan 2009/feb 2009/mar

 

The above same thing can be done by using the command

[root@client1 test]# mkdir 2009 2009/{jan,feb,mar}

 

2) To create a sequence of directories like directories from 1 to 10,A to Z and a to z,use the command

 

[root@client1 test]# mkdir {1..10} {a..z} {A..Z}

 

 

 

 

3) To create a nested directory like a/b/c/d/e/f where f is present under e ,and e under d ,d under c so on … use the command

[root@client1 test]# mkdir -p a/b/c/d/e/f[/b]

 

Use ls –R to verify the output.

 

 

[root@client1 test]# ls -R

.:

a

 

./a:

b

 

./a/b:

c

 

./a/b/c:

d

 

./a/b/c/d:

e

 

./a/b/c/d/e:

f

 

./a/b/c/d/e/f:

 

 

Or you can even use the command,the output of both the commands will be same

 

[root@client1 test]# mkdir a a/b a/b/c a/b/c/d a/b/c/d/e a/b/c/d/e/f

 

 

 

 

 

Setting permissions to the directory

 

 

The command mkdir with an option –m can be used to create a directory with read,write and execute permissions.

[root@client1 test]# mkdir -m a=rwx linux

 

This command will create a directory linux,where ”a” represents all ( owner,group members & others ) and ”rwx” the permission read,write and execute being granted to all the members. More about permissions will be covered in file permissions chapter.

 

[/b][root@client1 test]# ls -l

total 4

drwxrwxrwx 2 root root 4096 2009-03-16 10:46 linux[/b]

 

 

 

 

Using all the 3 options

 

All the 3 options that we you have learned –v, -m , -p can be used in a single command.

 

[root@client1 test]# mkdir -vm a=rwx -p a/b/c

mkdir: created directory `a'

mkdir: created directory `a/b'

mkdir: created directory `a/b/c'

 

Note: The parameters must immediately follow the options that is –m should be followed by a=rwx and –p by a/b/c.

 

 

The command given below is considered to be incorrect ,since the parameters don’t immediately follow the options.

 

root@client1 test]# mkdir -vp a=rwx -m a/b/c

 

 

Refer to the man pages of mkdir,cat,touch and od for more information

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.3: LISTING THE CONTENTS OF A DIRECTORY

 

 

 

Listing using ls

 

The Contents of a directory can be listed out by using the command ls ( list ). The syntax of the command is:

 

ls <Options> <Directory name>

 

 

Options:

 

 

-l : Will long list the files and show detailed information

 

-F: Shows binaries and executables * represents an executables and a / directory

 

-a: Shows all the files including hidden files

 

-X: Shows output in columns

 

-R: List contents of a directory recursively or prints the directory tree

 

-t: List the contents of the directory with last modified file first.

 

-u:List the files on the basis of access time with last accessed file first

 

-r: List the files of a directory in a reverse order

 

-i: List files along with inode numbers

 

-h: List contents of a directory and the size of the files in it human readable format

 

-ld: List directory

 

 

ll is equal to ls -l

 

 

Usage:

 

1) The command ls –l list the contents of the directory along with some detailed information.Absolute path can be used to list the contents of a directory which is present elsewhere.

 

 

[root@client1 test]# ls -l

total 6744

drwxr-xr-x 2 root root 4096 2009-03-16 12:01 file

-rw-r--r-- 1 root jax 6888896 2009-03-16 12:03 script.sh

 

 

 

• - : shows the type of the file whether it’s an ordinary file,directory e.t.c

 

• rwxr-xr-x – Shows the file permissions

 

• 2 – No: of links

 

• root : Shows the owner of the file

 

• jax : Shows the group owner of the file

 

• 6888896: Size of the file in bytes

 

• 2009-03-16: Shows the last modification time

 

• 12:01: Shows the latest timestamp

 

• file : Shows the name of the file

 

 

 

2) The command ls –h displays the contents of the directory in human readable format

 

[root@client1 test]# ls -aulih

total 6.7M

408034 drwxr-xr-x 3 root root 68K 2009-03-16 12:22 .

408001 drwxr-x--- 9 root root 4.0K 2009-03-16 12:16 ..

408031 drwxr-xr-x 2 root root 4.0K 2009-03-16 12:16 file

408037 -rw-r--r-- 1 root root 6.6M 2009-03-16 11:57 script.sh

408035 -rw-r--r-- 1 root root 6 2009-03-16 11:15 .t

 

 

Lists the contents of the directory on the basis of last access time,in long list format along with inode information and and all the files including hidden files being displayed in human readable format that is in kilo bytes.

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

Topic 4.2.4: Reading files using cat, less, more, head ,tail & using vi

 

 

 

The commands cat ,less ,more ,head,tail and vi can be used to read files.

 

 

 

 

cat

 

 

The syntax of to read a file using the command cat is

 

cat <options> <files>

 

 

Options:

 

-A: shows all characters like non printing characters and control characters

-n: number all the lines including the blank ones

-b: Number all the lines

-s: Squeeze the empty lines

-E: Shows end of line with a $ symbol

 

 

 

Usage:

 

1) To read a file use the command cat <filename> to read multiple filenames user cat <filename 1 > < filename 2>

 

[root@client1 test]# cat file_1 file_2 file_3

THIS

IS

LINUX

[root@client1 test]#

 

 

Same thing can be achieved by using cat file* or cat f* or cat file_{1..3} or also by using cat file_[1-3]

 

 

 

NOTE:

 

• Cat should only be used if the file is small.cat simply dumps the contents of the file to the STDOUT and creates a problem for scrolling lengthy files,less command is more suitable for lengthy files.

 

• Using cat to read the binary files may render the terminal l useless. Use the command reset to clean the garbled terminal.

 

 

 

 

less

 

 

The command less is a pager that can be used to read a file one page at a time. The man uses the less as its default pager.

The syntax is

 

less <filename>

 

 

• Use arrow keys to scroll

• Pressing enter moves one line at a time

• Pressing k moves back one line at a time

• Pressing space moves one full screen at a time

• Pressing b moves back one full screen at a time

• Pressing g & G to get to the top & bottom of the file respectively

• / <keyword> to search for the keyword in the file

• Pressing q exits the file

• Pressing v opens the vi editor

 

 

 

 

 

Head&Tail Command

 

 

Head & tail command can be used to display certain number of lines from a file. The syntax is

 

head <options> <filename>

 

The head command displays top 10 lines in a file by default,like wise tail command displays last 10 lines of a file by default.

 

Options:

 

-v: Verbose ,prints the file name

-n: Number of files to be read

-q: Quiet,doesn’t read the filename

 

 

Usage:

 

1) To read the first 5 lines of a file called test,which contains digits from 1 to 100,use the command.

 

[root@client1 test]# head -n 5 test

1

2

3

4

5

 

Replacing n with 5 gives the similar output

 

 

[root@client1 test]# head -5 test

 

 

 

 

Tail

 

Just like the head command which read the first 10 lines,tail command reads the last 10 lines of a file by default.

 

[root@client1 test]# tail -n 10 test

 

 

Most of the options are pretty much same as the head command except one. In addition to that using the –f option which stands for “follow” follows a file as it grows, its very useful for monitoring the logs.

 

For example : Using tail –f /var/log/secure will monitor the file secure real-time.When some one connects to the system using ssh ,the changes in the log file can be monitored in real time.

 

Similarly,using the below command

 

[root@client1 test]# watch tail -2 /var/log/secure

 

Gives the same output

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.5: COPYING ,MOVING,RENAMING AND DELETING FILES & DIRECTORIES

 

 

 

Copy

 

 

To copy a file from source to a destination or multiple destination ,the command cp (copy) is used.

 

The syntax of the command is

 

cp <options > <source path/filename > <destination/filename>

 

 

Options:

-i: Interactive

-p: Preserve the ownership and timestamps

-R: Copies the directories recursively

-u: update

 

 

For copy command

 

• If the destination is a file,in that case the copy command overwrites the existing destination with a user prompt

• If the destination is a directory,then the copy command will place the file in the directory

• If the destination doesn’t exist ,the copy will be renamed

• Append a / to the destination, if you intended to copy the contents to a directory.

 

Usage:

 

1) The command given below will copy the file file1 to the destination /mnt and with the filename same as the source.

[root@client1 test]# cp file1 /mnt/

 

2) The command given below will copy file1,file2,file3 and place it under /mnt directory

[root@client1 test]# cp file1 file2 file3 /mnt/

 

 

Same thing could be achieved using the following command also

[root@client1 test]# cp file[123] /mnt

 

Or using any special characters called as meta characters ( more about this later)

[root@client1 test]# cp f* /mnt/

 

This will copy all the files starting with f to the directory /mnt

 

 

3) To copy a directory and its contents use the command.The command given below will copy the directory mydocs and it contents and place the contents under a new directory called mydocs.backup.

[root@client1 test]# cp –R mydocs /mnt/mydocs.backup

 

4) Using the –p options preserves the timestamps and the owner of the file.

 

In unix and linux,a the creator of the file is owner of the file. If a user called tom creates a file,he becomes the owner of the file.If the super-user root copies the file created by tom,in that case root becomes the owner of the copied file. To retain the ownership of the copied file –p is used. ( more about this in file permissions)

 

5) The option –u (update) can be used to to take backups. To take a backup of the directory,with the –u option,the cp command will only consider copying that file from the directory ,that has been recently added to it, instead of copying the entire directory .This is done on the basis of timestamps & is useful while making periodic backups.

 

 

 

Move & Rename

 

 

The command to move a file and rename file is mv ( move).The command mv takes two arguments one is source and another being the destination.The cp command and mv command both work in a similar manner except that fact that the source file in the copying process is retained where as in moving process its not.

The syntax is

mv <options > < source file > <destination file>

 

Options:

 

-f: Use force,no prompt is made

-i: Use interactive method

-u: Update

-R: Recursively

 

 

When more than 2 arguments are given,all the arguments except the last one is considered as source. The last argument is considered as a destination path.

 

The usage of the command is similar to the copy command.

 

 

 

Rename

 

The command to rename a file is same as the move (mv) command.

 

Usage :

 

1) The command given below will rename the file file1 to f1.

[root@client1 test]# mv file1 f1

 

 

2) The command mentioned below will rename the file file2 to f2 ,but will make it a hidden file.( since a . is being used )

[root@client1 test]# mv file2 .f2

 

3) This command will rename the file3 to f3 & move the file one level up.

[root@client1 Desktop]# mv file3 ../f3

 

Using a single dot will rename & move the file to the current directory

 

 

 

 

Deleting

 

 

The command to delete files and directories is rm ( remove) . More than 1 file can be removed at a time. By default, the rm command doesn’t remove directories . The syntax of the command is

 

rm <options > <targets>

 

Options:

-f : Remove files forcefully,with out any prompt

-r: Remove files recursively

-i: Remove files interactively,with multiple prompts

-I : Removes file interactively but with single prompt and is less intrusive.

 

Usage:

 

1) To remove empty Directories use the command rmdir ( remove directory ). To remove files use the command rm.

 

[root@client1 Desktop]# rmdir hi

 

 

[root@client1 Desktop]# rm file1 file2 file 3

rm: remove regular empty file `file1'? y

rm: remove regular empty file `file2'? y

rm: remove regular empty file `file3'? y

 

 

2) To remove a directory along with its contents use the option –r.

 

 

[root@client1 Desktop]# rm documents/

rm: cannot remove `documents/': Is a directory

[root@client1 Desktop]# rm -r documents/

rm: descend into directory `documents/'? y

rm: remove regular empty file `documents/file1'? y

rm: remove regular empty file `documents/file2'? y

rm: remove directory `documents'? y

 

 

3) To remove the directory along with its contents without any prompt use the -r and –f together option.

[root@client1 Desktop]# rm -rf documents/

 

 

 

 

 

 

• Use the command alias and see its out put.

 

[root@client1 Desktop]# alias

alias cp='cp -i'

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias mv='mv -i'

alias rm='rm -i'

 

 

 

Using the command rm simply without any option will prompt the user for his\her permission before deleting the file. The alias rm=’rm-i ’ suggests that. Changing this to alias rm=’rm’ will not ask for any permission before deleting the files. Similarly regarding cp and mv user permission is sought before overwriting the file if the destination already has a file with the name same as source file.

 

 

 

 

File

 

 

The content of the file can be determined by using the command file. The content of the file can be known without actually opening the file.

 

Usage :

 

 

1)The command given below examines three types of file, separated with a colon (;)

 

[root@client1 Desktop]# file dir ; file 1 ; file /usr/share/backgrounds/abstract/Flow.png

dir: directory

1: ASCII text

/usr/share/backgrounds/abstract/Flow.png: PNG image, 1920 x 1200, 8-bit/color RGBA, non-interlaced

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.6: FILE CONVERSION FROM UNIX TO DOS AND DOS TO UNIX

 

 

 

In order to open the files that are created in unix or linux ( in command mode) in DOS use the command unix2dos and to open the files that are created in DOS in unix or linux use the command dos2unix.

 

The syntax is command <options > < file to be converted>

 

 

Options:

 

-k : Will retain the timestamps

-n: Change the output file name to something else

 

Usage:

 

1) Converts the source unix file to a new destination DOS file .Converts the file file.unix

 

[root@client1 Desktop]# unix2dos -n articles.unix articles.dos

unix2dos: converting file 1 to file 3.dos in DOS format ...

 

2) Converts the DOS file to unix file

 

[root@client1 Desktop]# dos2unix file_dos

 

 

Note: Use the od –bc command to see the differences between a dos file and a unix file.

 

 

 

Before converting to DOS file

 

[root@client1 Desktop]# od -bc file_unix

0000000 124 150 151 163 040 151 163 040 165 156 151 170 012 117 160 145

T h i s i s u n i x \n O p e

0000020 162 141 164 151 156 147 040 163 171 163 164 145 155 012

r a t i n g s y s t e m \n

0000036

 

After converting it to a Dos file

 

[root@client1 Desktop]# od -bc file_unix

0000000 124 150 151 163 040 151 163 040 165 156 151 170 015 012 117 160

T h i s i s u n i x \r \n O p

0000020 145 162 141 164 151 156 147 040 163 171 163 164 145 155 015 012

 

Converting a unix file to dos file will add an \r to every \n as seen in the above example.

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.7: UNDERSTANDING HARDLINKS & SYMBOLIC LINKS

 

 

Hardlinks

 

 

 

Using hardlinks we can create multiple names for a single file, that is we can create aliases or different names that refer to the same contents of a particular file. In a hard-link the file names point to the same physical data stored in the memory.

 

• To create multiple hard links the only that names to be done is specify the name of any existing link,the operating system will resolve the location of the actual data. Any number of hard links can be created.

 

• The hard links have the same inode and represent the same data on the drive as the source file.

 

• Hard links do not create duplicate files ( or duplicate data stored ) they just create different file names with same inode value.

 

• Changes that are made in the aliases will be updated to the original file,including the file permissions.

 

• Hardlinks to directories cannot be made & hardlinks cannot span over a different partition or file system.

 

 

 

Note: When the command rm is used,it doesn’t actually delete the data,it just unlinks.

 

 

Consider the image shown below:

 

The data stored on the disk has 2 links and it can be accessed via FILE1 (or) FILE2,when FILE1 is deleted, the data can still be accessed via FILE2,so in a way hard links can act like a backup.

 

 

The command for making a hardlink is ln ( link)

 

 

[root@client1 Desktop]# cat >> FILE1

This is linux

 

[root@client1 Desktop]# ln FILE1 FILE2

[root@client1 Desktop]# ls -li

total 8

81711 -rw-r--r-- 2 root root 14 2009-03-21 05:03 FILE1

81711 -rw-r--r-- 2 root root 14 2009-03-21 05:03 FILE2

 

 

In the first example after creating a file with filename FILE1 ,we have created a hardlink using the command ln . Interesting fact is ,the inode numbers of both the links will be the same (81711) and their size will also be same. Secondly,after creating the file FILE1 the link count will be 1, and after creating a hardlink FILE2 the links count is 2, which can be see in the above example.

 

 

 

You can hard link an existing file more than once, and doing this will increment the link count by +1 and will make the total 3 for the above example. The act of removing or un linking will decrement the link count by -1.

 

[root@client1 Desktop]# ln FILE2 FILE3

[root@client1 Desktop]# ls -li

total 12

81711 -rw-r--r-- 3 root root 14 2009-03-21 05:03 FILE1

81711 -rw-r--r-- 3 root root 14 2009-03-21 05:03 FILE2

81711 -rw-r--r-- 3 root root 14 2009-03-21 05:03 FILE3

 

By removing any of these links the data can still be accessed. In the above examples the data is no way being duplicated, its only that multiple filenames are being created by referring to an inode number.

 

 

• NOTE: The problem with hardlinks is ,the file ( or the pathnames) must be on the same file system, thats because the inode number being shared is common between them and is unique to a filesystem. Every file-system has its own inode table which is unique from the other file systems.

 

• The second problem is hardlinks cannot be created for directories.

 

• To create the links forcefully consider using the option f , in case the filename already exists.

 

 

For example

To hard link a file called file_100 to another file with a name file.backup , but file.backup already exists with a different inode value and data as shown below:

 

[root@client1 Desktop]# ls -li

total 8

81856 -rw-r--r-- 1 root root 3 2009-03-21 06:34 file_100

81855 -rw-r--r-- 1 root root 22 2009-03-21 06:35 file.backup

 

Note the inode values are different.

 

Lets try creating the hard link without the force (f) option and see the error:

 

[/b][/i]

[root@client1 Desktop]# ln file_100 file.backup

ln: creating hard link `file.backup': File exists[/b][/i]

 

The file file.backup already exists and contains someother data ,to bypass this error use the –f option & we get the following output.

 

[root@client1 Desktop]# ln -f file_100 file.backup

[root@client1 Desktop]# ls -li

total 8

81856 -rw-r--r-- 2 root root 3 2009-03-21 06:34 file_100

81856 -rw-r--r-- 2 root root 3 2009-03-21 06:34 file.backup

 

Now the inode values are same ,where as before file.backup had different inode value

 

 

 

Soft links

 

 

 

• A soft link is also called as a symbolic link

 

• The softlink can be created for directories as well as files on a different filesystem

 

• Unlike Hardlinks the softlinks don’t have similar inode values and a softlink is entirely a different file than the source file.

 

• The softlink actually creates a newfile ,where the new file refers to the actual file.

 

• The softlinks can be considered as a shortcut, once the actual file is deleted the softlink with rest of the files is broken, and when the softlinks is deleted only the link is broken and the main file is still accessible

 

 

Usage:

 

In the example shown below the option –s is used to create the soft link.

 

[root@client1 Desktop]# ln -s file1 file2

[root@client1 Desktop]# ls -li

total 4

81711 -rw-r--r-- 1 root root 17 2009-03-21 06:47 file1

81856 lrwxrwxrwx 1 root root 5 2009-03-21 07:09 file2 -> file1

 

 

Here,note that the inode values for the both files are different, since file2 is a different file by itself with some data in it. This can be verified by looking at the size. The actual file file1 which contains some data is of 17 bytes and the soft link file2 is of size 5 bytes.

 

The actual contents of file 2 are the path name that the symbolic link is referring to, which is file1. The letter l represents a symbolic link.

 

 

< will add images>

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.8: Learning to mount a cd\dvd-rom

 

 

 

 

Mounting is the process of creating a logical link between a directory and the file partition to access. In order to learn to mount devices like cdrom,usb devices and other devices e.t.c we need to create something called a mount point.

 

The syntax of mount command is :

mount < options > <Device name > < Mount point>

 

To mount a cd-rom firstly create a directory called dvdrom or anything of your choice,anywhere on the file system & then use the command mount.

 

 

 

• To mount use the commands

 

 

 

[root@client1 Desktop]# mount /dev/dvdrw dvdrom/

mount: block device /dev/sr0 is write-protected, mounting read-only

[root@client1 Desktop]# cd dvdrom/

[root@client1 dvdrom]# ls

autorun.inf Images Install PDFs Product Utils Videos

 

 

Normally the system should auto-mount your cdrom or dvdrom to /media.

 

 

 

• To access the device go to the folder dvdrom and do ls.

 

To unmount the device , first come out of the directory dvdrom and then type the command umount.

[root@client1 Desktop]# umount /dev/dvdrw

 

 

• To eject the cd\dvd use the command

[root@client1 Desktop]# eject /dev/dvdrw

 

 

• To Close the tray use same command with the option –t ( tray)

[root@client1 Desktop]# eject -t /dev/dvdrw

 

 

 

Mounting of partitions will be discussed later

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.9: Using the history & script command

 

 

 

 

The commands history and script are extremely useful to to see what all commands you have used in the past along with the output\result of the commands. You may consider the above to commands something like an archive.

 

The advantage of these commands is to verify if there was any mistake in the command which yielded an unexpected output and also to repeat commands.

 

 

History

 

 

 

The history command is used to see the commands that you have used in the past. The history command only shows the commands that we have entered but not their output or result. The bash shell stores all the commands in a file called /home/<username>/.bash_history

 

 

 

Usage:

 

 

1) Typing simply the command history will show all the commands, by default the shell stores around 1000+ commands

 

2) To execute the the previous command type !!

 

3) To execute the previous command that started with a character use !<character> for ex: !c , may execute the command clear if that was the recent command that was executed.

 

4) To see the last command executed press ESC. ( press escape and the dot )

 

 

5) To see the last commands execute without seeing the entire history list press the arrow keys

 

 

 

Examples:

 

• Executing the command date

 

[root@client1 Desktop]# date

Sat Mar 21 08:03:52 IST 2009

 

• Running !! will execute the previous command date

[root@client1 Desktop]# !!

date

Sat Mar 21 08:03:54 IST 2009

 

• Running !d will exectute the previous command starting with letter d

[root@client1 Desktop]# !d

date

Sat Mar 21 08:03:57 IST 2009

[root@client1 Desktop]#

 

 

 

 

Script

 

 

 

Since history command doesn’t store the output of the command invoked ,the script command can be used to do this. The script command along with displaying the contents printed on the terminal can also be used to store it in a file. For more information use man script

 

Usage:

 

1) Typing script will start the recording your terminal and store in a file called typescript.

 

[root@client1 Desktop]# script

Script started, file is typescript

 

[root@client1 Desktop]# ls -l

total 4

drwxr-xr-x 2 root root 4096 2009-03-21 07:36 dvdrom

[root@client1 Desktop]# exit

exit

Script done, file is typescript

 

After invoking the script command ,the command has stored the command ls and its output in the file typescript. To read the file use cat. You can also specify the filename of your choice by issuing script <filename>

 

 

2) The Above method stores your session in a file, Instead of doing this, you can have the script command paste the contents of a terminal (say of tty2) on another terminal ( say on tty3). If root logins in tty3 and a normal user in tty2 the root can view the activities of normal user on his terminal in real time.

 

To do this ,the root can login into tty2 ( where the normal user will log in) and type in to invoke the script command.

 

[root@client1 Desktop]# script /dev/tty3

Script started, file is /dev/tty3

 

What this does is redirect the output of tty2 to tty3, instead of sending it to a typescript file.

0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.10: Something about the inode table

 

 

In this segment we will examine what is an inode (index node) ,what it consists of and how the command like cp, mv, rm and ls actually work.

 

 

What is an inode table and an inode??

 

• An inode table is a list of all files (including directories) that are present on an ext2 or ext3 file system. The inode table consist of inodes or index nodes which has information about the files. The inodes are mere entries in the inode table.

 

• An inode stores the information or attributes of a file like

 

- UID

- GID

- FILE TYPE

- FILE SIZE

- FILE PERMISSIONS

- DATE & TIME

- NUMBER OF LINKS

- LOCATION OF THE DATA ON THE DISK (POINTERS)

 

 

Note: The inode doesn’t store the file name or the inode number,they are stored in the directory the file is located in.

 

How the inode functions when a file is created & read

 

• When a file named foo is created, the filename and the inode number are stored in the directory. The details or the attributes of the file are stored in an inode table else where on the disk.

 

• When the file is read with a cat or listed with ls then the kernel tries locating the file in the directory & the inode number.

 

• Then the kernel reads the inode table and the entries of the inode in it,to fetch the filesize & the address of disk blocks that contain the data of the file.

 

• It then goes to each block and reads the data till the number of characters displayed is equal to the file size!

 

 

 

 

How cp, mv & rm work

 

 

• When a file is copied, the kernel will allot it an inode number( which is different from the source file) along with the filename which is allotted by the command.

 

[root@client1 ~]# ls -li

total 0

408020 -rw-r--r-- 1 root root 0 2009-03-24 16:49 file1

[root@client1 ~]# cp file1 ./file2

[root@client1 ~]# ls -li

total 0

408020 -rw-r--r-- 1 root root 0 2009-03-24 16:49 file1

408027 -rw-r--r-- 1 root root 0 2009-03-24 16:49 file2

 

 

• When a file is moved ( or renamed) the name of the file is changed in the directory without disturbing the inode number.

 

 

[root@client1 ~]# mv file2 file3

[root@client1 ~]# ls -li

total 0

408020 -rw-r--r-- 1 root root 0 2009-03-24 16:49 file1

408027 -rw-r--r-- 1 root root 0 2009-03-24 16:49 file3

 

 

• When the file is removed the inode which is associated with that file is freed.

 

< Will add images >

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

Topic 4.211:The seven fundamental file types in unix \linux

 

 

 

 

 

We know that a file is a file and even a directory is a type of file. When we do ls –l :

 

drwxr-xr-x 2 root root 4096 2009-03-24 17:05 songs

 

The d represents what type of file is songs, and the file songs is a directory and a in the place of d represents the file is just an ordinary file ( could be a text file)

-rw-r--r-- 1 root root 0 2009-03-24 16:49 file1

 

In total there are 7 types of file in linux\unix. The table given below shows the following file types

 

 

2.jpg

 

 

• In linux\unix the hardware devices are special type of files. A device can be accessed via multiple different names. The device files are found in the /dev directory.

 

 

[root@client1 ~]# ls -l /dev/

total 0

crw-rw----+ 1 root root 14, 12 2009-03-24 14:11 adsp

crw-rw----+ 1 root root 14, 4 2009-03-24 14:11 audio

drwxr-xr-x 2 root root 80 2009-03-24 14:11 bsg

drwxr-xr-x 3 root root 60 2009-03-24 14:11 bus

lrwxrwxrwx 1 root root 3 2009-03-24 14:11 cdrom -> sr0

brw-rw---- 1 root disk 1, 0 2009-03-24 14:11 ram0

brw-rw---- 1 root disk 1, 1 2009-03-24 14:11 ram1

brw-rw---- 1 root disk 1, 10 2009-03-24 14:11 ram10

brw-rw---- 1 root disk 1, 11 2009-03-24 14:11 ram11

brw-rw---- 1 root disk 1, 12 2009-03-24 14:11 ram12

 

 

The device files are categorized into two types the block devices and the character devices represented through b and c respectively.

 

 

Block devices

 

A block represents a chunk like 512bytes ,1024 bytes e.t.c,When a file is written the write command operates in chunks or blocks. The data is first transferred to a cache,and then the kernel writes to the disk later on. So, the devices that use the buffer cache & the data is written in terms of blocks and chunks are called as block devices and are represented with a b.

 

Ex: hard disks, cd-roms e.t.c

 

 

 

Character devices

 

Character devices are those devices that do not use a cache and the device is directly accessed. For example printers or tape drives. The data is written or read one character at a time.

 

 

Pipe

 

A pipe is a file which doesn’t store any data, rather it passes on the data from one process to another. A pipe can be used,to write data into the pipe by a process and another process reading that from the pipe.

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

<...Chapter 4 contd...>

 

 

Topic 4.2.12: Archiving and compressing files

 

 

 

Archiving

 

 

 

The process of combining multiple files together for easy distribution is called as archiving. Archiving doesn’t compress the files. The command to archive the files is tar ( tape archive).

 

The syntax of the command is :

tar <options> <Destination> < source files>

 

 

Options:

 

-c : Creates archive

-v : Verbose

-f : To assign the filename

-t: Display the contents of the archive

-x: Extract the contents of the archive

-z : Archive + Compress

 

Usage:

 

1) To create a tar use the command

 

[root@client1 ~]# tar -cvf files.tar f1.txt f2.txt f3.txt f4.txt

 

2) To view the contents of the tarball files.tar use the command

 

[root@client1 ~]# tar -tvf files.tar

-rw-r--r-- root/root 0 2009-03-24 19:39 f1.txt

-rw-r--r-- root/root 48894 2009-03-24 19:40 f2.txt

-rw-r--r-- root/root 48894 2009-03-24 19:40 f3.txt

-rw-r--r-- root/root 78888897 2009-03-24 19:40 f4.txt

 

3) To extract the contents of the tar use the command

 

[root@client1 ~]# tar -xvf files.tar

f1.txt

f2.txt

f3.txt

f4.txt

 

 

 

Compressing

 

 

While tar is used for archiving, for compression use gzip.

 

 

• To compress use the command

[root@client1 ~]# gzip files.tar

 

• To Decompress use the command

[root@client1 ~]# gzip -d files.tar.gz

 

You can also use gunzip

 

• To view the contents use gzcat or gzmore

 

 

Archiving + Compression

 

 

To achieve archiving and compression together use the command zip. The syntax of the command is

zip <options> <destination file> < source files>

 

Options:

 

–c : To add comment

-r : To zip recursively

-P :To password protect the zipped file

-g : To grow the zip file by adding another zip

-e: To encrypt the contents of the zip

-v: view the contents

 

 

1) To zip along with verbose use the command

 

[root@client1 ~]# zip -v f2.zip f2.txt

adding: f2.txt (in=48894) (out=22602) (deflated 54%)

total bytes=48894, compressed=22602 -> 54% savings

 

 

 

 

 

2) To View the contents of the file without extracting use the command

 

[root@client1 ~]# unzip -v f2.zip

Archive: f2.zip

Length Method Size Ratio Date Time CRC-32 Name

-------- ------ ------- ----- ---- ---- ------ ----

48894 Defl:N 22602 54% 03-24-09 19:40 8c7685ad f2.txt

-------- ------- --- ------- 48894 22602 54% 1 file

 

 

 

3) To extract the contents of the zip file use the command

[root@client1 ~]# unzip f2.zip

 

 

4) To password protect the zip archive use the –P option, where –P should be followed by the password.

 

[root@client1 ~]# zip -vP pass f.zip f2.txt

adding: f2.txt (in=48894) (out=22602) (deflated 54%)

total bytes=48894, compressed=22614 -> 54% savings

 

[root@client1 ~]# unzip f.zip

Archive: f.zip

[f.zip] f2.txt password:

 

 

 

 

 

 

 

 

This completes chapter 4

Edited by TESLA.COIL
0

Share this post


Link to post
Share on other sites

CHAPTER-5

 

User Account Administration & File permissions

 

 

 

Objectives:

 

< to be added>

 

 

 

Users

 

 

 

• Anyone who logs into a system is considered as an user. Every user who logs into a system as a username and a user identification number also known as UID. The username and the UIDs have to be unique.

 

• The username and the UID and other characteristics related to the user are stored in a file called as the passwd file which is located at /etc/passwd.

[root@client1 ~]# tail -3 /etc/passwd

jax:x:500:500::/home/jax:/bin/bash

tesla:x:501:501::/home/tesla:/bin/bash

tom:x:502:502::/home/tom:/bin/bash

 

 

The above command shows the last 3 lines of the file passwd ,where each line presents a user and his\her properties. The : acts like a delimiter for each and every field.

 

• The first field is the username field, in the above example jax, tesla, tom are the users .

 

• The second file is the password field which is empty, The password for the users are stored in the /etc/shadow file, where the contents are present in encrypted format.

 

jax:$6$bF1zjUBL48/sDOIY$10eVQHu29/dcJptLjp6fasRC4CnaLtd6LZXTdXkwH2z3txhHHCUG0QtuKpmJ8edGt./RA6Z/cpK4/ST.9yUCd0:14315:0:99999:7:::

 

The above example shows the password of jax in encrypted format , the password for jax is just 4 characters long.

 

• The third & the fourth fields are the UID & the GID which are unique for every user.GID stands for group id, when a user is created a group with that name is created by default. Both UID and GID have to be unique for every user across a system.

 

• The fifth field is the comment field which can be used to store any kind of additional information about the user or it can be used to store the name of the user. For example

 

[root@client1 ~]# tail -1 /etc/passwd

tom:x:502:502:he is an ordinary user:/home/tom:/bin/bash

 

• The sixth field is the home directory field, which specifies the home directory of a user or the location where the user goes after he logins. The user has full permission over his\her own home directory then can create or remove files in their home directories.

 

• The seventh field or the last field specifies the type of shell a user gets after he\she logins into the system .

 

 

 

To get additional information about a user ,use the command finger or id.

 

[root@client1 ~]# finger root

Login: root Name: root

Directory: /root Shell: /bin/bash

On since Wed Mar 25 19:06 (IST) on pts/0 from client1.tesla.com

New mail received Wed Mar 25 15:09 2009 (IST)

Unread since Thu Mar 12 11:31 2009 (IST)

No Plan.

 

 

 

Chapter 5 will be completed by tomorrow For any tips,suggestion or for any additional info PM me :)

0

Share this post


Link to post
Share on other sites

Hi,

 

Thanks a lot for the post.

It is very informative and useful.

 

Can you please complete the other chapters too, so that I can start preparing for rhce :mellow:

 

 

0

Share this post


Link to post
Share on other sites

Great job but Where is the other chapters. If you started a work that you must complete this job. A lot humans waiting other chapters. Please write other chapters.

0

Share this post


Link to post
Share on other sites

sorry well i actually wrote other chapters i havent posted them yet since i am pretty busy with job :( i promise that i will paste it soon here :) well the thing is i have decided to put the tutorial on a separate blog,i will put the entire thing on the blog soon :)

0

Share this post


Link to post
Share on other sites

If you wrote them, please post under this topic. Then If you want you can post your blog. You must complete this topic.

0

Share this post


Link to post
Share on other sites

hello tesla,

 

can you please complete the chapters, this is my second request to the post.

 

i need it asap.

 

Regards,

bunty

0

Share this post


Link to post
Share on other sites

Dear moderator,

 

You must remove from pinned to this topic. Because this topic havent update for a long time.

 

Thanks.

0

Share this post


Link to post
Share on other sites

Dear moderator,

 

You must remove from pinned to this topic. Because this topic havent update for a long time.

 

Thanks.

 

Just be patient ...and be Thankful mate ....THANXXXXXXXXXXX TESLA.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0