Sunteți pe pagina 1din 11

UNIX/RHEL6 Labs

File Mgmt.

1. File can be created using cat, touch and vi cmd.

--> Using cat cmd.

# cat > test

This is my test file


We are learning cat cmd

ctrl+d <--- To save and quit cat cmd.

2. To display contents of file

# cat test

3. To append the file

# cat >> test

1
2
3
4
5

ctrl + d <----To save and quit the file.

4. To check file type

# file test

5. Touch cmd can create an empty file and update time stamp

# touch test1
# touch test11 test12 test13
# touch test{21,22,23}
# touch test-{1,2,3}.log
# touch {1,2,3}.log

6. To remove / delete the file

* rm cmd. in linux supports interactive deletion.

# rm test1
# rm test11 test12 test13
# rm {1,2,3}.log
# rm *.log

# rm -f test{21,22,23} <----To delete the data forcibly

Directory Mgmt.

1. To make directory

# mkdir chn
# mkdir chn1 chn2 chn3
# mkdir chn{11,12,13}

2. To create dir tree

# mkdir -p universe/world/india/TN/chn/nsn

3. To verify Dir tree.

# tree universe

4. To call / change dir

# cd chn

5. To check present working directory.

# pwd

* Every dir holds two hidden dir.

. <--- Current dir.


.. <--- Parent dir.

6. To go to parent directory.

# cd ..

7. To go to 4 level up

# cd ../../../../

8. To jump between current and previous dir.

# cd -

9. To go to logged-in user's home dir.

# cd
# cd ~

10. To remove an empty dir.

# rmdir chn
# rmdir chn1 chn2 chn3

11. To remove non-empty dir.

# rm -r universe <--- -r does recursive deletion.

# rm -rf universe <--- -f overrides interactive deletion.

Listing Files and Directories:

1. # ls <-- to list files/dires present in current dir.

# ls -a <--- To list files/dires present in current dir including hidden object.


-a is all
# ls -p <--- Put / to diectories.

# ls -R <--- List the dir recursively


# ls -R universe

# ls -i <--- To list i-node no of file/dir.


# ls -i test

# ls -l <--- To long list files and dir.


# ls -l test
# ls -l /etc

# ls -lt <----t is time


# ls -ltr <----r is reverse

Disk usage Utilities

du ( Disk Usage ) It list size of files/dir.

# du chntest <--- list the size in blocks Unit: 1 Block = 1 KByte

# du -k chntest <--- list the size in kilobytes

# du -h chntest <--- List the size in Human readable format


# ls -lh chntest <--- l is long list and h is human readable.

# du -sh /etc <--- List specific dir. size in human readable format.

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

df ( Disk Free ) It list size of mounted partitions including total/free/used


size.

# df <---- It list mounted partitions in blocks

# df -k <--- It list mounted partitions in KBytes

# df -h <--- It list mounted partition in Human readable format

# df -h /boot
# df -h /
# df -h /home

Compression/Uncompression Utilities:

1. gzip/gunzip/zcat

# gzip chntest <--- To compress the file

* It compress the file and renames it with .gz ext.

# zcat chntest.gz <--- to read compressed file.

# gunzip chntest.gz <--- To uncompress the file.

2. bzip2/bunzip2/bzcat

# bzip2 chntest <---To compress the file


* It compress the file and renames it with .bz2 ext.

# bzcat chntest.bz2 <--- to read compressed file.

# bunzip2 chntest.bz2 <--- To uncompress the file.

3. xz/unxz/xzcat

# xz chntest <---To compress the file

* It compress the file and renames it with .xz ext.

# xzcat chntest.xz <--- to read compressed file.

# unxz chntest.xz <--- To uncompress the file.

History Commands:

# history <--- List all history cmds.

# !! <--- To repeat previous cmd.

# !c
# !cl<--- To repeat the cmd. begining with cl

# !<Cmd. History no.> To execute cmd by history no.


# !115

# history -c <--- To clear the history

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

****** Network Configuration and troubleshooting

Database Files:

1. /etc/hosts <--- Maps hostname with IP Address and vice versa.

2. /etc/sysconfig/network <--- It holds hostname, networking status and gateway

