Saturday 6 October 2012

linux commands


Unix History   
In the 1960s, Massachusetts Institute of Technology, AT&T Bell Labs, and General Electric developed an experimental operating system called Multics (Multiplexed Information and Computing Service)for the GE-645 mainframe.
Multics was highly innovative, but had many problems.
Bell Labs, frustrated by the size and complexity of Multics but not the aims, slowly pulled out of the project.
Summer 1969 Unix was developed.
 UNIX is much better, but much much expensive. Only for minicomputer for commercial applications
People was looking for a UNIX based system, which is cheaper and can run on PC
Both DOS, MAC and UNIX are proprietary, i.e., the source code of their kernel is protected
No modification is possible without paying high license fees
    

Beginning of Linux
A famous professor Andrew Tanenbaum developed Minix, a simplified version of UNIX that runs on PC
Minix is for class teaching only. No intention for commercial use
In Sept 1991, Linus Torvalds, a second year student of Computer Science at the University of Helsinki, developed the preliminary kernel of Linux, known as Linux version 0.0.1
It was put to the Internet and received enormous response from worldwide software developers
By December came version 0.10. Still Linux was little more than in skeletal form.


Message from Professor Andrew Tanenbaum
" I still maintain the point that designing a monolithic kernel in 1991 is a fundamental error.  Be thankful you are not mystudent.  You would not get a high grade for such a design :-)"(Andrew Tanenbaum to Linus Torvalds)
"Linux is obsolete".
               (Remark made by Andrew Tanenbaum)
But work went on. Soon more than a hundred people joined the Linux camp. Then thousands. Then hundreds of thousands
It was licensed under GNU General Public
 License, thus ensuring that the source codes will be free for all to copy, study and to change
Linux Today
Linux has been used for many computing platforms PC, PDA, Supercomputer,…
Current kernel version 2.6.13
Not only character user interface but graphical user interface.

Advantages over Windows
 It's almost free to relatively inexpensive.
Source code is included.
Bugs are fixed quickly and help is readily available through the vast support in Internet.
Linux is more stable than Windows.
Linux is truly multi-user and multi-tasking.
multiuser: OS that can simultaneously serve a number of users
multitasking: OS that can simultaneously execute a number of programs
Linux is mainly used in commercial applications, server implementation.
More than 75% current network servers are developed based on Linux or Unix systems. Due to the relatively high reliability

                                              Common Distributions
                  

Slackware  RedHat  Caldera Mandrake  Debian Corel SuSe






1   ls - list directory contents

SYNOPSIS

       ls [OPTION]... [FILE]
                 -a, --all
                            do not ignore entries starting with . (display all file including hidden files
                 -d, --directory
                              list directory entries instead of contents
                  -i, --inode
                              print the index number of each file
                    -l       use a long listing format

                     -r, --reverse
                             reverse order while sorting
                    -R, --recursive
                           list subdirectories recursively
                     -S     sort by file size
                      Z, --context
                                  Display  security context so it fits on most displays.  Displays only mode, user, group,                              security context and file name.
                            ls  -a [a-d]     all files  between a to d
                            ls  -a[!a-d]  not list files  between a to d

 2  cat - concatenate files and print on the standard output

      cat [OPTION]... [FILE]...
                                -A, --show-all
                                -n, --number       number all output lines
                                 -T, --show-tabs  display TAB characters as ^I

                                  -E, --show-ends    display $ at end of each line display
                                cat     file name   display content of file
                                cat >  file name  create new file
                                cat >> file name   append the content of file  

 3  # pwd

Present working directory

Displays the location where the user is currently working


                                   pwd [OPTION]...

4  # mkdir

to create a directory

syn: # mkdir <dir_name>

eg: # mkdir jai

syn: # mkdir -p <path_of_the_dir>



eg: # mkdir -p /ims/solaris/delhi

It creates the parent directory /ims/solaris along with the directory delhi.



                             
 5 man - format and display the on-line manual pages
                            man   command
                          # man date
6  cd  change directories
                  cd    directories name
                   cd ..  change to parent directory
                   cd  ~  change to user home directory
                   cd   change to user home directory
7  who - show who is logged on
                    -a, --all
                     same as -b -d --login -p -r -t -T -u
                     -b, --boot                  time of last system boot
\
                   -l, --login                print system login processes

8  whoami - print effective userid

9  w - Show who is logged on and what they are doing.
                    /var/run/utmp
                    information about who is currently logged on

 10  rm - to remove the file

# rm <file-name>

# rm rose/Documents

to remove or to delete the file named rose

# rmdir - to remove or delete the directory

# rmdir <dir-nam/Documentse>

# rmdir delhi

will remove the directory name delhi only if it is empty

# rm -rf <dir-name>

# rm -rf delhi

will remove the contents of the directory named delhi and delete the directory delhi.

where

-r = recurrsive

-f = forcefully

-i = interactive

 11  type    find the location of command
                          type   command

 12  file - determine file type
                            file   file name

13 wc - print newline, word, and byte counts for each file

                               wc [OPTION]... [FILE]...
                               -c, --bytes                   print the byte counts
                               -l, --lines                    print the newline counts
                               -w, --words                print the word counts

14 # cp - to copy a file or a directory

syn:  # cp <source_file> <destination_file>

eg:  # cp rose jack

here the contents of the file named rose is copied to new file named jack in the same location

# cp rose /Desktop/jack

will copy the contents of the file named rose to the location /Desktop with the file name as jack

# cp rose /Desktop/

will copy the contents of the file named rose to the location /Desktop with the same file name.

# cp -r <source_dir> <destination>

where

-r = recurrsive

To copy all the files and sub-directories inside a directory

15 diff [OPTION]... FILES

16 touch - change file timestamps
                         touch [OPTION]... FILE...
                      -a     change only the access time
                       -m     change only the modification time
                      -t STAMP                 use YYMMDDhhmm instead of current time
                        touch -t  3312131212 restoresymtable
 17  more         More is a filter for paging through text one screenful at a time
 # more <file_name>

# more /etc/passwd

to view the contents of the file in pagewise

18    less    Less is a program similar to more (1), but which allows backward  movement in the file as well as forward movement
# less <file-name>

# less /etc/passwd

to view the contents of the file in pagewise


19  head        Print  the  first  10 lines of each FILE to standard output
# head -n <file-name>

# head -4 /etc/passwd

to view the first 4 lines of the specified file
20  tail     Print  the  last  10  lines of each FILE to standard output
# tail -n <file-name>

# tail -5 /etc/passwd

to view the last 5 lines of the specified file

21  # mv - to rename or move or to cut and paste the file or directory

# mv jack rock

will rename the file jack as rock in the current location

# mv jack /Desktop/rock

will move the file jack to the location /Desktop with the file name as rock.

NOTE: Source file "jack" will not be present after moving


22 cut - remove sections from each line of files
                           cut OPTION... [FILE]..

23 tty - print the file name of the terminal connected to standard input

24  init - Upstart process management daemon
                     init  0   halt
                      init 6  reboot

25  sort - sort lines of text files
                       sort [OPTION]... [FILE]
                        -r, --reverse  reverse the result of comparisons
                          -n, --numeric-sort  compare according to string numerical value

26 grep - print lines matching a pattern

 grep - to search a key word

# ls | grep rose

this command will look for the dir or file named rose under the current location and display the

same if it is present in the present working directory

# grep <keyword> <file-name>

# grep one rose

will search for the keyword 'one' in the file named rose

and will display the same

# grep -i one rose

will search for the keyword 'one' by ignoring the case and will display the same



# grep -v one rose

will dispaly all the lines and words expect 'one' from the file rose.

# grep -h good rose jai

will look for the word 'good' in miltiple files named rose and jai respectively.

To search a particular word from the file and to display the name of the file having the search

keyword

                 -n, --line-number   Prefix each line of output with the 1-based line  number  within     its input file.
                 grep   test$  file name   display all line  start with test
                 grep   ^test file name   display all line end with test

 27   bc - An arbitrary precision calculator language

 28  date - print or set the system date and time
                          date [OPTION]... [+FORMAT]
                          date  121212302010         [mmddhhmmyyyy]

29 env - run a program in a modified environment

30 arch - print machine hardware name (same as uname -m)
                arch [OPTION].
31  find - search for files in a directory hierarchy
                         find / -name  passwd
                          find / -inum  1471670

32  locate - find files by name
                     locate [OPTION]... PATTERN...

33 wall -- send a message to everybody’s terminal.
                   wall [-n] [ message ]
                    -n     Suppresses  the  normal  banner  printed by wall

34 write - send a message to another user
           write user [ttyname]

 35  ps - report a snapshot of the current processes.
                              ps [options]
                              ps ax
                              ps axu

36  kill - terminate a process
                   kill [-s signal|-p] [--] pid.

 37  pgrep  -  look  up  or signal processes based on name and other    attributes

38  pkill  terminate process by name
                           pkill [-s signal|-p] [--] process name
                           pkill  -9  bash

39 cmp - compare two files byte by byte
                    cmp [OPTION]... FILE1 [FILE2
40 diff - compare files line by line
                      diff [OPTION]... FILES
 41 uniq - report or omit repeated lines
           SYNOPSIS
            uniq [OPTION]  filename
              d, --repeated                only print duplicate lines
              -u, --unique                  only print unique lines
                -i, --ignore-case       ignore differences in case when comparing
42 echo - display a line of text
        echo   $PATH
        echo  $?   0 no error  1 error
43  export  PATH=$PATH:/rr    add last of path
     export  PATH=/yy:$PATH   add start of path

44    gzip    Gzip  reduces  the  size  of  the  named  files using Lempel-Ziv coding

       (LZ77).  Whenever possible, each file  is  replaced  by  one  with  the

       extension .gz, while keeping the same ownership modes, access and modi-

       fication times.
# gzip <file-name>

# gzip passwd2

to zip the file  the file extension is .gz

 45          gunzip can currently decompress files created by gzip

# gunzip <file-name>.gz

# gunzip passwd2.gz 
to unzip the file 
                                                                                                                                      
46   bzip2 expects a list of file names to accompany the command-line flags.

       Each  file is replaced by a compressed version of itself, with the name

       "original_name.bz2"

# bzip2 <file-name>

# bzip2 passwd3

to zip the file

file extension is .bz2

# bunzip2 <file-name>.bz2

to unzip the file

# tar - Tape ARchieve

# tar -cvf <file-name>.tar <source-file>

# tar -cvf one.tar passwd6

here

-c = to create the archieve

-v = verbose (detail) mode

-f = forcefully

here a tar file named one.tar is created from the source file

passwd6

# tar xvf <file-name>.tar

# tar xvf one.tar

will extract the file to the current location

here

-x = to extract
 zip - package and compress (archive) files
  

    The zip program puts one or more compressed files  into  a  single  zip

       archive, along with information about the files

 SYNOPSIS    zip options archive inpath inpath
        zip  accel anaconda-ks.cfg  install.log
here a  zip  file named accel.zip  is created from the source file

                reboot          reboot   the system

                halt              stop the system

                poweroff     stop the system


shutdown - bring the system down

SYNOPSIS

       shutdown [OPTION]...  TIME [MESSAGE]

       -r     Requests that the system be rebooted after it has  been  brought

              down.

 -c     Cancels  a  running  shutdown.
-k     Only send out the warning messages and disable  logins,  do  not

              actually bring the system down.

lsmod - program to show the status of modules in the Linux Kernel

 
uptime - Tell how long the system has been running.
 free - Display amount of free and used memory in the system

  du - estimate file space usage

 du [OPTION]... [FILE]...
 -h, --human-readable

              print sizes in human readable format (e.g., 1K 234M 2G)

       df - report file system disk space usage



SYNOPSIS

       df [OPTION]... [FILE]...


-h, --human-readable

              print sizes in human readable format (e.g., 1K 234M 2G)

  uname - print system information

SYNOPSIS

       uname [OPTION]..
-a, --all

              print  all  information,  in the following order, except omit -p

              and -i if unknown:



       -s, --kernel-name

              print the kernel name



       -n, --nodename

              print the network node hostname



       -r, --kernel-release

              print the kernel release

# cal

will display the current month of the current year

# cal 2009

will display the cal of 2009

# cal 10 1987

will display the 10th month of 1987


 #history

will display the commands executed in the particular shell

# history -c

to clear the history

# alias - to assign the shortname to a command

# alias c=clear

this is only temp

c will perform the function of clear command


# bc = binary calculator

# bg = to view the process running at the back ground

# fg n

to bring the process to the fore ground

where n is the number of the process that is dispalyed whist executing the command bg.

Links:

1. Links are of two types.

2. a. Hard link

b. Soft link or symbolic link

Hard link:

1. Both the source file and the destination file will have the same contents.

2. Any number of links can be created

3. Both the source file and the destination linked file will have the same inode numbers.

4. If the source file is removed or deleted unfortunately still the datas can be assessed from the

destination.

5. When hard links are created, link counts will be increased. And if the hard links are removed

or deleted, link count decreases automatically.

6. Permissionship on the source file will have the impact on the destination file permissionship.

7. # ln <source_file> <destination_file.

Eg: # ln /4students/jai /new

8.    The size of the files (both source and destination) remains same.



Soft or Symbolic link:

1. Both the source file and the destination file will have the same contents.

2. But the inode number of the source file and destination file will be different.

3. The permissionship of the soft link destination will be differ from the source file.

4. Link count will not be increased nor decreased.

5. If the source file is deleted, contents cannot be seen from the destination file.

6. Size of the file will be equal to the number of the characters of the file name

7. # ln -s <source_file> <destination_file>

Eg: # ln -s /4students/jai /soft


Editors

vi

vim - vi improved

emac

pico

gedit - graphical editor - works only with graphics

VI - Editor

# vi - is one of the powerful editor

used to create a file, edit a file, view the contents of the file

esc+i - to insert the characters to the file

esc+A - to bring the cursor to the end of the line and to add the contents to the line

esc+$ - to bring the cursor to the end of the line

esc+G - to bring the cursor to the end of the file

esc+x - to delete a single character

esc+dw - to delete a single word

esc+dd - to delete a line

esc:n - to move the cursor to the nth line

esc:10 - to move the cursor to the 10th line

esc+O - to create a empty line above the cursor

esc+o - to create a empty line below the cursor

esc/<keyword> - to search the keyword

esc:set nu - to set the line number

esc:set nonu - to remove the line number

esc+R - to replace the number of characters

esc+r - to replace a single character

esc:n,md - to delete number of lines

where

n = starting line to be deleted

m = end line to be deleted

d = delete the lines

esc:w - to save/write and go back to the location

esc:q - to quit without saving the contents to the file

esc:wq - to save and quit from the file

esc:wq! - to save and quit from the file forcefully

esc+h - to move the cursor to the left side

esc+l - to move the cursor to the right side

esc+k - to move the cursor upward

esc+j - to move the cursor downward

esc+J - to joinin the line

esc+yy - to copy the line

esc+p - to paste the line

esc+nyy - to copy n number of lines

esc+5yy - to copy 5 number of lines from the cursor

esc:nd - to delete the nth line

esc:3d - to delete the 3rd line

esc+I - to bring the cursor to the beginning of the line

esc+u - undo operation

esc:wq <file-name> - to save the contents to another file


# vi -R <file-name>

# vi -R new

to open the file as Read Only

# vi -x <file-name>

# vi -x rose

will prompt for the key/password.

the contents of the file will be encrypted

the contents cannot be seen by cat or vi editor.

the contents can be seen only by inserting the option -x with vi editor and by providing the

password.

File Systems

File system refers to the files and directories stored on a computer. A file system can have different formats called file system types. These formats determine how the information is stored as files and directories. Some file system types store redundant copies of the data, while some file system types make hard drive access faster

Why Share a Common Structure?

The file system structure is the most basic level of organization in an operating system. Almost all of the ways an operating system interacts with its users, applications, and security model are dependent upon the way it organizes files on storage devices. Providing a common file system structure ensures users and programs are able to access and write files.

File systems break files down into two logical categories:

    *

      Shareable vs. unsharable files
    *

      Variable vs. static files


Overview of File System Hierarchy Standard (FHS)

Red Hat Enterprise Linux uses the Filesystem Hierarchy Standard (FHS) file system structure, which defines the names, locations, and permissions for many file types and directories.

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.
/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/.
/etc/ Directory

The /etc/ directory is reserved for configuration files that are local to the machine. No binaries are to be placed in /etc/
/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.
 /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.
 /mnt/ Directory

The /mnt/ directory is reserved for temporarily mounted file systems, such as NFS file system mounts. For all removeable media,
opt/ Directory

The /opt/ directory provides storage for most application software packages
/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.
/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. Of this directory

/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,

/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.

 /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

/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

/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.



mount - mount a filesystem


All files accessible in a Unix system are arranged in one big tree, the

       file hierarchy, rooted at /.  These files can be spread out  over  sev-

       eral  devices.  The mount command serves to attach the filesystem found

       on some device to the big file tree
SYNOPSIS

 mount     [-t vfstype] [-o options] device dir



 The argument following the -t is used to indicate the filesystem

              type.   The  filesystem  types  which  are  currently  supported

              include: adfs,  affs,  autofs,  cifs,  coda,  coherent,  cramfs,

              debugfs, devpts, efs, ext, ext2, ext3, ext4, hfs, hfsplus, hpfs,

              iso9660, jfs, minix, msdos, ncpfs, nfs, nfs4, ntfs, proc,  qnx4,

              ramfs,  reiserfs,  romfs,  squashfs,  smbfs, sysv, tmpfs, ubifs,

              udf, ufs, umsdos, usbfs, vfat, xenix,  xfs,  xiafs


 The argument following the -o
                    ro               read only
                     rw              read and write
                    remount     to remount the already mounted file system
                    exec           execute permission
                     noexec       not allowed execution of commands in the mount file system permission
                    loop     used to mount iso image


 mount point  it is a directory name that should be created before mounting of a system
 multiple  option separate by comma

mount flash drive to /media/flash at read &write


mount -t vfat   -o rw /dev/sdb1   /media/flash

 remount flash drive to /media/flash   at read only           
 mount     -t vfat    -o ro,remount  /dev/sdb1   /media/flash
mount  iso image    using loop command
 mount  -o loop /cd1.iso     /media
 Permanent mounting
     
      To mount a partition permanently it should be specified in the /etc/fstab file the contents of the file are in following format
 Device file      mounting point      type (file system) option   dump option     fsck ption      
         
The first field, (fs_spec),  describes  the  block  special  device  or
       remote filesystem to be mounted.The  device  to  be  mounted,  like
       ‘/dev/cdrom’   or   ‘/dev/sdb7’.    For   NFS   mounts  one  will  have
       <host>:<dir>,
 Instead of giving the device explicitly, one may indicate the (ext2  or
       xfs)  filesystem that is to be mounted by its UUID or volume label  writing  LABEL=<label>  or  UUID=<uuid>,
       e.g.,   ‘LABEL=Boot’   or  ‘UUID=3e6be9de-8139-11d1-9106-a43f08d823a6’.
       This will make the system more robust: adding or removing a  SCSI  disk
       changes the disk device name but not the filesystem volume label.


 The second field, (fs_file), describes the mount point for the filesys-
       tem.  For swap partitions, this field should be specified as ‘none’.

 The third field, (fs_vfstype), describes the type  of  the  filesystem.
       Linux  supports  lots  of filesystem types, such as adfs, affs, autofs,
       coda, coherent, cramfs, devpts, efs, ext2, ext3,  hfs,  hpfs,  iso9660,
       jfs,  minix,  msdos,  ncpfs,  nfs,  ntfs,  proc, qnx4, reiserfs, romfs,
       smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix,  xfs,


The  fourth  field, (fs_mntops), describes the mount options associated
       with the filesystem.


     noauto     prevents the indicated file system from being mounted at a boot time     
     ro        mount the file system read-only ( Commas must separate options)
     rw    mount the file system read and write
    auto      the indicated file system from being mounted at a boot time     
    defaults  (auto,rw)

The  fifth  field,  (fs_freq),  is  used  for  these filesystems by the
       dump(8) command to determine which filesystems need to be  dumped.   If
       the  fifth  field  is not present, a value of zero is returned and dump
       will assume that the filesystem does not need to be dumped.

The sixth field, (fs_passno), is used by the fsckprogram to  deter-
       mine the order in which filesystem checks are done at reboot time.  The
       root filesystem should be specified with a fs_passno of  1,  and  other
       filesystems  should  have a fs_passno of 2. 
        If the sixth field is not present or zero, a value  of  zero
       is  returned  and fsck will assume that the filesystem does not need to
       be checked.


mount      -a, --all
              Mount all filesystems (of the given types) mentioned in fstab.


0 comments:

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes