1) ifconfig = allows the operating system to setup network interfaces and allow the user to view information about the configured network interfaces

Examples

ifconfig

View the network settings on the Ethernet adapter currently used.

ifconfig eth0

View the network settings on the first Ethernet adapter installed in the computer.

ifconfig -a

Display into on all network interfaces on server, active or inactive.

ifconfig eth0 down

If eth0 exists would take it down causing it cannot send or receive any information.

ifconfig eth0 up

If eth0 exists and in the down state would return it back to the up state allowing to to send and receive information.

ifconfig eth0 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255

Assign eth0 with the above values for IP, netmask and broadcast address.

.

2) ifup = bring a network interface up

ifup eth0 – bring up interface eth0

.

3) ifdown = bring a network interfacedown

ifdown eth2 – bring down interface eth2

.

4) ping = ping allows a user to ping another network IP address. This can help determine if the network is able to communicate with the network.

Example:

ping gmail.com – Would ping the gmailhost .com to see if it is alive.

ping gmail.com -c 1 – Would ping the hgmailost .com once and return to the command line

.

5) traceroute = print the route packets take to network host

Examples:

$ traceroute google.co.in — Trace the route for Google Server.

$ traceroute -v 192.168.12.1 — Show more details.

$ traceroute -n server — Print the HOP Address in numeric form.

$ traceroute -I server
— Use ICMP ECHO instead of UDP datagrams.

$ tracerout
e -i eth1 server — Use eth1 for send the probe packets.

$ traceroute server 100
— Sent 100 Bytes packet instead of default 40 Bytes packet.

6) host = simple utility for performing DNS (Domain Name Service) lookups.  It is normally used to convert names to IP addresses and vice versa

Examples:

$ host google.com — Show the IP Address of Google.com.

$ host -v google.com — Show detailed output.

$ host -a google.com — Show more details.

$ host 127.0.0.1 — Do reverse lookup and Show the host name.

$ host -l mydomain.com — List all hosts available in MyDomain.

.

7) dig = DNS lookup utility

Ecamples:

dig yahoo.com

dig 66.94.234.13

dig -x 192.168.52.

dig -t ANY yahoo.com

1) jobs = lists the jobs that you are running in the background and in the foreground

Syntax

jobs [-p | -l] [-n] [-p] [-x] [job id]

If the prompt is returned with no information no jobs are present

jobs -p : list only the PID of process group leader

jobs -l : list only jobs that have change status since last notified by their status

jobs -r : resrict output to running jobs

jobs – s : restrict output to stopped jobs

.

2) bg = place a job in background

Normally user can run a job in background, by adding & at end of the
command (ex: sleep 10 &).