3. /etc/sysconfig/network-scripts/ifcfg-eth0 <--- It holds IP address, netmask,


gateway, NM control status, IPv6 status, etc. for eth0 lan interface.

4. /etc/resolv.conf <--- It holds default domain to search and nameserver i.e. DNS
server IP Addresses.

5. /etc/nsswitch.conf <--- It holds name server search wrt. local system or dns or
nis or nisplus or ldap.

Exer:

1. Add network system's HN and IP Address entry to local system in /etc/hosts file.
Check connectivity using name and IP Address.
2. To set temp. hostname to the computer

# hostname nsnchennai

* It is set temp. If system is rebooted then the hostname mentioned in the file
/etc/sysconfig/network will be loaded by kernel.

3. To setup IP manually.

# system-config-network

4. To check IP Address

# ifconfig
# ifconfig eth0

# ip addr show
# ip addr show eth0

5. To view default gateway or route

# ip route
# netstat -r ( r <--- Routing Table )

6. To verify DNS entries from /etc/resolv.conf

# nslookup google.com <--- Forward Lookup Zone


# nslookup 74.125.136.94 <-- Reverse Lookup Zone

# host google.com <--- Forward Lookup Zone


# host 74.125.136.94 <-- Reverse Lookup Zone

# dig google.com <--- Forward Lookup Zone


# dig -x 74.125.136.94 <-- Reverse Lookup Zone

7. To setup Ip Address temp.

# ifconfig eth0 10.10.10.1 netmask 255.255.255.0

* It is temp. set. If system is rebooted then IP Address will be loaded from


"ifcfg-eth0" file.

8. To restart network service

# service network stop


# service network start

# service network restart

# /etc/rc.d/init.d/network stop
# /etc/rc.d/init.d/network start

# /etc/rc.d/init.d/network restart

9. To check network service status

# service network status


# /etc/rc.d/init.d/network status

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

User Account Mgmt.

cmd:

useradd <-- To create new user a/c

usermod <-- To modify existing user a/c properties wrt. UID,GID,Home Dir., Login
Shell etc.

userdel <-- To remove/delete user a/c

passwd <-- To set/reset user a/c password

groupadd <-- To create new group

groupmod <-- To modify group properties wrt. GID and Group Name

groupdel <-- To remove/delete group

gpasswd <-- To set/reset group password

chown <-- To setup User/Group ownership on files/dir.

chgrp <-- To change group ownership only.

* We can add member to the group while user a/c creation using "useradd" cmd.
If user a/c exist then we can use "usermod" cmd. to add existing user to the group
as its member.

chmod <-- To setup file/dir. permissions.

newgrp <-- To login to the group.

Exer:

1. create user a/c raj and set it password.

# useradd raj
# passwd raj

2. To view user a/c details

# finger loginname
# finger raj

3. To view user a/c UID and GID

# id loginname
# id raj

4. Create user a/c "james" with following properties,

UID=1000
Comment=System Crasher
Login Shell= csh ( /bin/csh )

# useradd -u 1000 -c "System Admin" -s /bin/csh james

-u <-- UID
-c <-- Comment
-s <-- Login Shell

5. Setup login shell /bin/ksh and comment "system analyst" to user a/c prabhakaran.

# usermod -s /bin/ksh -c "System Analyst" prabhakaran

6. Rename user a/c "prabhakaran" to "karan" and rename its home dir.

# mv /home/prabhakaran /home/karan <-- Renames Home dir. only

# usermod -l karan -d /home/karan prabhakaran

-l <-- New login name


-d <-- Specify/update Home Dir. path

7. Delete user a/c jack with home dir.

# userdel -r jack <-- -r is delete home dir.

8. Delete user a/c james w/o home dir.

# userdel james

9. To lock user a/c

# passwd -l karan <-- -l is lock

10. To unlock user a/c

# passwd -u karan <-- -u is unlock

11. To delete user a/c password

# passwd -d karan <-- -d is delete password

12. Setup Minimum, Maximum and Warning days for user a/c raj.

Minimum Age of Password: 1 Day


Max. Age of Password : 30 Days
Warning : 3 Days

