Basics of Unix

Unix PROGRAMMING

Introduction to Unix:
Unix  is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson,  Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna. The Unix operating system was first developed in assembly language, but by 1973 had been almost entirely recoded in C, greatly facilitating its further development and porting to other hardware. Today’s Unix systems are split into various branches, developed over time by AT&T as well as various commercial vendors and non-profit organizations. The second edition of Unix was released on December 6th, 1972.
During the late 1970s and early 1980s, the influence of Unix in academic circles led to large-scale adoption of Unix (particularly of the BSD variant, originating from the University of California, Berkeley) by commercial startups, the most notable of which are Solaris, HP-UX and AIX. Among all versions of Unix, OS X currently has the biggest use on personal computers with more than fifty five million systems installed.
Kernel:
The kernel of Unix is the hub of the operating system, it allocates time and memory to programs and handles the filestore and communications in response to system calls.
Shell:
The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter(CLI).
 
                                  
Features of Unix:
The Unix Operating System is available on machines with a wide range of computing power, from microcomputers to mainframes, and on different manufacture’s machines. No other operating system can make this claim. We see the reasons of popularity and success of Unix.

The reasons are
 :

Multi User:
            Unix is a multi user system designed to support a group of users simultaneously. The system allows for the sharing of processing power and peripheral resources, while at the same time providing excellent security features.
Multitasking:
            A single user can also run a multiple tasks concurrently: Unix is a multi tasking system. It is usual for a user to edit a file, print another one on the printer etc., – all without leaving any of the applications. In a multitasking environment, a user sees one job running in the foreground: the rest run in the background. You can switch between background and foreground, suspend or even terminate them.
Building-Block Approach:
            By interconnecting a number of tools, you can have an large number of combinations of their usage. That’s why it’s better for a command to handle a specialized function rather than solve multiple probelms. Though Unix started with this concept, it was somewhat forgotten when tools were added to the system later.
Unix ToolKit:
            To properly exploit the power of Unix, we need to use the host of applications that are shipped with every Unix system. These applications are quite drivers in scope. There are general purpose tools, text manipulation utilities (called filters), compilers and interpreters, networked applications and system administration tools. We’ll have a choice of shells.
Pattern Matching:
            Unix provides very sophisticated pattern matching features. For example, we can use ls command with * instead of explicitly specifying filename. The * is a special character used by the system to indicate that it can match any number of filenames. If you choose your filenames carefully, you can use a simple expression to access a whole lot of them. The * (known as Meta character) is not the only special character used by the Unix. Like * there are many several special characters.
Programming Facility:
            Unix shell is also a programming language, it was designed for a programmer, not a casual end user. Unix has several ingredients like control structures, loops and variables, to establish it as a powerful programming language in its own. These features are used to design shell scripts-programs that can also invoke the Unix commands.
Documentation:
            The principle online help facility available is the man command, which remains the most important reference for commands and their configuration files. Apart from the online documentation, there’s a vast ocean of Unix resources available on the internet.
Vi  Editor:
The VI(Virtual) editor is a popular full-screen editor available with all Unix systems since 1970’s. It was created by BILL JOY for BSD (Berkely Software Distribution) Unix but it is now standard on all Unix systems.
The VI editor in LINUX system is called as VIM(vi improved), the VIM editor is the enhanced version of VI. VIM editor was developed by BRAM MOOLENAAR.
The VI editor has three modes :
                                               
1) Command Mode – Where keys are used as commands to act on text.
2) Input Mode – Where any key pressed is entered as text.
3) Last Line Mode or ex Mode – Where commands can be entered in the last line of the screen to act on text.
The relationship between these three modes and shell is shown in the below figure:
           
                     