bg is a shell command. It is used to move a job from foreground to the
background, as if it had been started with `&’. If JOB is not present,
the shell’s notion of the current job is used.

Examples (follow all the steps below)

a) $ sleep 100 — Start a dummy job in foreground.   (sleep = waits a x amount of second)
Press Ctrl+z to stop the current job.

b) $ bg — Move the last stopped job to background.

c) $ sleep 150 — Dummy job 1
Press Ctrl+z to stop the current job.

d) $ sleep 140 — Dummy job 2
Press Ctrl+z to stop the current job.

e) $ sleep 130 — Dummy job 3
Press Ctrl+z to stop the current job.

f) $ jobs — List all active jobs.

g) $ bg 2 — Move the 2nd active job to background.

.

.3) fg = continues a stopped job by running it in the foreground

Examples

fg – Typing fg alone will resume the first job were it was left off.

fg 1 – specifying the job (in this case 1) will resume that particular job. The job id can be determined by running bg

.

4) nice = run a command with modified priority

nice command is used to run the given command with its scheduling
priority adjusted. Priority range goes from -20 (highest priority)
to 19 (lowest priority).

Examples:

$ nice — Prints the current priority value.

$ nice ls — Increment the priority value of the ls command
by 10 (Default value) and run.

$ nice -n 5 ls — Increment the priority value of the ls command
by 5 and run.

# nice -n -2 ls — Decrement the priority value of the ls command by
-2 and run.

NOTE: Incrementing the priority value will reduce the priority level
and vice versa. Priority range is -20 (high) to 19 (low).

.

5) renice = renice is used to alters the scheduling priority of one or more
running processes, priority range goes from -20 (highest priority)
to 19 (lowest priority).

Examples:

$ renice +1 123 — Increment the priority value of a process, which
process ID is 123.

# renice +1 123 — Decrement the priority value of a process, which
process ID is 123. (Root only can decrement ).

$ renice +1 -p 123 -p 200 — Same as above. Here no. of process is 2.

$ renice +1 -u sbharathi — Increment the priority value of all
processes, which is owned by a user (sbharathi).

$ renice +1 -g backup — Increment the priority value of all
processes, which is owned by a group (backup).

NOTE: Incrementing the priority value will reduce the priority level
and vice versa. Priority range is -20 (high) to 19 (low).

.

6) at = schedules a command to be ran at a particular time, such as a print job late at night

Syntax
at –  executes commands at a specified time.
atq – lists the user’s pending jobs, unless the user is the superuser; in that case, everybody’s jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, job class.
atrm –  deletes jobs, identified by their job number.
batch – executes commands when system load levels permit; in other words, when the load average drops below 1.5, or the value specified in the invocation of atrun.

Examples

at -m 01:35 < atjob = Run the commands listed in the ‘atjob’ file at 1:35AM, in addition all output that is generated from job mail to the user running the task. When this command has been successfully enter you should receive a prompt similar to the below example.

commands will be executed using /bin/csh
job 1072250520.a at Wed Dec 24 00:22:00 2003

at -l = This command will list each of the scheduled jobs as seen below.

1072250520.a Wed Dec 24 00:22:00 2003

at -r 1072250520.a = Deletes the job just created.

or

atrm 23 = Deletes job 23.

If you wish to create a job that is repeated you could modify the file that executes the commands with another command that recreates the job or better yet use the crontab command.

Note: Performing just the at command at the prompt will give you an error “Garbled Time”, this is a standard error message if no switch or time setting is given.

.

7) top = provide information (frequently refreshed) about the most CPU-intensive processes currently running

Description of the fields

a: PID — Process Id
The task’s unique process ID, which periodically wraps, though never restarting at zero.
b: PPID — Parent Process Pid
The process ID of a task’s parent.
c: RUSER — Real User Name
The real user name of the task’s owner.
d: UID — User Id
The effective user ID of the task’s owner.
e: USER — User Name
The effective user name of the task’s owner.
f: GROUP — Group Name
The effective group name of the task’s owner.
g: TTY — Controlling Tty
The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you’ll see ‘?’ displayed.
h: PR — Priority
The priority of the task.
i: NI — Nice value
The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task’s dispatchability./dd>
j: P — Last used CPU (SMP)
A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).
k: %CPU — CPU usage
The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if ‘Irix mode’ is Off, top will operate in ‘Solaris mode’ where a task’s cpu usage will be divided by the total number of CPUs. You toggle ‘Irix/Solaris’ modes with the ‘I’ interactive command.
l: TIME — CPU Time
Total CPU time the task has used since it started. When ‘Cumulative mode’ is On, each process is listed with the cpu time that it and its dead children has used. You toggle ‘Cumulative mode’ with ‘S’, which is a command-line option and an interactive command. See the ‘S’ interactive command for additional information regarding this mode.
m: TIME+ — CPU Time, hundredths
The same as ‘TIME’, but reflecting more granularity through hundredths of a second.
n: %MEM — Memory usage (RES)
A task’s currently used share of available physical memory.
o: VIRT — Virtual Image (kb)
The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out.

VIRT = SWAP + RES.

p: SWAP — Swapped size (kb)
The swapped out portion of a task’s total virtual memory image.
q: RES — Resident size (kb)
The non-swapped physical memory a task has used.

RES = CODE + DATA.

r: CODE — Code size (kb)
The amount of physical memory devoted to executable code, also known as the ‘text resident set’ size or TRS.
s: DATA — Data+Stack size (kb)
The amount of physical memory devoted to other than executable code, also known as the ‘data resident set’ size or DRS.
t: SHR — Shared Mem size (kb)
The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.
u: nFLT — Page Fault count
The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available.
v: nDRT — Dirty Pages count
The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.
w: S — Process Status
The status of the task which can be one of:
‘D’ = uninterruptible sleep
‘R’ = running
‘S’ = sleeping
‘T’ = traced or stopped
‘Z’ = zombieTasks shown as running should be more properly thought of as ‘ready to run’ — their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top’s delay interval and nice value.
x: Command — Command line or Program name
Display the command line used to start a task or the name of the associated program. You toggle between command line and name with ‘c’, which is both a command-line option and an interactive command.When you’ve chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in parentheses, as in this example:( mdrecoveryd )

Either form of display is subject to potential truncation if it’s too long to fit in this field’s current width. That width depends upon other fields selected, their order and the current screen width.

Note: The ‘Command’ field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines.

y: WCHAN — Sleeping in Function
Depending on the availability of the kernel link map (‘System.map’), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash (‘-‘) in this column.Note: By displaying this field, top’s own working set will be
increased by over 700Kb. Your only means of reducing that overhead
will be to stop and restart top.
z: Flags — Task Flags
This column represents the task’s current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in . Less formal documentation can also be found on the ‘Fields select’ and ‘Order fields’ screens.

.

Interactive commands

While top is running you may issue some options that will interact immediately with top these options are:

h
Help, displays a summary of command that will modify the behavior of top
k
Kills a process, you will be able to kill only your own processes, unless you are running top as root
n
Once this command is entered top will ask you how many lines you want on your screen, if you enter 0 top will display as much as it can
q
Exits top
r
Change the priority of a process, as well as with k you will only be able to act on your own processes unless you are root
W
Writes the current configuration to your personal configuration file, which is $HOME/.toprc

1) ps = report process status

ps : typing ps alone would list the current running processes

ps -u username : to search processes run by a certain user

ps ag : to get information about all running process

ps aux : to display the owner of the processes along with the processes

ps ax | grep  processname : to see if a particular process is running or not

.

2) ptree : to display a tree of processeses

pstree -p | less : also display the pid of the process

.

3) pgrep : look up or signal processes based on name and other attributes

pgrep sshd : to list the processes called sshd

pgrep -u root sshd : will only list the processes called sshd AND owned by root

pgrep -u root,daemon : will list the processes owned by root OR daemon

.

4) pidof — find the process ID of a running program

pidof emacs – list the process id for emacs

pgrep and pidof is much the same except that grep is more powerful it has more options (check man pages for both)

.

5) pkill = kill all processes matching the search text

pkill sshd : kill all sshd processes

pkill -9 –u userlogin : kill a process owned by a particular user

.

6) kill = Send a signal to terminate one or more process IDs

kill 2345 : terminate process 2345 (to list process id use ps)

kill -9 2345 : if kill 2345 doesnt work, use kill -9 2345 to force it

.

7) killall = kill all processes by name

killall nautilus

Unlike the kill command, it is not necessary to first try to find the PID(s) for nautilus. And if there are multiple instances of nautilus running, all will be terminated immediately.

killall is similar to pkill


1) useradd = create a new user or updates default new user information

Usage:

useradd login options

Examples:

# useradd usr1 — Add new user usr1 with default settings

# useradd usr1 -d /home/usr1 — Create the new user’s home dir in /home

# useradd usr1 -e 2009-04-30 — From 30/4/2009 the user acc will be disabled.

# useradd usr1 -f 6 — After passwd expires, system will allow the user to login for 6 days with a warning to change his passwd.

# useradd usr1 -g staff — Set user1 group as staff

# useradd usr1 -p $1$d8 — Create the usr1 with the given encrypted password. For No passwd, acc disabled.

# useradd usr1 -s /bin/csh — Set C Shell as the default login shell for the usr1

.

2) userdel = delete a user account and user’s related files 

userdel loginname – delete the user account

userdel -r loginname – delete the user account together with user’s home directory and all files inside it

userdel -f loginname – for the deletion even the user is still log in, it will force to delete the user’s home directory and files as well, this option is dangerous use with caution

.

3) usermod = to modify a users account

Examples:

# usermod -d /home2/usr1 usr1 — Create the new home Dir for usr1 in /home2 & Move old Dir contents to this Dir.

# usermod -e 2005-04-30 usr1 — From 30/4/2005 the usr1 acc will be disabled.

# usermod -f 6 usr1 — After passwd expires, system will allow the user to login for 6 days with a warning to change his passwd.

# usermod -g prof usr1
— Set usr1’s initial group as prof.

# usermod -p $1$d8 usr1 — Set the new passwd for the usr1

# usermod -s /bin/bash usr1 — Set Bash as the default login shell for the usr1.

# usermod -L usr1 — Lock a user’s password.

# usermod -U usr1 — Unlock a user’s password.

.

4) groupadd = create a new group

# groupadd sales

.

5) last = show listing of last logged in users 

Examples:

$ last — List all entries.

$ last tty6 — List, who are all logged thru tty6.

$ last bharathi — List all entries of bharathi (user).

$ last -6 — List only last 6 entries.

$ last -R
— Don’t show the Host Name field in output.

$ last -a — Show Host Name field in last column.

$ last -i — Show IP Number for Remote host.

$ last -t 20080818120000 — List all entries upto Aug 18 12:00:00 2008

.

6) lastb = display a list of recent bad login attempts (from the /var/log/btmp file). Accepts the same option flags and arguments as last


1) Tab key = to complete a file name. very useful for long file name

ls <enter>

finance-report-june-2008  sales-report-june-2008  engineering-report-june-2008

if i want to open finance report i can just type

more fi<tab>, it will auto complete the filename become more finance-report-june-2008

.

2) Ctrl+R = to search for a keyword in history

.

3) !string and  !num = to perform previous action in history

Example for !string

!ssh <enter>

it will perform previous command in history ssh 122.456.789.123 -l mylogin

.

Example for !num

type history to see all the previous commands, you can see for each command is assigned an id

!54 <enter> ( ! followed by the id number)

it will perform the command in history with id number 54

.

4) Tilde (~) = shortcut to home directory

cat ~/.bash_profile

to refer to your own directory

cat ~julie/public_html

to refer to another user’s home directory

.

5) Command editing Tricks

There are many but i find these are the most useful

Ctrl + a = moves to beginning of line

Ctrl + e = moves to end of line

Ctrl + w = deletes the word before the cursor

Ctrl + u = deletes to beginning of line

Ctrl + k = deletes to end of line

Ctrl + y = undo a deletion

Alt + b = moves to beginning of line word by word

Alt + f = moves to end of line word by word

1) su = become super user or another user

Examples:

I already login as a normal user. To switch to root I can type

su <enter> : it will ask for root password then will log in to root account but maintaining the user environment

su root <enter> : same as above

su – <enter> : after entering the root password it will log in to root account with root environment (processing all login scripts)

su – david <enter> : login to david’s account with david’s environment

The difference between su and su – is one will maintain the user environment while the other will use the new user environment

.

2) sudo = execute a command as another user, as specified in the sudoers file.

a) by default, sudo requires that users authenticate themselves with a password (not root password)

b) sudo determines who is an authorized user by consulting the file /etc/sudoers. the login access have to be created by root user in this file

c) basically sudo is used to give access to superusers to do administrative job without them login using root account, so monitoring of each task done by many administrators can be recorded properly

Examples:

sudo more /etc/sudoers : in order to view a content where the user has no access, he can use sudo

sudo shutdown -h now : to shutdown a machine

using sudo is by just adding the word sudo in front of any command that requires root/superuser privileges

.

3) wc = wc displays a count of lines, words, and characters in a file

Examples:

wc resignationletter.txt

output is : 10   52   121  resignationletter.txt

10 = lines,  52 = words, 121 = characters

wc -w resignationletter.txt

the command above is to get only the word count

wc -c filename : to get the character count

wc -l filename : to get the number of lines in the document

.

4) cut = takes a vertical slice of a file, printing only the specified columns or fields

Eg 1 : For Findind List of users available on your linux machine
( see the previous post)

cut -d : -f 1 /etc/passwd

/etc/passwd is the file about user information , the general format of this file is

username:password:userid:groupid:userdirectory:usershell
or
antony:x:103:105:/home/antony:/bin/sh

x means password is in /etc/shadow field

now i want ot retrieve the all username and their userid from that file
the command is

cut -d : -f 1 3 /etc/passwd

cut – command name
-d – delimiter (:)
-f – field numbers seperated by space (1 -username , 3 – userid)

Eg 2: the same like we can retrieve the groups details from /etc/groups

cut -d : -f 1 /etc/groups

taken from http://linuxforadmin.blogspot.com/2007/08/cut-command.html

.

5) diff = displays two files and prints the lines that are different

Examples:

diff filenew.txt fileold.txt : use to compare the different between the two files.

more examples at http://lowfatlinux.com/linux-compare-files-diff.html

1) chown :  change file owner and group

To check the ownership of a file or directory use ls -l

Usage: chown [-Rcfv] newowner filenames/directory. Take note only root can change the ownership.

Example:

chown linda file.txt

This will cause file.txt to now be owned by linda.

chown -R abu:sales /home/account/

This is going to make all files inside /home/account/ and its subdirectories to belong to abu and to be associated with the group sales. -R means include all subdirectories

.

2) chgrp : change group ownership

Usage : chgrp [-Rcfv] groupname foo.txt

Example:

chgrp marketing file.txt – to change the group specified to a certain document

chgrp oracle /usr/database – to change the group specified to a certain directory

chgrp -R marketing /sales/2008 – to change the group specified to a certain directory recursively

.

3) chmod : to change the permissions of a file or directory. Use ls -l to see the permission settings.

Below is how the permission is assigned.

rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000

and so on...

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4

For example, if we wanted to set some_file to have read and write permission for the owner, but wanted to keep the file private from others, we would:

chmod 600 some_file

Here is a table of numbers that covers all the common settings. The ones beginning with “7” are used with programs (since they enable execution) and the rest are for other kinds of files.

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666 (rw-rw-rw-) All users may read and write the file.
644 (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600 (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Here are some useful settings for directories:

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.
755 (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.
700 (rwx——) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.

taken from http://www.linuxcommand.org/lts0070.php

chmod Shortcuts

Who

The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.

u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users
a all of the above (an abbreviation for ugo)

.

Permissions

Of course, the permissions are the same letters that you see in the directory listing:

r Permission to read the file.
w Permission to write (or delete) the file.
x Permission to execute the file, or, in the case of a directory, search it.

Let’s say we have these files:

-rwxrwxrwx  joe  acctg  wordmatic
-r--r--r--  joe  acctg  calcmatic

We’d like to remove write permission for the group and others on wordmatic, and add write and execute permission for all users on calcmatic.

Rather than try to figure out what the new permissions are and do these commands:

   chmod go=rx wordmatic
   chmod a=rwx calcmatic

The chmod command literally lets us add and subtract permissions from an existing set by using + or - instead of =.

Thus, we can take away the first file’s write permission for the group and others with this command:

   chmod go-w wordmatic

…and we can add write and execute permission to the second file for all users with:

   chmod a+wx calcmatic

Copying Permissions

As one other shortcut, it’s possible to tell chmod “give users of one class the same permissions that some other class has.”

Let’s say we have these files:

d------rwx  joe  acctg  sales
-rw-r--r--  joe  acctg  info.dat

The other users have full permissions on the sales directory. We’d like to say “ the user and group should be assigned (=) the permissions belonging to others.” That translates to:

   chmod ug=o

Similarly, to make info.dat readable and writable to the group, we can say:

   chmod g=u info.dat

(you can read this as “the group is assigned (=) the permissions currently held by the user.”)

You may also use + and – to add and subtract the permissions that currently belong to a different class of user.

You can’t mix the standard permissions (r, w, and x) with the coyping shortcuts. chmod will protest if you give it something like this:

   chmod g=wu info.dat

Taken from http://catcode.com/teachmod/chmod_cmd.html

.

4) umask = set file creation mask

The ‘UMASK‘ is the default permission setting that is applied to your files and directories when they are created. After files and directories are created, the chmod command can be used to change the permissions to allow or disallow access as before. The UMASK is set when you login to a UNIX machine.

It is, however, possible to change your UMASK and put the UMASK in your login files so that your default permissions are always set for files when you create them.

Just like chmod, a umask works on a number. However, instead of the numbers being ADDED like chmod, with a umask the numbers are SUBTRACTED from 7.

So from chmod –

Read – 4
Write – 2
Execute – 1

If a user wants all directories to be created with rwxr-xr-x, that is

Owner == Read, Write, Execute == 7 – 4 – 2 – 1 == 0
Group == Read, Execute == 7 – 4 – 1 == 2
Others == Read, Execute == 7 – 4 – 1 == 2

Then the umask would be 022

There is one important difference with the UMASK and files and directories – the execute part will be set on directories, but they have to be manually changed on files after the file has been created. The read and write parts remain the same.

You can change your default UMASK using the command ‘umask’. For example, the command:

umask 022

Will change your umask to the permissions stated above.

To make your new umask be the default for your next login, you will have to edit your .login file and place the umask command down the bottom of that file. The next time you login to your UNIX system, your default umask will be set to that which you have specified in your .login file.

For redhat, to change permanently modify .bashrc and include umask nnn in one of the lines.

1) find = finds one or more files assuming that you know their approximate filenames

Examples:

find -name mypage.htm
In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory.

find / -name mypage.htm
In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root.

find -name file*
In the above example the system would search for any file beginning with file in the current directory and any subdirectory.

find -name ‘*’ -size +1000k
In the above example the system would search for any file that is larger then 1000k.

find /usr -name *stat

Find every file under the directory /usr ending in “.stat”.

find / -mtime -2 -print

Search the system for files that were modified within the last two days (good candidates for backing up)

More examples: http://www.oracle.com/technology/pub/articles/calish-find.html

.

2) locate = find files by name

Searches are conducted against a database of system contents that is updated periodically. To update the database, use the updatedb command.

locate "*.png"

to display all files on the system that have the .png filename extension

locate "*.png" -q

to suppress error messages, such as those that might be returned in the event that the user does not have permission to access designated files or directories

locate -n 15 "*.html"

display only 15 results in a search for files that have an .html extension:

locate "*.html" | less

presents only one screenful of output at a time

locate -i "*.HtmL"

The -i option performs a case-insensitive search. That is, it will return any results that match the arguments regardless of whether individual letters are lower case or upper case.

.

3) whereis = the whereis command is used to locate the binary, the source code and the online manual page for any specified program. Take note it is not for searching your files.

Example:

whereis locate

locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz

whereis -b locate (search only binaries)

locate: /usr/bin/locate

.

4) sort =  sort lines of text files

sort can be used in many ways, below are some simple examples

a) example 1

assume i have 1 text file with name fruits containing below

orange
lemon

and another text file veggy with contents below

papaya
cucumber

sort fruits veggy : it will produce output in alphabetical order as below

cucumber
lemon
orange
papaya

sort fruits veggy > fruitveggy : this command will save into a file fruitveggy

b) example 2

i can create a text file that is sorted in real time, for example, by typing

sort > color

it will put me into data entry mode, i can keep entering data for example blue, green, yellow each followed by <enter> command. once im done, pressing Ctrl-D keep me back at command prompt. now if i check the text file color i can see alll my input is there already sort out

c) example 3

i have a data file data.txt as below:

24 John
45 Sharon
98 Robert

i want to sort it on second field (name by alphabetical order), i can use this command

sort -d -k 2 data.txt , the output will be

24 John
98 Robert
45 Sharon

Explanation: The ‘-d’ switch stands for ‘dictionary sort’ and ensures that sorting

takes place alphabetically as a dictionary would do it. The ‘-k’ switch

stands for ‘key’ and with the ‘2’ tells sort to sort on the second

field in the file, that is the names.

.

5) grep = finds text within a file

grep tutorial *.htm = search all .htm files in the current directory for the text “tutorial”

grep -i love history.txt = print all lines containing love (ignoring uppercase and lowercase) in history.txt

grep -ic “love me” history.txt = To print just the number of lines containing the word “love me”

grep -r tutorial * = -r is to search not only in the current directory but recursively in all the sub directories, the symbol * means to search all files

ls | grep readme = this command is to print all files that has the phrase “readme” in the filename. take note it is not the text inside the document but the name of the document

ls -l | grep rwxrwxrwx = to find all filesystem objects in the current directory whose permissions have been set so that any user can read, write and execute them

.

The /bin/ Directory

The /bin is a standard subdirectory of the root directory in  that contains the executable (i.e., ready to run) programs that must be available in order to attain minimal functionality for the purposes of booting (i.e., starting) and repairing a system.

.

The /boot/ Directory

The /boot/ directory contains static files required to boot the system, such as the Linux kernel. These files are essential for the system to boot properly.

.

The /dev/ Directory

The /dev/ directory contains device nodes that either represent devices that are attached to the system or virtual devices that are provided by the kernel. These device nodes are essential for the system to function properly. The udev demon takes care of creating and removing all these device nodes in /dev/.

Examples of common files in the /dev include:

/dev/hda - the master device on primary IDE channel.
/dev/hdb - the slave device on primary IDE channel.
/dev/tty0 - first virtual console.
/dev/tty1 - second virtual console.
/dev/sda - first device on primary SCSI or SATA channel.
/dev/lp0 - first parallel port.

.

The /etc/ Directory

The /etc/ directory is reserved for configuration files that are local to the machine. No binaries are to be placed in /etc/. Any binaries that were once located in /etc/ should be placed into /sbin/ or /bin/.

/etc/opt/ – Configuration files for /opt/.

/etc/X11/ – Configuration files for the X Window System, version 11.

/etc/sgml/ – Configuration files for SGML.

/etc/xml/ – Configuration files for XML.

.

The /lib/ Directory

The /lib/ directory should contain only those libraries needed to execute the binaries in /bin/ and /sbin/. These shared library images are particularly important for booting the system and executing commands within the root file system.

.

The /media/ Directory

The /media/ directory contains subdirectories used as mount points for removeable media such as usb storage media, DVDs, CD-ROMs, and Zip disks.

.

The /mnt/ Directory

The /mnt/ directory is reserved for temporarily mounted file systems, such as NFS file system mounts. For all removeable media, please use the /media/ directory. Automatically detected removeable media will be mounted in the /media directory.

.

The /opt/ Directory

A package placing files in the /opt/ directory creates a directory bearing the same name as the package. This directory, in turn, holds files that otherwise would be scattered throughout the file system, giving the system administrator an easy way to determine the role of each file within a particular package.

For example, if sample is the name of a particular software package located within the /opt/ directory, then all of its files are placed in directories inside the /opt/sample/ directory, such as /opt/sample/bin/ for binaries and /opt/sample/man/ for manual pages.

Packages that encompass many different sub-packages, data files, extra fonts, clipart etc are also located in the /opt/ directory, giving that large package a way to organize itself. In this way, our sample package may have different tools that each go in their own sub-directories, such as /opt/sample/tool1/ and /opt/sample/tool2/, each of which can have their own bin/, man/, and other similar directories.

.

The /proc/ Directory

The /proc/ directory contains special files that either extract information from or send information to the kernel. Examples include system memory, cpu information, hardware configuration etc

.

The /sbin/ Directory

The /sbin/ directory stores executables used by the root user. The executables in /sbin/ are used at boot time, for system administration and to perform system recovery operations.

.

The /srv/ Directory

The /srv/ directory contains site-specific data served by your system running Red Hat Enterprise Linux. This directory gives users the location of data files for a particular service, such as FTP, WWW, or CVS. Data that only pertains to a specific user should go in the /home/ directory.

.

The /sys/ Directory

The /sys/ directory utilizes the new sysfs virtual file system specific to the 2.6 kernel. With the increased support for hot plug hardware devices in the 2.6 kernel, the /sys/ directory contains information similarly held in /proc/, but displays a hierarchical view of specific device information in regards to hot plug devices.

.

The /usr/ Directory

The /usr/ directory is for files that can be shared across multiple machines. The /usr/ directory is often on its own partition and is mounted read-only. At a minimum, the following directories should be subdirectories of /usr/:

/usr
   |- bin/
   |- etc/
   |- games/
   |- include/
   |- kerberos/
   |- lib/
   |- libexec/
   |- local/
   |- sbin/
   |- share/
   |- src/
   |- tmp -> ../var/tmp/

Under the /usr/ directory, the bin/ subdirectory contains executables, etc/ contains system-wide configuration files, games is for games, include/ contains C header files, kerberos/ contains binaries and other Kerberos-related files, and lib/ contains object files and libraries that are not designed to be directly utilized by users or shell scripts. The libexec/ directory contains small helper programs called by other programs, sbin/ is for system administration binaries (those that do not belong in the /sbin/ directory), share/ contains files that are not architecture-specific, src/ is for source code.

The /usr/local Directory

The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable among a group of hosts, but not found in /usr.

The /usr/local/ directory is similar in structure to the /usr/ directory. It has the following subdirectories, which are similar in purpose to those in the /usr/ directory:


/usr/local
        |- bin/
	|- etc/
	|- games/
	|- include/
	|- lib/
	|- libexec/
	|- sbin/
	|- share/
	|- src/

.

The /var/ Directory

Since the FHS requires Linux to mount /usr/ as read-only, any programs that write log files or need spool/ or lock/ directories should write them to the /var/ directory. The FHS states /var/ is for:

…variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.

Each type of filesystem has its own set of rules for controlling the allocation of disk space to files and for associating data about each file (referred to as metadata) with that file, such as its name, the directory in which it is located, its access permissions and its creation date.

.

Minix filesystem

1) The earliest versions of Linux used the Minix filesystem, which was developed by Professor Andrew S. Tanenbaum for use in his MINIX operating system, a small clone of UNIX that was intended only for computer science education purposes.

2) Although mostly free of bugs, it suffered from a small maximum partition size of 64 megabytes and a file name length limit of 14 characters.

.

The extended file system, also called Ext

1) Was released in April 1992 and was included in the Linux kernel (i.e, core of the operating system) version 0.96c.

2) It overcame the main Minix limitations by allowing a huge increase in maximum partition size to two gigabytes and file names of up to 255 characters

3) However, ext still had problems: in particular, it lacked support for separate access for each user and group, and it also lacked timestamps for modifications to inodes and to data. An inode is a data structure on a filesystem on Unix-like operating systems that stores all of a file’s metadata except its name.

4) Another problem was that the linked lists data structure ext used to track free blocks and inodes gradually became unsorted as the filesystem was used, thus causing the filesystem to become fragmented (i.e., parts of files widely dispersed rather than in contiguous blocks).

.

Ext2 filesystems

1) Ext2 was initially designed by Rémy Card, a French software developer, based on ext but incorporating many ideas from the Berkeley Fast File System and with extensibility in mind.

2) Ext2 features (1) improved algorithms that greatly increase its speed, (2) additional timestamps (such as date of last access and date of last inode modification), (3) the ability to track the state of the filesystem and (4) support for a maximum file size of 4TB (one terabyte equals 1024 gigabytes).

3) It maintains a special field in the superblock that indicates the status of the filesystem as either clean or dirty; the latter will trigger a utility to scan the filesystem for errors. As a result of these improvements, ext2 has completely superseded ext.

4) Ext2 is designed so that data is held in blocks of equal size on the HDD or other storage medium, although blocks can be different sizes on different partitions, different HDDs, etc. The size is set when the filesystem is created by the mke2fs program. The disadvantage of this approach is that an average of half of the block size is wasted for each file. For example, with a a block size of 1024 bytes, each 1025 byte file would require two blocks.

.

Ext3 filesystems

1) Ext3 has been integrated into the Linux kernel since version 2.4.16 and has become the default filesystem on Red Hat and some other distributions. It is basically an extension of ext2 to which a journaling capability has been added, and it provides the same high degree of reliability because of the exhaustively field-proven nature of its underlying ext2.

2) Also featured is the ability for ext2 partitions to be converted to ext3 and vice-versa without any need for backing up the data and repartitioning. If necessary, an ext3 partition can even be mounted by an older kernel that has no ext3 support; this is because it would be seen as just another normal ext2 partition and the journal would be ignored.

The ext3 file system adds, over its predecessor:

  • A Journaling file system
  • Online file system growth
  • htree indexing for larger directories (specialized version of a B-tree — not to be confused with H tree)

.

ReiserFS

1) ReiserFS, developed by Hans Reiser and others, was actually the first journaling filesystem added to the Linux kernel. As was the case with ext2, it was designed from the ground up for use in Linux.

2) However, unlike ext3, it was also designed from the ground up as a journaling filesystem rather than as an add-on to an existing filesystem, and thus it is widely considered to be the most advanced of the native Linux journaling filesystems.

3) Features include high speed, excellent stability and the ability to pack small files into less disk space than is possible with many other filesystems.

4) A new version of ReiserFS, designated Reiser4, was scheduled for release in the first half of 2004. It is a complete rewrite from version 3 and is said to result in major improvements in performance, including higher speeds, the ability to accommodate more CPUs, built-in encryption and ease of customization.

.

JFS

1) JFS was originally developed by IBM in the mid-1990s for its AIX Unix operating system, and it was later ported to the company’s OS/2 operating system. IBM subsequently changed the licensing of the OS/2 implementation to open source, which led to its support on Linux.

2) JFS is currently used primarily on IBM enterprise servers, and it is also a good choice for systems that multiboot Linux and OS/2.

3) JFS provides fast file system restart in the event of a system crash. Using database journaling techniques, JFS can restore a file system to a consistent state in a matter of seconds or minutes, versus hours or days with non-journaled file systems.

.

XFS

1) XFS was developed in the mid-1990s by Silicon Graphics (SGI) for its 64 bit IRIX Unix servers. These servers were designed with advanced graphics processing in mind, and they feature the ability to accommodate huge files sizes.

2) The company likewise converted XFS to open source, after which it was also adopted by Linux. Because it is a 64-bit filesystem, XFS features size limitations in the millions of terabytes (in contrast to the still generous 4TB limit of ext2).

The XFS filesystem provides the following major features:

  • Quick Recovery The XFS journaling technology allows it to restart very quickly after an unexpected interruption, regardless of the number of files it is managing. Traditional filesystems must do special filesystem checks after an interruption, which can take many hours to complete. The XFS journaling avoids these lengthy filesystem checks.
  • Fast TransactionsThe XFS filesystem provides the advantages of journaling while minimizing the performance impact of journaling on read and write data transactions. Its journaling structures and algorithms are tuned to log the transactions rapidly.

    XFS uses efficient tree structures for fast searches and rapid space allocation. XFS continues to deliver rapid response times, even for directories with tens of thousands of entries.

  • Massive ScalabilityXFS is a full 64-bit filesystem, and thus is capable of handling filesystems as large as a million terabytes.
  • Efficient AllocationsXFS implements extremely sophisticated space management techniques. Efficiency in space management has been achieved through the use of variable sized extents, rather than the simple single-block-at-a-time mechanism of many other filesystems. XFS was the first filesystem to implement delayed space allocation for buffered writes, supports direct I/O, provides an optional realtime allocator, and is able to align allocations based on the geometry of the underlying storage device. The XFS allocator performs admirably in the presence of multiple parallel writers, and is renowned for its resistance to space fragmentation under such conditions.
  • Excellent BandwidthXFS is capable of delivering very close to the raw I/O performance that the underlying hardware can provide. XFS has proven scalability on SGI Altix systems of multiple gigabytes-per-second on multiple terabyte filesystems.

.

Comparison

Feature ext2 ext3 ReiserFS3.6 (not supported by Oracle)
Maximum partition size 4TB 4TB 16TB
Maximum file size 2GB-2TB 2GB-2TB 8TB
Block size 1KB-4KB 1KB-4KB 4KB only
Journaling capabilities No Yes Yes
Reboot after a crash Slow Fast Very Fast
State of data after crash Good Very Good Fair
ACL support Yes Yes No
Stability Excellent Good Good