Saturday, July 12, 2014

Hard links and Soft Links

Links are special files that point to other files. An operation performed on a file that is a link is actually performed on the file that is pointed to by the link. There are two kinds of links:-


  • Hard Links
  • Symbolic or Soft  Links 
Hard Links:-

A hard link is another name for an existing file and is indistinguishable from the file it is linked to.If a file is altered any hard links to it are also altered ; and conversely, altering any hard link will also alter the original file and any other hard links that it may have.However if  the original file is removed , any hard links will still contain the contents of the original file. This is because a hard link is another INSTANCE of the file it points to.

Hard Links have two limitations:
- Hard Links cannot be created across file-systems.
- Hard Links cannot be created for directories, even if, those directories exist within  the same file-system.

Each file on the system has at least one hard link, which is the original file name itself. Directories  always have at least two hard links - the directory name itself( which appears in the parent directory) and the special file, inside the directory.Likewise , when a new sub-directory is created, the parent directory gains a new hard link for the special file... inside the new sub-directory.

If a hard link is removed, the original file and its other hard links are not removed; and conversely, even if the original file is removed, its hard links still remain intact.


Symbolic or soft links:



Symbolic Links or soft links are pointers to a file that exists elsewhere.A symbolic link passes most operations( such as reading and writing)  to the file it points to.Symbolic Links are  identified in file listingswith an "l" in the first character of the first column, and , by default, are output as cyan  in colour listings.
If a symbolic link is deleted only the link is deleted and not the  original file .  However, if  the original file is deleted and replaced with another file, the symbolic link will point to the contents of the new file.

As opposed to hard links , symbolic links can be created across filesystems. Also, we can create symbolic links for directories.
Windows shortcuts are an excellent example of symbolic links.



Tuesday, February 19, 2013

File Attributes

The common characteristics of all files are called the attributes of a file. They are as follows:-
  • Name: A filename is a string (i.e., a sequence of characters) that is used to identify a file. File names in Linux can contain any characters other than - a forward slash ( / ) and the null character. The forward slashis reserved for use as the name of the root directory (i.e., the directory that contains all other directories and files) and as a directory separator. The null character is used to terminate segments of text. Spaces are permitted, although they are best avoided because they can be incompatible with legacy software in some cases. Typically, however, file names only use alphanumeric characters (mostly lower case), underscores, hyphens and periods. Other characters, such as dollar signs, percentage signs and brackets, have special meanings to the shell(they are used as shell metacharacters).File names should never begin with a hyphen.A relatively small number of file names on a system consist only of upper case characters, such as README, INSTALL, NEWS and AUTHORS. They are usually plain text files that come bundled with programs and are for documentation purposes.File names were limited to 14 bytes (i.e 14 characters) in early UNIX systems. However, modern Unix-like systems support long file names, usually up to 255 bytes in length. File names can be as short as a single character.File names consist of two parts: a user-designated name and an extension which is determined by the type of file. The two are separated by a period.Although Unix-like operating systems generally do not require the use of file extensions, they can be convenient and useful. In particular, they can make it easy to identify file types at a glance and to facilitate manipulating groups of files. Files can also have multiple extensions.File names must be unique within a directory. However, multiple files and directories with the same name can reside in different directories because such files will have different absolute pathnames (i.e., locations relative to the root directory), and thus the system will be able to distinguish them.On a Unix-like operating system any file or directory can have multiple names because of the operating system's use of inodes instead of names to identify files and directories. Additional names can be provided by using the ln command to create one or more hard links to a file or directory.
  • Location: As files have places inUnix, therefore, paths need to be specified to define the location of a file. There are two methods of specifying paths. The absolute path is a sequence of directories from the root to the directory in which the file is housed. Each directory in the path is separated by a forward slash (/). A relative path is a sequence of directories from any of the directories above the current file and is a part of its parent tree. A path is different from a pathname as a pathname always ends up in an ordinary file whereas a path ends in a directory file. Consider the following directory structure: unix image1 The absolute path for the file file2 is /usr1/a1.dir and the pathname is /usr/a1.dir/file2. The relative path for file 2 is simply a1.dir where the current working directory is usr1 . The relative pathname is a1.dir/file2.
  • Size of a file: This is given in terms of bytes and is limited by the physical capacity of the disk and the disk qoutas assigned by the superuser.
  • Link Count: The link count of a file is a special number attached with each file which counts the number of files with different pathnames that access the same physical file. Links are implemented as hard or soft. (Links will be discussed in the next post).
  • i-node number: It is a unique number that the kernel assigns to each file for identification. An inode structure is defined per file , where inode- number is one of its prime members along with attributes like size of file, ownership, permissions , link count, address of disk blocks etc.
  • Time stamps: There are three time stamps attached to each file :-
    • Time of creation
    • Time of last modification
    • Time of last access
    These time stamps are automatically updated by the Unix system but they can be modified by the user with the help of commands like 'touch'.
These were the file attributes typically assosciated with each file. We shall discuss them in greater detail along with the assosciated commands when we discuss the topic 'Handling File Attributes'. The next post will discuss hard links and soft links.

Friday, February 15, 2013

Types of files in Unix

There are four types of files in Unix. They are:-
  1. Regular or Ordinary Files
  2. Directory Files
  3. Device Files
  4. FIFO Files

Regular Files:

These files usually consist of a sequential series of bytes and occupy space on the disk. They always form a leaf node in the tree hierarchy. They have no fixed format. Their format and structure is totally dictated by the utility that creates and accesses such files.These files can be created using editors like ed,ex, vi or from the standard input using 'cat>filename' command. An ordinary file can be a text file from a word processing package, a program written in any language of the shell etc.

Directory Files:

A directory is just a tabular collection of files and subdirectories. The contents of a directory can be any number of ordinary files, device files and directory files. A directory file can be thought of as the branch of the Unix file system tree.Each directory has a name of normally upto 14 characters. Two or more files can have the same name if they are in different directories. It is only the kernel which can write a directory file. It is the kernel , which updates the corresponding directory file whenever a user adds or deletes a file from it. A user can only create directories, add or delete files from a directory ,or delete the directory itself.All the directories created by the user reside in the home directory of the user. The home directoryis assigned to the user when they are assigned a recognised login name. The user has complete control over the home directory; no one else except a privileged user can read or write files in it without the user's permission. The Unix system also maintains several directories for its own use.The structure of these directories is much the same on all Unix systems. These directories which include several important system directories, are located directly under the root directory.The root directory (designated by /) is the source of the Unix file structure; all directories and files are arranged hierarchically under it.

Device Files:

All device files(i.e terminals , printers and other hardware) in Unix are called special files. This is the key to providing device independence. The system reads and writes to special files in the same way it does to ordinary files.However, the system read and write requests to do not activate the normal file access mechanisms; instead they activate the device handler assosciated with the file. The advantage of having devices as files is that you don't need any special commands or function to access devices. The output directed to such a file will be automatically redirected to the respective physical device associated with the filename. The kernel implements this by mapping special filenames to their respective devices.For example: the user could direct the output of a process or a file-listing to the printer by using the printer name in a command.Similarly , if the user wants to print a file, the system would simply write the file to the printer device file just as it would write to any other file. This allows you to control access to any device very effectively. All the Unix device files are stored in a directory called /dev, which resides immediately below the root directory. Devices in the Unix file system can also be thought of as leaves in the Unix file system tree.The special files associated with devices are not really files but pointers that point to the device drivers located in the kernel that handles data flow.Since the devices to be handled are addressed as files, the protection that is applicable to files is also applicable to devices. There are two types of device files - block special files and character special files. Block special files are for disk and tape devices.Block devices are divided into blocks (which are units of storage on the hard disk) . These blocks are used to store i-node entries of the files. i-nodes dictate the position of blocks through a process called indirect addressing. Character special files are for terminals ,printers , RAM etc. A character device is simply a device from which characters are read. They do not require the data to be buffered before it is read . /dev/kmem and /dev/mem are character special files for main memory.

FIFO(First In First Out) Files:

FIFO files let unrelated file communicate with each other. These files are typically used in applications where the communication path is one-way only and where a number of processes have to communicate with a single process, often called the daemon process . Each process writes a message to the FIFO file , and the Unix system guarantees that another user will not overwrite each individual message written on the file. Even though Unix treats all files similarly, files are categorized into the above three types because the files attributes associated with each file is different for each category. File attributes are common to all files with slightly different interpretations.In the next post we shall discuss these file attributes.

Wednesday, February 13, 2013

The Unix File System

The Unix file system is a hierarchical, tree- structured name space that is designed to help users organize and access files.The namespace consists of directories that hold files.The tree-structure consists of a root directory and branching subdirectories. Each subdirectory can have its own directories. Each directory may contain its own files. Every type of data in Unix is arranged in files , therefore it is essential to understand the Unix file system ;first on a logical level and then as its structure on the physical device. Unix treats everything it knows and understands as a file. A file to Unix is an array of bytes and its size is simply equal to the number of bytes present in it. Unix treats even directories and devices as files. A file can contain text , object code or a directory structure. The dominant file type is text which contains a series of bytes, sometimes with a suitable delimiter to separate fields. In Unix, all files have places and are collectively arranged as a top-down tree structure.The Unix file system provides a logical method of organising , retrieving and managing information.

Features of a Unix file System:

  • Hierarchical Structure:The Unix system groups all files under another type of files called directories.The whole structure is organized as an upside down hierarchical tree structure. Thus, all files always have a parent file apart from one directory file called the root directory. The root directory is the parent of all the files on the system. The greatest advantage of arranging files in a hierarchical structure is the dynamic flexibility of adding and deleting files at any level. It also improves access time. It was the Unix operating system which introduced the hierarchical file structure.
  • Structureless/ featureless files: Unix imposes no format or structure on the contents of a file.Any format imposed is by the utility that creates the files and not the Unix operating system. The Unix operating system treats all files simply as an array of bytes. A Unix file does not contain an extension . for e.g. A C program written on Unix does not contain a .c extension. The .c extension is added later due to the requirements imposed by the C compiler.
  • Dynamic File Expansion:The size of a file is not restricted by any rule other than amount of disk-storage space available. The sizes of the files and the number of files can be dynamically modified.
  • Security: Unix provides security at various levels. Files are protected using file ownership mechanisms. All users are divided into three groups and each group is granted access or denied access in terms of read, write and execute permissions for each file separately.
  • Device Independence: As devices and directories are both treated as files in Unix, therefore, a user is protected from knowing the details of device related operations and procedures.
In the next post we shall continue with the discussion of the Unix file system.Specifically we will discuss the three types of files supported in the logical view of the Unix file system.

Sunday, January 8, 2012

bc

bc  is an arbitrary-precision arithmetic language in unix.
 

Syntax:
bc [-c] [-1] [file...]

bc is an interactive processor for a language that resembles C but providesunlimited precision arithmetic.It takes the input from any of the given files, then reads the standard input. bc is actually a preprocessor for the desk calculator program dc, which it  invokes automatically unless the -c option is present. In this case the dc input is sent to the standard output.

-c: Compile only.The output is sent to the standard output.
-1: Argument stands for the name of an arbitrary precision math library.

The syntax for bc programs is as follows:

here L means the letters a-z

         E means expression

         S means statement

Comments are enclosed in /* and*/

 

Names:

   simple variables:L

   array elements:L[E]

   the words ibase (for input base),  obase( for output base) and  scale

Other operands:

   arbitrarily long numbers with optional sign and decimal point(E)

   sqrt(E)

   length(E) : number of significant decimal digits

   scale(E):   number of digits right of decimal point.

   L(E,...,E)

Operators:

  +-*/%^(% is for remainder and ^ is for power)

   ++,-- (prefix and postfix)

   == <= >= ! < >

   = =+ =- =* =/ =% =^

Statements:

  E

   {S;...;S}

  if(E)S

  while (E)S

  for(E;E;E)S

  null statement

  break

  quit

Function Definitions:

  defineL(L,...,L){

   auto L,..,L

   S;...S

   return(E)

}

Functions in -1 math library:

   s(x): sine

   c(x): cosine

   e(x): exponential

   l(x) :  log

   a(x): arctangent

   j(n,x): Bessel function

All function arguments are passed by value.

The value of  a statement  that is an expression is printed unless the main operator is an assignment. Either semicolons or newlines may separate statements.Assignments to scale influences the number of digits to be retained on arithmetic operations in the manner of dc.Assignments to  ibase  or obase set the input and output number radix respectively.

The same letter may be used as an array, a function and  a simple variable simultaneously. All variables are global to the program. auto variables are pushed down during function calls.When using array  as function arguments, or when defining them as automatic variables,empty square brackets must follow the array name.

The files used for bc command are

/usr/lib/lib.b   mathematical library

/usr/bin/dc     desk calculator proper

Also,

    the bc command does not recognise the logical operators && and ||.
    the for statement must have all three expressions
    the quit statement is interpreter when read not executed.

Tuesday, December 6, 2011

The echo command

The echo command echoes its arguments separated by blanks and terminated by a new line on the standard output.
Syntax:
              echo [arg] 
              echo[-n][arg]


The /user/bin/sh version understands the following C-like escape sequences:
 \b  backspace
 \c  print line without newline
\n   new--line
\r    carriage return
\t    tab
\v   vertical tab
\\    backslash
\n   where n is the 8 bit character whose ASCII code is the 1,2or 3 digit octal number representing that character.

The following option is available to /usr/bin/sh users only if /usr/ucb preceeds /usr/bin in the user's path.It is available to  /usr/csh users regardless of the PATH:
-n  Do  not add newline to the output

The echo command is useful for producing diagnostics in command files, for sending known data into a pipe, and for displaying the contents of environment variables.

The next command will be bc which is an arbitrary-precision arithmetic language in unix

Sunday, November 27, 2011

Choosing a Password and Password Files

Choosing a Password:


Passwords must be constructed to meet the following requirements:


  • Each password must have atleast PASSLENGTH characters as set in /etc/default/passwd file.PASSLENGTH must contain a minimum of 6 characters, but only the first 8 characters are significant.
  • Each  password must contain at least 2 alphabetic characters and atleast 1 numeric or special character.
  • Each password must differ from the user's login name and any reverse or circular shift of that login name. For comparison purposes, an upper case letter and its corresponding lower case letter are equivalent .
  • New passwords must differ from the old by atleast 3 characters.

Password Files:

The passwd  command uses the files /etc/shadow, /etc/passwd and /etc/oshadow.
The file /etc/passwd contains the following information for each user:
  • login name
  • dummy password
  • numerical user ID
  • numerical group ID
  • comment
  • initial working directory
  • program to be used as the shell
passwd is an ASCII file . Each field within each user's entry is separarted from the next by a colon. The comment field  can contain any information that the user desires. each user is separated from the next by a new-line. If the shell field is null, /usr/bin/sh is used.

This file has user login information and general read permission. It can therefore be used , to map numerical user ID's to names.
The password field consists of the character x.Password information is contained in the file /etc/shadow.




The next command will be the echo command.


Wednesday, November 23, 2011

The passwd command- continued

To recollect the syntax of the passwd command is:
              passwd[name]
              passwd[-l |-d ][-f][-n min][ -x max][-w warn] name
              passwd -s [-a]
              passwd -g [name]


The following options can be used only by a privileged user:

  • -l: Locks password entry for name.
  • -d: Deletes password for name. The login name will not be prompted for password.
  • -n: Sets minimum field for name.  The  min field contains the minimum number of days between password changes for  name.  If value of  min  >value of  max, the user may not change the password.Always use this option with the -x option, unless max is set to -1(ageing turned off ). In that case, min need not be set.
  • -x: Sets maximum field for name. The max  field  contains the number of days that the password is valid for name. The ageing of name  will be turned off if max is set to -1.
  • -w: Sets  warn  field for name. The warn  field contains the number of days the user will be warned before the password expires.
  • -a:  Shows password attributes for all entries. Use only with -s option ; name  must not be provided.
  • -f:  Forces the user to change password at the next login by expiring the password for name.
 Any user may use the -s option to show password attributes for one's own login name.
The format of the output will be:
name status mm/dd/yy min max warn

 Or, if password ageing information is absent,
name status

Super users may change any password; hence; passwd does not prompt privileged users for the old password. Privileged users are not forced to comply with password ageing and password construction requirements. A privileged user can create a null password by entering a carriage return in response to the prompt for a new password.

The passwd command exits with one of the following values:
0 SUCCESS
1 Permission denied
2 Invalid combination of options
3 Unexpected failure. Password file unchanged.
4 Unexpected failure .Password file is missing.
5 Password file(s) busy .Try again later
6 Invalid argument to option.


If root deletes a password for a user with the passwd -d command and password ageing is in effect for that user, the user will not be allowed to add a new password until the NULL password has been aged.This is true even if  the PASSREQ flag in /etc/login/default  is set to YES. This results in a  user without a password. It is recommended that the -f option be used with the  -d option so that the user is forced to change the password at the next login.


The next post will list the rules for choosing a password and the details of the files used by the passwd command.

Monday, November 21, 2011

The passwd command

The passwd command changes the password or lists attributes assosciated with the user's login name. Additionally, privileged users may use this command to install or change passwords and attributes assosciated with any login name.

Syntax:
              passwd[name]
              passwd[-l |-d ][-f][-n min][ -x max][-w warn] name
              passwd -s [-a]
              passwd -g [name]

  The behaviour of this command is extremely system-dependent.It asks you to enter your old  password, and if that is typed correctly,prompts you to enter your new password twice.The password may be chosen by a unix system or customized by the user. Some system administrators implement password aging which for security reasons forces the user to change the password after a certain period of usage.

Unix updates the corresponding files /etc/passwd  and /etc/shadow  for every change in password.
/etc/passwd  lists information about users.A user can read this file but not write into it. Each field of information is separated from the next by a ':' .An /etc/passwd file  dispalys login name, encrypted password,user ID, group Id, comment , default  working directory, default working shell.

There is another password file present in  /bin  directory called /bin/passwd . It is this file that actually gets executed when we change the password. Thus, /bin/passwd  is  an executable file which permits changing of password, whereas /etc/passwd  contains the information about each user.
 I shall discuss the options of the passwd command in the next post.

The uname command

The command uname prints the name of the current unix system.

Syntax:
uname[-amnprsv]
uname[-S system_name]
uname prints the current system name of the unix system to standard output.It is mainly useful to determine which system one is using.The options cause selected information returned by uname and/or sysinfo command to be printed:
  • -a : Print all information.
  • -m: Print the machine hardware name.
  • -n:  Print the node name(name by which the system is known to the communication  network)   .This is the default setting.
  • -p: Print the processor type of the current host.
  • -r: Print the operating system release.
  • -s:Print the name of the operating system.
  • -v: Print the version of the operating system.
 On your computer specifying a system name argument to the -S option may change the node name. The system name argument is restricted to SYS_NMLN  characters.SYS_NMLN is an implementation specific value defined in <sys/utsname.h>  file. Only the super-user is allowed to use this capability.

The next post will talk about the passwd command.

Tuesday, November 15, 2011

The tty command

The unix command tty displays the name of the terminal type.tty is the controling terminal interface.
The file /dev/tty is, in each process a synonym for the control terminal assosciated with the process group of that process. It can be used for programs that demand the name of a file for output, when typed output is desired .

Syntax:
            tty[-l][-s]
 The tty command prints the path name of the user terminal.
-l prints the synchronous line number to which the user's terminal is connected, if it is on an active
    synchronous line.
-s inhibits the printing of the terminal path name, allowing one to just test the exit code.
    The exit codes are as follows:
 2 if invalid options were specified
 0 if standard input is a terminal.
 1 otherwise

The error message  not an active synchronous line,  appears if the standard input is not a synchronous terminal and -1 is specified.

The error message  not a tty, appears if the standard input is not a terminal and -s is not specified.

The who command -continued

The options assosciated with the who command are as follows:

  • -u:    This option lists only those users who are currently logged in .The name  is the user's login name. The line is the name of the line as found in the directory /dev. The  time is the time that the user logged in. The  idle column contains the number of hours and minute  since  activity last occurred on that particular line. A dot(.) indicates that the terminal has seen activity in the last minute and is therefore 'current'. I f more than 24 hours have lapsed or the line has not been used since boot time, the entry is marked old. This field is useful to find out whether a person is currently working at the terminal line or not. The pid is the process-ID of the user's shell. The  comment is the comment field assosciated with this line as found in  /sbin/inittab  file. This can contain information about where the terminal is located, the telephone number of the data set, type of terminal if hard-wired and so on.
  • -T:     This option is same as the -s option except that the state  of the terminal line is printed.The state  describes whether  someone else can write to that terminal. A '+' appears if the terminal is writeable by anyone, else a '-' sign appears.  root  can write to all lines whether a '+' appears or a '-'.If a bad line is encountered a question mark(?) is printed.
  • -l:       This option lists only those lines on which the system is waiting for someone  to login.The  name is LOGIN  in such cases. Other fields are same except that the  state  field does not exist.
  • -H:     This option will print column headings above the  regular output.
  • -q:      This is a 'quick who' listing only the names and numbers of the users currently logged in. When this option is used all other options are ignored.
  • -p:      This option lists any process that is currently active and has previously been spawned by init. The  name is the name of the program executed by init   as found in /sbin/inittab file. The state,line  and idle  fields have no meaning .The  comment  field shows the  id  field from the   /sbin/inittab  file that generated this process.
  • -d:       This option displays all processes that have expired and not been regenerated by init.The exit field appears for dead processes and  contains the termination and exit values, as returned by the wait command. This can be useful in determining why a process terminated.
  • -b:        This option indicates the time and date of the last reboot.
  • -r:         This option indicates the current run level of the init process.It also displays the process termination status ,process-ID and process exit status under the idle,pid and the comment  headings respectively.
  • -t:          This option indicates the last change to the system clock via the date  commnad , by root. 
  • -a:         This option processes /var/adm/utmp  file or the named file with all options turned on.
  • -s:         This option is the default and lists only the  name, line and time fields respectively.
  • -nx:       This optin takes a numeric argument, x , which specifies the number of users to display per line. x must be at least 1. The -n option must be used with -q.

After a shutdown to the single user state, who returns a prompt.The reason is that since /var/adm/utmp file is updated at login time and there is no login in single user state, who cannot report accurately on this state.  who am i  however returns the correct information.
The who command uses the files / var/adm/utmp, / var/adm/wtmp  and /sbin/inittab.

 The next post would be about tty command.

Sunday, November 13, 2011

The who command

The who command lists the login names of everyone currently working on your system. the tty designation refer to the special files that correspond to each user's terminal. The date and time at which each user logged in are also shown.

Syntax:
        who[-uTlHqpdbrtas] [file]
        who -qn x[file]
        who am i
        who am I

The who command can list the user's name,terminal line,login time,elapsed time since activity occured on the line and the process-ID of the command interpreter(shell) for each current unix system user. It examines the   /var/adm/utmp  file to obtain its information.If file  is given , that file, is examined. 

The am i or am I  option identifies the user invoking the who command.

The general format for output is:
name [state] line time [idle] [pid] [comment] [exit]

The name,line and time information is produced by all options except -q. The state information is produced only by -T; only u and -l produce the idle and pid information; and the comment and exit information is produced only by -a. With options who can list logins , logoffs, reboots and  changes  to the system clock, as well as other processes  generated by the init process.
The  options  will be discussed in the next post.

Friday, November 11, 2011

The date utility-Part 2

The date utility also supports specifications of native language translations of month and weekday-names. The names used for a language are based on the locale specified by the environment variables LC_TIME and LANG in the environ command. The month and weekday names are taken from a file whose format is specified in strftime command. This file also defines country specific date and time formats such as %c, which defines the default format of date 


The field descriptors mentioned in the previous post are:
 a- abbreviated weekday name
 A- full weekday name
 b- abbreviated month name
 B- full month name
 c- country specific date and time format
 d- day of month 01 to 31
 D- date as %m/%d/%y
 e-  day of month 1 to 31(single digits are preceeded by a blank.
 h- abbreviated month name(alias for %b)
 H- hour 00 to 23
 I- hour 1 to 12
 j- day of year 001 to 366
 m- month of year 01 to 12
 M- minute 00 to 59
 n- insert a new line character
 p- string containing anti-meridiem(A.M.-before noon ) or post meridiem(PM- after noon)    
      indicator

 r- time as %I:%M:%S:%p
 R- time as%H:%M
 S- second 00 to 61 allow for leap seconds
  t- insert a tab character
 T- time as %H:%M:%S
 U- week number of year(Sunday as first day of the week)-0 to 53
w- day of week sunday = 0
W- week number of year(Monday as first day of the week) 00 to 53
x- Country specific date format
X- Country specific time format
y- Year within century 00 to 99
Y- year as ccyy(4 digits)
Z- time zone name

Examples:

1.date
   Lists the date and time of the server. Below is an example of the output.

   Fri Nov 11 16:47:32 MST 2011

2.date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
   Would list the time and date in the following format.
   
    DATE: 11/11/11
    TIME:  13:50:15

The following example would work only if you are the super user:
3.date -s "11/11/2011  01:48:00"

Sets the date to the date and time shown.


The next post would be about the who  command.

 

Saturday, November 5, 2011

The date utility-Part 1

date utility is used to display current time and date.No user can modify the date and time unless they are the  superuser  i.e the system administrator.This is required for the smooth functioning of the system. 
Syntax:
              date[-u][+format]
              date[-a[-]sss.fff][-u][[mmdd]HHMM | mmddHHMM[cc]yy]
 If no argument is given, or if the argument begins with +, the current  current date and time are printed.


-a[-]sss.fff     Slowly adjusts the time by sss.fff seconds,where fff represents fractions of a          
                        second.The adjustment can be positive or negative.The clock of the system will be
                        speeded up or slowed until it has drifted by the number of seconds specified.
-u                    Displays (or sets) the date in GMT(Greenwich Mean Time), bypassing the normal 
                        conversion to or from normal or local time.
mm                 is the month 
dd                   is the day of the month
HH                  is the hour in the 24 hr system.
MM                 is the minute 
cc                   is the century minus one.
yy                   is the last two digits of the year .The month, day,year and century may be
                        omitted; the current values are applied as defaults. 
                        For eg: date 12301600 sets the date to Dec 30, 4:00 PM. The current year is the  
                        default because no year is supplied . The system operates in GMT. date takes  
                        care of the conversion to and from the local standard and daylight saving time.
                        Only the superuser may change the date.After successfully setting the date and  
                        time date displays the new date according to the default format. The date utility
                        uses the TZ in environ  command to determine the correct time zone information.
+format         If the argument begins with +, the output of the date is under the control of the  
                        user. Each Field Descriptor, described in the next post,is preceeded by %, and  
                        is replaced  in the output by its corresponding value.A single % is encoded by  
                        %%.  All other characters are copied to the output without change. The string is 
                        always  terminated by a newline character.If the argument contains embedded 
                        blanks ,it must be qouted. 

Thursday, November 3, 2011

Unix utilities- banner and cal

Utilities  are  the core tool kit of the Unix command set, including banner ,cal, who and many others.  Subcategories include:  
1. System utilities – administrative tools such as mkfs, fsck, and many others.
 
2.User utilities – environment management tools such as passwd, kill, and others.


banner:  The banner utility makes posters. 
                  Syntax:  banner strings
The banner utility prints its arguments , each up to 10 characters long, in large letters on the standard output.

However the banner utility works only in Unix and not in Linux.


cal:   The cal  utility prints a calendar.
          Syntax:  cal [ [month] year]
The cal utility prints a calendar for the specified year. If a month is also specified, a calendar is printed just for that month.If neither is specified, a calendar for the present month is printed.
The month is a number between 1 and 12. The year can be between 1 and 9999.The calendar produced is that for England and the United States, i.e. the Gregorian calendar.

An unusual calendar is printed for September 1752.In this month ,11 days were skipped to make  up for lack of leap year adjustments. To see this calendar type:  cal 9 1752

Also note that cal 83 refers to the year 83 and not to the year 1983.

Next we will be discussing the date utility which has a number of options.  

Wednesday, November 2, 2011

Internal and External Commands

Unix commands are grouped into two categories-Internal and External. There is a set of commands which are part of the shell and to execute them the shell does not need to search the given path in the PATH  variable. These are also called  shell builtins or Internal Commands. The shell does not fork a new process for these commands.

Commands that are available as independently compiled C programs usually located in the /bin or the /usr/bin directory are called  External Commands.  The shell searches the path for these command files. An example is the 'ls ' command which is used for directory listing.

To find out whether a particular command is Internal or External  and to find out the location of  an External Command, the 'type' command is used.

Example:

$ type ls
       ls is /bin/ls
the above command returns the location or the path of the ls command .Therefore ls is an external command.

$ type echo
          echo is a shell builtin
the 'echo' command is an Internal Command or a shell builtin.

$ type LS
         LS: not found

As unix is case sensitive the shell cannot locate the ls command when typed in upper case(capitals).

In the next post I shall list out some  unix utilities.

Tuesday, September 13, 2011

Shell Commands

A program is a set of instructions to the computer.Programs that can be executed by the computer without need for translation are called Executable Programs or Commands.
As a user of the unix system ,there are many standard programs and tools available to you.
You can also employ system calls, subroutines etc. to write programs and develop software on unix. 


The syntax of  a unix system command line is:

          command option(s) arguments


 Command is the name of the program you want to run.



Options or Flags modify how a command runs.Flags are generally one letter codes preceeded by a '-' sign,'+' sign or by no character.


Parameters or Arguments specify data that the command processes,usually the name of a directory or file.
 
Space separates commands and arguments and arguments among themselves.If arguments need to have spaces and yet be treated as one argument, these must be enclosed in double quotes(") or single quotes(').


Each new command has to be entered after command line separators  which are a semicolon enter key and an ampersand(&).


Unix handles user commands through a COMMAND INTERPRETER. Command Interpreter  is  a special interface program that processes commands entered at the keyboard. After you log in a command prompt( a symbol that indicates that the interpreter is ready for the command to be entered) will be shown which may look like 
%
or
machine %


where 'machine' is the name of that particular unix system. The command prompt may be different as there are three command interpreters- the C shell, the Bourne shell and the Korn  shell.


To execute a command,enter  a command line when a prompt (such as a $ sign) appears on the screen. The shell considers your command as input, searches through one or more directories to retrieve the program you specifiedand conveys your request along with the program requested  to the kernel.The kernel then follows the instructions in the program and executes the command you requested.


After the program has finished running the shell signals that it is ready for your next command by printing another prompt.

Tuesday, August 30, 2011

Basics of Unix Commands

Unix is a command line based operating system. Unix commands can be combined to perform complex tasks.To perform these tasks repeatedly these commands can be placed in files called shell scripts and these shell scripts can be executed to provide the required output.

Unix users and processes:


Unix has two basic concepts : files have places and processes have life . All files are placed at some location and each process travels  in a life cycle from birth to death.


Each user in unix is identified by uniquely by an  identification number,name and group identification.A user is able to access  a unix system only after being given a login name and password by the system administrator. When a user tries to access a unix system it displays a  login  prompt where the users types in the login name and password. If the user is a valid user , a shell prompt($) appears on the screen where unix commands can be typed..


A user can end a unix session by pressing < ctrl+d >.  Ctrl+d kills a process.


Command Line is defined as the line on which the shell prompt occurs and a command with its arguments is  entered  and is considered complete only when the enter key is pressed.
The command may spill over multiple lines shown by a secondary prompt (>). The complete line is then fed to the shell as its input for interpretation and execution.


Unix is CASE SENSITIVE. All unix commands must be typed in LOWER CASE.


The next post would be concerning shell commands- the syntax and the  actual commands.


 

Saturday, August 27, 2011

The Unix System Architecture

An operating system(OS) is an intricately woven fabric of programs.The programs are usually coded in the assembly language and are  specific to the processor around which the computer is built. The unix OS ,on the contrary, is written largely in the 'C' language which is not processor dependent. However, part of the unix os is written on the Assembler. This makes Unix highly portable- which means that it can run on various processors with little modification.
The structure of the Unix OS makes it a better OS as compared to other conventional operating systems.

The responsibilities of an OS include command interpretation,I/O control, communications and a lot more .To perform these tasks a large number of simple as well as complicated programs are needed. These programs can be independent or interdependent. In conventional operating systems, all these programs are put  together forming one large program that occupies a large amount of memory. Therefore the system response is very slow. Unix with a fresh structural approach does not slow down the system.

The Unix system can be divided into four major units. These units work together but are still separate so that one large portion of the memory does not get blocked and slow the system down.
 
The four units are:-


1. Kernel- A core unit that interacts with the hardware for low-level functions. The kernel is  a program that constitutes the nucleus of the operating system. It co-ordinates the internal functions of the computer, such as allocating system resources. The kernel works invisibly. The user will never be aware of it while working on the system.


2.Shell- An outer unit that interacts with the user to perform functions desired by the user. The shell is a program that acts as a liason between the user  and the kernel by interpreting and executing user commands. As it reads user input and sends messages to the user it is described as interactive.

3.Commands - Commands  are compiled C programs that perform a specific operating system job. These commands are invoked by name through the shell. Unix has very few in- built commands(internal commands) like 'echo'and 'pwd'. For these no separate C compiled programs are required. These are the shell's inbuilt features and the  shell is able to interpret them itself. Unix commands  perform  a range of functions like editing, copying , erasing files, sending and receiving emails etc.

4.File System- The file system is a collection of all the files available on the computer. It allows you to store and retrieve information easily.