Saturday, July 17, 2010

/etc Directory

/etc directory contains configuration files of all the programs and services that run in a linux machine. A Linux service is an application (or set of applications) that runs in the background waiting to be used, or for carrying out essential tasks. This directory is one of the most used directories by the system administrators. There are many useful files and directories that are used by a system administrator on a day-day basis.

How does a system administrator tell what services are running, and more importantly, how does he set up one of his own?

Let's start by looking at how the system is set up, and in particular at the directory /etc/rc.d. Here you will find either a set of files named rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6, or a set of directories named rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, and rc6.d. You will also find a file named /etc/inittab. The system uses these files (and/or directories) to control the services to be started.

The file /etc/inittab will have entries something like this:

id:4:initdefault:l

0:0:wait:/etc/rc.d/rc.0l

6:6:wait:/etc/rc.d/rc.6x

1:4:wait:/etc/rc.d/rc.4


The boot process uses these parameters to identify the default runlevel and the files that will be used by that runlevel. In this example, runlevel 4 is the default and the scripts that define runlevel 4 can be found in /etc/rc.d/rc.4.

Runlevel is the point at which the system is entered. Runlevel 1 is the most basic configuration (Simple single user access using an text interface), while Runlevel 5 is the most advanced (multi-user, networking and a GUI front end). Runlevels 0 and 6 are used for halting and rebooting the system.

System Boot Process:
When booting multi-user, the kernel runs init (located in /sbin/init), which spawns a shell (/bin/sh) to run /etc/rc, which contains commands to check the consistency of the file-systems, mount the disks, start up system processes, etc. /etc/rc invokes /etc/netstart to configure the network and any associated services, and /etc/rc.local (if it exists) for locally added services.
After /etc/rc has successfully completed, init forks a copy of itself for each terminal in /etc/ttys, usually running /usr/libexec/getty on them. Administrative configuration of system services is controlled by editing the scripts (/etc/rc, /etc/rc.local, /etc/netstart). In some instances, only shell variables need to be changed, in others commands are added, changed, or removed.



/etc/rc

Saturday, July 10, 2010

Most Commonly Used Linux Commands



Host Information

uname .............. Print system information
hostname ........... Print the system's hostname
ifconfig ........... Display or set network interface configuration
host ............... Lookup DNS information
nslookup ........... Lookup DNS information (deprecated)
whois .............. Lookup domain registrants
ping ............... Test reachability of a host
traceroute ......... Display network path to a host

Process Management

ps ................. List processes
w .................. List users' processes
uptime ............. View the system load, amount of time it has been running, etc.
top ................ Monitor processes
free ............... Display free memory
kill ............... Send signals to processes
killall ............ Kill processes by name
nice ............... Set a processes nice value
renice ............. Set the nice value of a running process.
at ................. Run a job at a specific time
crontab ............ Schedule repeated jobs
batch .............. Run a job as the system load premits
watch .............. Run a programm at specific intervals
sleep .............. Wait for a specified interval of time

Disks and File Systems

df ................ Display free space
du ................ Display disk usage
mount ............. Mount a filesystem
fsck .............. Check and repair a filesystem
sync .............. Flush disk caches

File and Directory Basics

cd ................. Change Directory
cp ................. Copy files
file ............... Determine a file's content
ls ................. List files or directories
ln ................. Make a link to a file
mkdir .............. Make a directory
rmdir .............. Remove a directory
mv ................. Move a file
rm ................. Remove a file

Locate Files

find .............. Find files and directories
which ............. Locate commands within your search path
whereis ........... Locate standard file

File Management

ls ................ Display file attributes
stat .............. Display file attributes
wc ................ Count the number of lines, words and characters in a file
file .............. Identify file types
touch ............. Set the time stamp of a file or directory
chgrp ............. Change the group of a file
chmod ............. Change the permissions (mode) of a file
chown ............. Change the owner of a file
chattr ............ Change advanced file attributes
lsattr ............ Display advanced file attributes

File Viewing

cat ............... Display the contents of file
less .............. Page through files
head .............. Show the top portion of a file
more .............. Display screenfuls of a file
tail .............. Display bottom portion of a file
nl ................ Count the number of lines in a file
wc ................ Count the number of lines, words and characters in a file
od ................ View a binary file
tee ............... Display output on stdout and write it to a file simultaneously

File Manipulation

csplit ............ Split a file
cut ............... Display columns of a file
paste ............. Append columns in a file
sort .............. Sort a file
tr ................ Translate chracters in a file
uniq .............. Find unique or repeated lines in a file
xargs ............. Process multiple arguements

File Comparison

diff .............. Find differences in two files
dircmp ............ Compare two directories
cmp ............... Compare two files
comm .............. Compare sorted files
md5sum ............ Compute the MD5 checksum of a file
sum ............... Compute the checksum of a file

File Compression and Archiving

gzip .............. Compress a file using GNU Zip
gunzip ............ Uncompress a file using GNU Zip
compress .......... Compress a file using UNIX compress
uncompress ........ uncompress a file using UNIX compress
bzip2 ............. Compress a file using block-sorting file compressor
bunzip2 ........... Uncompress a file using block-sorting file compressor
zip ............... Compress a file using Windows/DOS zip
unzip ............. Uncompress a file using Windows/DOS zip
tar ............... Read/Write (tape) archives
cpio .............. Copy files to and from archives
dump .............. Dump a disk to tape
restore ........... Restore a dump
mt ................ Tape control programme

Printing

lpr ............... Print files
lpq ............... View the print queue
lprm .............. Remove print jobs
lpc ............... Line printer control program