# chage -m 1 -M 30 -W 3 raj

-m <-- Min
-M <-- Max
-W <-- Warn

13. Display Password Age details for user a/c raj.

# chage -l raj <-- -l is list password age details

14. Setup a/c expiry to 31 Dec. 2016.


# chage -E YYYY-MM-DD raj
# chage -E 2016-12-31 raj

15. Setup a/c expiry to "never".

# chage -E -1 raj

16. Create new group "tech"

# groupadd tech

17. To check group details of group "tech"

# grep tech /etc/group

18. Create group "support" with GID 600.

# groupadd -g 600 support <-- -g is GID

19. Add existing user a/c "raj" to group "tech" and "support"

* User a/c "raj" has its own group called "raj" which is his primary group. Groups
"tech" and "support" will be his secondary groups.

# usermod -G tech,support raj <-- -G is Secondary Group

20. Create user a/c priya and add it to secondary groups "tech" and "support".

# useradd -G tech,support priya

21. Rename the group "tech" to "research".

# groupmod -n research tech <-- -n is New Groupname

22. Change GID of group "research" to 2000.

# groupmod -g 2000 research

23. Delete the group "support"

# groupdel support

24. Setup password to group "research"

# gpasswd research

25. Login to the group "research"

# newgrp GroupName
# newgrp research

26. Change the GroupOwner of dir. /data.

# chgrp options groupname file/dir

# chgrp research /data


# chgrp -R research /data
27. Change UserOwner to "raj" and GroupOwner to "support" for "/data" dir.

# chown option username:groupname file/dir

# chown raj:support /data


# chown -R raj:support /data

28. chmod: This cmd. is use to set/reset permissions on files/dir.

* There are three Basic Permissions


1. Read (r)
2. Write (w)
3. eXecute (x)

--> Numeric equivalents of these basic permissions are,


read --> 4
write --> 2
execute --> 1

* Umask --> It is filter used by system to calculate effective permissions to be


applied to the file/dir. while creating it.

Umask of the system can be checked by cmd.


# umask

Default Umask value for the root user (UID=0): 0022


Default Umask value for non-root user (UID#0): 0002

Effective Permissions for the file: 666 - Umask


Effective Permissions for the dir.: 777 - Umask

* Default permissions for the file: 644


Default permissions for the dir.: 755

* "chmod" cmd. syntax:


#chmod option permission filename/dirname

Exer.:

Current File Permissions on file called "test" : - rw- r-- r--


Expected File Permissions on file called "test": - rwx r-x -wx

# chmod 753 test


# chmod u=rwx,g=rx,o=wx test
# chmod u+x,g+x,o-r+wx test

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

Understanding runlevels and grub (GRand Unified Bootloader)

Exer:

1. Change default runlevel to 3 i.e. multiuser mode with NFS.

* Default runlevel can be set in the file "/etc/inittab"

# vi /etc/inittab

id:3:initdefault:
(save and quit the file.)

* Now onwards system will always boot in runlevel 3.

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

Exer:

2. Reset forgotten root a/c password.

* Go to "single user mode" from Grub menu. System will enter in shell without
"root" user password.

Execute,
# passwd root

then

# exit

* System will boot into default runlevel, now login by new password.

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

Managing Processes

To list all processes running on local terminal

# ps

To list all processes running on all the terminals

# ps -a <--- all

To list all processes running on system

# ps -e <-- Every

To list all the processes running on system in Full format

# ps -ef

To list all kill signals

# kill -l

( Default kill signal is 15 i.e. SIGTERM, Forcible kill signal is


9 i.e. SIGKILL.)

To kill specific process

# kill <PID>
# kill 123

To kill spe. process forcibly

# Kill -9 <PID>
To set process priority.

# nice -n -20 yes

To renice process priority

# renice -n 10 -p 3787

* Manange the processes using top (table of process ) cmd.

# top
---------------------------------------------------------------

Managing Services

To check all installed services status ( enabled or disabled )

# chkconfig --list | less

To enabled specific service on runlevel 2 and 3

# chkconfig --level 35 dhcpd on

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

S-ar putea să vă placă și