Command Mode:
In this mode you can enter different command to enter into any mode. This mode is meant for performing navigation and cut-and-paste operation. Keys here are used both singly and in combination. By pressing Esc key one can go to Command Mode from other modes. By pressing : one can go to ex Mode.
The following are the list of different commands used in Command Mode to enter into the Input Mode.
Command
Description
i
To insert text before the current cursor position.
I
To insert text at the beginning of the line.
a
To insert text after the cursor position.
A
To insert text at the end of the current line.
o
Open a new line below the current line.
O
Open a new line above the current line.
r(ch)
Replaces single character at cursor with ch character.
R
Replaces text to the left of the cursor.
s
Replaces single character at cursor with more characters.
S
Replaces entire line.
x or X
To delete a single character at cursor.
nx
To delete n characters from cursor position.
J
To join the next line to the end of the current line.
dd
To delete the current line.
ndd
To delete n lines from the current line.
dw
To delete the current word.
ndw
To delete n words from the current word.
d$
To delete all characters from the position of the cursor.
u
To undo the effect of the previous command.
.
To repeat the previous command.
yy
To copy the entire line.
yw
To copy the word at the cursor.
p
To place the copied or deleted information below the cursor.
P
To place the copied or deleted information above the cursor.
Input Mode:
In this mode you can enter any data into the document or file by using keyboard. By pressing Esc one can goto the Command Mode.
Last Line Mode or ex Mode:
When you edit a file using VI editor, the original file doesn’t disturb. The editor works with the copy of file which places in the buffer. This is a temporary storage area that is associated with the file on disk. From time to time you should save your work by writing the buffer contents to the disk, it can be done by using different ex Modecommands. Every command in this mode is preceeded by
: (colon) and followed by [Enter] key.
The following are the different ex Mode commands:
Commands
Description
:w
Saves file and remains in editing mode.
😑
Saves files and quits editing mode.
:wq
As above
:q
Quits editing mode when no changes are made to file.
:q!
Ignore changes & quit.
File handling utilities:
cp Command:
The cp command copies a file or a group of files. It creates an exact image of the file on the disk with a different name. The syntax requires at least two file names to be specified in the command line. When both are ordinary files, the first is copied to the second
Syntax:$cp [option] <source file> <Destination file>
1. File to a File
2. File to a Dictionary
3. Directory to Directory
File to File:
Syntax  :  $cp <source file> <Destination file>
Ex : $cp sekhar raj

Ex ; $cp -f sekhar kumar

Note : It is copy the file forcibly sekhar to kumar without any permission.
File to Directory:

Syntax ; $ cp <source file> <Destination Directory>

Ex ; $ cp venkat raj
…. raj is Directory

Ex : $ cp -b venkat nani

Note : It copys the venkat file to nani Directory with backup.
Directory to Directory:
Syntax : $ cp <Source Directory> <Destination Directory>

Ex : $ cp Dravid Ganguly

Ex : $ cp -r Mody Venkat

Note : It copies the Directory to Directory (including all files and Directories).
cp options:
-i  –  Interactive copying.
-r  – Copying directory structures completely(all files and sub folders).
-f  – Forcibly copy file or directory with out any permissions.
-b  – Copy files or directories with backup.
rm Command:
The rm command delete files or directories,  and make space available on disk. It can delete more than one file or directory with a single instruction.
To Remove a file
Syntax; $ rm [option] <filename>

Ex: $ rm kiran
Ex: $ rm f1 f2 f3 f4
Ex: $ rm -f kiran

To Remove Directory
Syntax: $ rm [option] <Directory Name>

Ex: $ rm sagar

Ex: $ rm -rf sagar

Ex: $ rm -r sagar

rm options:

-i – Interactive deletion.
-r – Recursive deletion (deletes all directories and sub directories)
-f – Forcible deletion.

mv Command:

mv renames (moves) files and directories. It doesn’t create a copy of the file but merely renames it. It has two functions

Β§  Rename a file.
Β§  Moves a group of files to different directory.

Syntax: $ mv [option] <Source file/Directory> <Target file/Directory>
These are basically 3 types
1. File to File
2. File to Directory
3. Directory to Directory
1. File to File:
Syntax: $ mv [option] <Source file> <Target file>

Ex: $ mv file1 file2

2. File to Directory:
Syntax: $ mv [option] <Source file> <Target Directory>

Ex: $ mv file1 Dir1

Note: The file1 moves to Directory (Dir1)
3. Directory to Directory:
Syntax: $ mv [option] <Source Directory> <Target Directory>

Ex: $ mv Dir1 Dir2

Note: The content of Dir1 moves to Dir2
mv options:
-i  –  Interactive mode.
-f  – Forcibly mode
-b  – backup mode.
mkdir  Command:
mkdir command is used to create directories. The command is followed by the names of the  directories to be created.

Syntax: $ mkdir [option] <Directory name>
Ex: $mkdir raja
Ex: $ mkdir d1 d2 d3 d4 d5 (multiple directories)
Ex: $ mkdir –p /d5/d51/d52/d53 (multi-level directories)
Ex: $ mkdir –p d3/d31 d4/d41 (multiple sub directories)

mkdir options:

-m – sets the access mode for the new directory.
-p – if the parent directories doesn’t exit,this command creates them.

rmdir  Command:

rmdir (remove directory) command is used to remove directories. Like mkdir , rmdir can also delete more than one directory in one shot.

Syntax: $rmdir[option]<Directory name>
Ex: $rmdir d1
Ex: $ rmdir -p a/b/c (deletes directories and the ancestors)

rmdir options:

-p – deletes directories and the ancestors.
-v – output a diagnostic for every directory processed.

ls Command:

ls command is used to display files and directories of current directory.

$ ls : It is a command to list the files and directories in
       the present working Directory
$ ls – a : It is a command to display all files and
           Directories including hidden files and Directories
$ls * : List information about the Files (the current
        directory by default). Sort entries alphabetically

$ls ~: It list the all Backup files
$ls @ : It list the all linked files and Directories
$ls -d : It Displays the present working Directory.
$ls -i : It Displays the inode numbers of files and
           Directories
$ls -s : It Displays the sizes in blocks (Files &
           Directories)
$ls -l : It Displays the long listing files and
          directories in present working directory
$ls -ld *     List all the file and directory names in the current directory using long format.      Without the “d” option, ls would list the contents of any sub-directory of the current. With the “d” option, ls just lists them like regular files.
$ls -al: It Displays including hidden and log
              listing files and Directories
$ls -m: It Displays all files and Directories with
             separated by comma (,)
$ls -ls: It Displays all long listing Directories
$ls –full-time: It Displays files and Directories
                         with total information date and time
$ls -nl: It Displays the long listing files and
             Directories according to modification Time
$ls -rtl: It Displays the file and Directories
              with reverse order
$ls -R: It Displays the all files and Directories
             Regressively (order by order)
$ls -l: It Displays the files and Directories in a
           single column (vertical)
$ls -x: It Displays the files and Directories with
            multiple columns
Links:
Unix allows a file to have more than one name and yet maintain a single copy in the disk. The file is then said to have more than one link. A file can have as many names as you want to give it, but the only thing common to all of them is that they all have the same inode number.
Links are divided in to two types:
1.  Hard links
2.  Symbolic links
Hard Links:
The link count is displayed in the second column of the listing. This count is normally 1, but the following files have two links,
-rwxr-xr–  2  kumar   metal   163   Jull   13 21:36   backup.sh
-rwxr-xr–  2  kumar   metal   163   Jul   13 21:36   restore.sh
All attributes seem to be identical, but the files could still be copies. It’s the link count that seems to suggest that the files are linked to each other. But this can only be confirmed by using the –i option to ls.
ls -li backup.sh restore.sh
478274 -rwxr-xr– 2 kumar metal163 jul 13 21:36 backup.sh
478274 -rwxr-xr– 2 kumar metal163 jul 13 21:36 restore.sh
ln: Creating Hard Links
A file is linked with the ln command which takes two filenames as arguments (cp command). The command can create both a hard link and a soft link and has syntax similar to the one used by cp. The following command links emp.lst with employee:
ln emp.lst employee
The –i option to ls shows that they have the same inode number, meaning that they are actually one end the same file:
ls -li emp.lst employee
29518 -rwxr-xr-x 2 kumar metal 915 may 4 09:58 emp.lst
29518 -rwxr-xr-x 2 kumar metal 915 may 4 09:58 employee
The link count, which is normally one for unlinked files, is shown to be two. You can increase the number of links by adding the third file name emp.dat as:
ln employee emp.dat ; ls -l emp*
29518  -rwxr-xr-x  3  kumar  metal  915 may 4 09:58 emp.dat
29518  -rwxr-xr-x  3  kumar  metal  915 may 4 09:58 emp.lst
29518  -rwxr-xr-x  3  kumar  metal  915 may 4 09:58 employee
You can link multiple files, but then the destination filename must be a directory. A file is considered to be completely removed from the file system when its link count drops to zero. ln returns an error when the destination file exists. Use the –f option to force the removal of the existing link before creation of the new one
Where to use Hard Links:
ln data/ foo.txt input_files
It creates link in directory input_files. With this link available, your existing programs will continue to find foo.txt in the input_files directory. It is more convenient to do this that modifies all programs to point to the new path. Links provide some protection against accidental deletion, especially when they exist in different directories. Because of links, we don’t need to maintain two programs as two separate disk files if there is very little difference between them. A file’s name is available to a C program and to a shell script. A single file with two links can have its program logic make it behave in two different ways depending on the name by which it is called.
We can’t have two linked filenames in two file systems and we can’t link a directory even within the same file system. This can be solved by using symbolic links (soft links).
Symbolic Links:
            Unlike the hard linke, a symbolic link doesn’t have the file’s contents, but simply provides the pathname of the file that actually has the contents.
ln -s note note.sym
ls -li note note.sym
9948 -rw-r–r–  1  kumar  group  80  feb  16  14:52  note
9952 lrwxrwxrwx 1 kumar group 4 feb16 15:07note.sym ->note
Where, l indicate symbolic link file category. -> indicates note.sym contains the pathname for the filename note. Size of symbolic link is only 4 bytes; it is the length of the pathname of note.
            It’s important that this time we indeed have two files, and they are not identical. Removing note.sym won’t affect us much because we can easily recreate the link. But if we remove note, we would lose the file containing the data. In that case, note.sym would point to a nonexistent file and become a dangling symbolic link.
            Symbolic links can also be used with relative pathnames. Unlike hard links, they can also span multiple file systems and also link directories. If you have to link all filenames in a directory to another directory, it makes sense to simply link the directories. Like other files, a symbolic link has a separate directory entry with its own inode number. This means that rm can remove a symbolic link even if its points to a directory.
            A symbolic link has an inode number separate from the file that it points to. In most cases, the pathname is stored in the symbolic link and occupies space on disk. However, Linux uses a fast symbolic link which stores the pathname in the inode itself provided it doesn’t exceed 60 characters.
Security by File Permissions:
Unix has a simple, but well-defined system of assigning permissions to the file. Unix follows a three-tiered file protection system that determines a file’s access rights. It is displayed in the following format:
Filetype owner (rwx) groupowner (rwx) others (rwx)
For Example:
-rwxr-xr–  1   kumar   metal   20500  may 10 19:21  chap02
  
               r w x                             r – x                          r – –
owner/user                       group                     others
The first group has all three permissions. The file is readable, writable and executable by the owner of the file. The second group has a hyphen in the middle slot, which indicates the absence of write permission by the group owner of the file. The third group has the write and execute bits absent. This set of permissions is applicable to others. You can set different permissions for the three categories of users – owner, group and others.
Changing file Permissions:
A file or a directory is created with a default set of permissions, which can be determined by umask. Let us assume that the file permission for the created file is -rw-r–r–. Using chmodcommand, we can change the file permissions and allow the owner to execute his file. The command can be used in two ways:
Β·         In a relative manner by specifying the changes to the current permissions
Β·         In an absolute manner by specifying the final permissions
Relative Permissions:
chmod only changes the permissions specified in the command line and leaves the other permissions unchanged. Its syntax is:
Syntax: $chmod category operation permission filename(s)
chmod takes an expression as its argument which contains:
      user category (user, group, others)
      operation to be performed (assign or remove a permission)
      type of permission (read, write, execute)
Category                    operation                    permission
u – user                        + assign                       r – read
g – group                      – remove                      w – write
o – others                     = absolute                    x – execute
a – all (ugo)
Ex:
Initially,
-rw-r–r–          1          kumar    metal  2011  aug      23:38   xstart
chmod u+x xstart
-rwxr–r–         1          kumar    metal  2011   aug      23:38   xstart
The command assigns (+) execute (x) permission to the user (u), other permissions remain unchanged.
chmod ugo+x xstart     or
chmod a+x xstart         or
chmod +x xstart
-rwxr-xr-x        1          kumar    metal  2011   aug      23:38   xstart
Absolute Permissions:
Here, we need not to know the current file permissions. We can set all nine permissions explicitly. A string of three octal digits is used as an expression. The permission can be represented by one octal digit for each category. For each category, we add octal digits. If we represent the permissions of each category by one octal digit, this is how the permission can be represented:
Β·         Read permission – 4
Β·         Write permission – 2
Β·         Execute permission – 1
Octal                     Permissions                      Significance
0                                  – – –                               no permissions
1                                  – – x                              execute only
2                                  – w –                             write only
3                                  – w x                            write and execute
4                                  r – –                              read only
5                                  r – x                              read and execute
6                                  r w –                             read and write
7                                  r w x                            read, write and execute
            We have three categories and three permissions for each category, so three octal digits can describe a file’s permissions completely. The most significant digit represents user and the least one represents others. chmod can use this three-digit string as the expression.
 
Using relative permission, we have,
chmod a+rw xstart
Using absolute permission, we have,
             chmod 666 xstart
             chmod 644 xstart
             chmod 761 xstart
will assign all permissions to the owner, read and write permissions for the group and only execute permission to the others.
777 signify all permissions for all categories, but still we can prevent a file from being deleted. 000 signifies absence of all permissions for all categories, but still we can delete a file. It is the directory permissions that determine whether a file can be deleted or not. Only owner can change the file permissions. User can not change other user’s file’s permissions. But the system administrator can do anything.
umask Command:
When you create a file and directories, the default permissions that are assigned to them depend on the system’s default settings.these default permissions are inherited by files and directories created by all users.
  • rw-rw-rw- (ocatal 666) for regular files.
  • rwxrwxrwx (octal 777) for directories.
However,these are not the file permissions you see when you create a file or a directory. Actually default is transformed by subtracting the user mask from it to remove one or more permissions. This mask is evaluated by using umask without arguments:
Ex:$umask
022
This is an octal number, and subtracting this value from the file default value yields 666-022 = 644. This represents the default file permissions that you normally see when you created a regular file (rw-r–r–). Similarly, the default directory permissions are also rwxr-xr-x (777 – 022 = 755).
Process Utilities:
A process is defined as an instance of a running program. Like a file , a process has many attributes, and for a proper understanding of its functioning, you need to know some of these attributes. The ps command is used to display the attributes of a process.
By default, ps displays the process associated with a user at the terminal.
Ex: $ps
PID      TTY       TIME        CMD
659       tty03      00:00:01     sh
684       tty03      00:00:00     ps
ps command generates header information. The first qtwo columns show the PID and the terminal (TTY) with which the process is associated. The login shell (sh)
has the PID 659, time shows the total CPU time used by the process. This is generally small because most programs usually complete their jobs quite fast. CMD shows the process name.
ps options:
Option
Significance
-f
Full listing showing the PPID of each process.
-e
All process including the user and system process.
-a
Process of all users excluding process not associated with terminal.
-l
A long listing shows memory related information.
Disk Utilities:
du Command:
The du command is used to display the disk usage(usually in multiples of 1K blocks). du command without any argument displays disk usage of all files, subdirectories of current working directory.
Ex: $du /home/usr1
Options:
Option
Significance
-a
Displays the space that each file is taking up.
-k
Displays the files sizes in units of 1024 bytes.
-s
Displays the sum of usage in the current directory.
df Command:
The df command displays details about each mounted partition, percentage of freeness, percentage of occupation etc.,
Syntax: $df [OPTION]  [FILE]
Ex: $df
df options:
Options
Significance
-h, –human-readable
Print sizes in human readable format(e.g., 1K 234M 2G)
-I, –inodes
List inode information instead of block usage.
-k
Like –block-size=1K
mount Command:
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 several devices. The mount command serves to attach the file system found on some device to the big file tree. Conversely, the umount command will detach it again.
The standard form of the mount command, is
$mount -t type device dir
This tells the kernel to attach the file system found on device (which is of type type) at the directory dir. The previous contents (if any) and owner and mode of dir become invisible, and as long as this file system remains mounted, the pathname dir refers to the root of the file system on device.
Ex:  To mount a file system on the /oracle directory on Linux system use
       $mount –t ext2 /dev/hda3 /oracle
umount Command:
The umount command detaches the file system(s) mentioned from the file hierarchy. A file system is specified by giving the directory where it has been mounted. Giving the special device on which the file system lives may also work, but is obsolete, mainly because it will fail in case this device was mounted on more than one directory.
Ex: $umount /dev/fd0
Networking Commands:
The following are the some of the networking commands in Unix.
β€’         finger
β€’         arp
β€’         ftp
β€’         telnet
β€’         rlogin
finger Command:
This command is used to know the information about the user such as when he has logged into machine, When did he/she see their e-mail,etc., in addition to content of .plan (and other files) of his home directory. By default finger simply produces a list of all logged users on the local machine. But you can use it with an              @-prefixed hostname to obtain similar details for the remote user.
Syntax: finger [-b] [-f] [-h] [-i] [-l] [-m] [-p] [-q] [-s] [-w] [username]
-b   :  Suppress printing the user’s home directory and shell in a long format     printout.
-f     :     Suppress printing the header that is normally printed in a non-long format printout.
-h    :    Suppress printing of the .project file in a long format printout.
-i    :     Force “idle” output format, which is similar to short format except that only the login name, terminal, login time, and idle time are printed.
-l    :     Force long output format.
-m  :     Match arguments only on user name (not first or last name).
-p   :     Suppress printing of the .plan file in a long format printout.
-q   :     Force quick output format, which is similar to short format except that only the login name, terminal, and login time are printed.
-s   :     Force short output format.
-w  :     Suppress printing the full name in a short format printout.
Ex: $finger @sekhar
Login                           Name               Tty                   Idle                  Login Time      Where
henry                           Henry              2                                              aug 3 23:15
sumit                           Sumit               4                      45                    aug 2 12:15
rlogin Command:
With the help of these command, It is possible to login to a remote machine if we happened to have legal username and password on that machine. When we do so, the current machibne becomes terminal to that remote machines. After that, whatever file we created it will be stored in that remote machine.
Syntax: $rlogin [-8] [-E] [-L] [-ec] [ -l username ] hostname
8                     :           Pass eight-bit data across the net instead of seven-bit data.
-E                    :           Stop any character from being recognized as an escape character
-L                    :           Allow the rlogin session to be run in β€œlitout” mode.
-ec                :              Specify a different escape character,c, for the line used to   disconnect from the remote host.
-l username  :         Specify a different username for the remote login. If you do not use this option, the remote username used is the same as your local username.
hostname      :        The remote machine on which rlogin establishes the remote login session.
Ex: $rlogin home
telnet Command:
The telnet command is used to communicate with another host using the TELNET protocol. If telnet is invoked without the host argument, it enters command mode, indicated by its prompt (telnet> ) In this mode, it accepts and executes the commands listed below. If it is invoked with arguments, it performs an open command with those arguments.
Syntax: $ telnet [-8] [-E] [-L] [-c] [-d] [-r] [ -e escape_char ] [ -l user ] [-n file ] [ host [ port ] ]
-8             :                   Specifies an 8-bit data path. Negotiating the TELNET BINARY option is attempted for both input and output.
-E             :                  Stops any character from being recognized as an escape character.
-L             :                  Specifies an 8-bit data path on output. This causes the BINARY option to be negotiated on output.
-c              :                  Disables the reading of the user’s telnetrc file.
-d              :                  Sets the initial value of the debug toggle to TRUE.
-r               :                  Specifies a user interface similar to rlogin . In this mode, the escape character is set to the
                                    tilde (~) character, unless modified by the -e option. The rlogin escape character is only recognized when it is preceded by a carriage return. In this mode, the telnet escape
                                    character, normally ‘^]’, must still precede a telnet command. The rlogin escape character
                                    can also be followed by ‘.r’ or ‘^Z’, and, like rlogin, closes or suspends the connection, respectively. This option is an uncommitted inter- face and may change in the future.
-e
escape_char:         Sets the initial escape character to escape_char. escape_char may also be a two character sequence consisting of ‘^’ followed by one character. If the second character is ‘?’, the DEL character is selected. Otherwise, the second character is converted to a control character and used as the escape character. If the escape character is the null string (that is, -e ”), it is disabled.
-l user          :               When connecting to a remote system that understands the ENVIRON option, then user will be sent to the remote system as the value for the ENVIRON variable USER.
-n file          :                Opens tracefile for recording trace information.
arp Command: (Address resolution protocol)
This command is used to manipulate arpcache. That is, we can see the arp cache, remove a hosts entry from the arpcache, etc., In a networked system when a packet arrives at router machine(often a Unix machine) then the IP address to ethernet address mapping is neede. This is achieved by arpprotocol. These mappings are stored in arpcache such that next time another packet arrives with the same IP address then its Ethernet or physical address is calculated by carrying out a lookup operation on this arp cahce. With arp command we can modify, view, delete the entries of cache.
$arp  -a                                    :           Displays all entries.
$arp  -a  hostname                   :           Display entries of the given host.                  
$arp -d  hostname                   :           Removes  the entries of the specified host
$arp –s  hostname HW_addr :       Creates manually arp entry for the host with the     given hardware address.
find Command:
In Unix and some other operating systems, find is a command-line utility that searches through one or more directory trees of a file system, locates files based on some user-specified criteria and applies a user-specified action on each matched file. The possible search criteria include a pattern to match against the file name or a time range to match against the modification time or  access time of the file. By default, find returns a list of all files below the current working directory.
Syntax: $ find path expressions
Ex: $find –name raj
          This command displays all occurrences of the file named raj in current directory.
  
      $find /-name raj
            This command displays all occurrences of the file name raj under / directory.
ulimit Command:
Unix system has resource limits such as limits on number of process, maximum allowed file size, etc.,
Ex: $ulimit  -a
-c         :           Displays maximum core file size(in blocks).
-d         :           Displays maximum size of the data segment.
-R        :           Displays maximum file size.
-n         :           Display open files
-s         :           Display stack size.
-t          :           Display maximum CPU time.
-v         :           Display maximum size of virtual memory in Kbytes.
who Command:
Unix maintains an account of all users who are logged on to the system. It’s often a good idea to know their names so that you can mail them messages or set up a chat session. The who command displays an informative listing of the users.
Who produces a simple three-coloumn output.
Ex: $who
root                 console                        aug  03  00:16
sekhar             tty01                            aug  03  23:58
The first coloumn shows the user-id’s of the four users currently working on the system. The second coloumn shows the device names of their respective terminals. The third coloumn shows the date and time of logging in.
And we can display your username with who am i or whoami.
w Command:
The w command produces a more detailed output of users activities and additionally displays many detail of the system.
Ex: $w
2:40pm    up   1:37,   3 users,   load average:   0.00, 0.00, 0.00
User                tty                    From        Login@         Idle   Jcpu      Pcpu   What
Raj              tty1                            1:24           6.0s   11.20s  11.01s  vi ux3rd

The first line in the output indicate the time when the command was executed at 2:40pm on a system having one user. The system itself has been up and running for 1 hour and 37 minutes.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks