Friday, December 26, 2014

Introduction to the shell

The command interpreter is the interface between the user and the operating system, hence the name "shell".

The shell, a shell between the OS and the userThe shell therefore acts as an intermediary between the operating system and the user thanks to command lines that are entered by the latter. Its role consists in reading the command line, interpreting its meaning, carry out the command, and then return the result via the outputs.

The shell is an executable file responsible for interpreting the commands, transmitting them to the system, and returning the result. Ther are several shells, the most common being sh (called "Bourne shell"), bash ("Bourne again shell"), csh ("C Shell"), Tcsh ("Tenex C shell"), ksh ("Korn shell"),and zsh ("Zero shell"). Their name generally matches the name of the executable.





Shell Name
Developed by
Where
Remark
BASH ( Bourne-Again SHell )Brian Fox and Chet RameyFree Software FoundationMost common shell in Linux. It's Freeware shell.
CSH (C SHell)Bill JoyUniversity of California (For BSD)The C shell's syntax and usage are very similar to
the C programming language.
KSH (Korn SHell) David Korn AT & T Bell Labs
--
TCSHSee the man page.
Type $ man tcsh
--
TCSH is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).

                 Each user has a default shell, which will be launched upon opening of a command prompt. The default shell is specified in the dans configuration file /etc/passwd in the last field of the line corresponding to the user. It is possible to change the shell during a session by simply executing the corresponding executable file, for example:/bin/bash
 
Tip: To find all available shells in your system type following command:
$ cat /etc/shells

Prompt
      The shell is initialized by reading its overall configuration (in a file of the directory /etc/), followed by reading the user's own configuration (in a hidden file whose name starts with a dot, located in the basic user directory, i.e. /home/user_name/.configuration_file). Then, a prompt is displayed as follows: 

machine:/directory/current$
 
By default, for most shells, the prompt consists of the name of the machine, followed by two points (:), the current directory, then a character indicating the type of user connected:
  • "$" speciies a normal user
  • "#" specifies the administrator, called "root"


Thursday, December 25, 2014

The /etc/passwd File


The file /etc/passwd

                  The file /etc/passwd contains all information regarding the user (login, passwords, etc.). Only the superuser (root) must be able to change it. It is therefore necessary to change the rights of this file so that it can only be ready by the other users.

                  This file has a special format which makes it possible to mark each user, and each of its lines has the following format:

account_name : password : user_number : group_number : comment : directory : start_program

Seven fields are specified separated by the character ":":

    the account name of the user
    the password of the user (encoded, of course)
    the integer identifying the user for the operating system (UID=User ID, user identification)
    the integer identifying the group of the user (GID=Group ID, group identification)
    the comment in which the information on the user or simply its real name can be found
    the connection directory, which is directory which opens upon connection to the system
    the command is the one that is executed after connection to the system (often, this is the command interpreter)
Here is an example of a passwd file:

 It is important to know that the passwords located in this file are encrypted. It is therefore useless to edit and replace the field password by directly typing the password, which would only cause the account to be blocked.

Once a user connects, the login program compares the password typed in by the user (after encrypting it) with the password stored in the passwd file. If they do not match, the connection can not be established. 

UID: (unique) identifier of each user account. Numbers beween 0 and 99 are frequently reserved for the machine's own accounts. Numbers higher than 100 are reserved for user accounts.

GID: group identifier. The default group (called group) has the number 50. This identifier is used in connection with access rights to the files. This question will not concern you if your system has more than one user group. (In that case, you must pay attention to the file /etc/group.

The superuser may not necessarily be called root. To change this, just replace the root account name by the desired name.
A privileged account is an account whose identifier (UID, User ID) is zero.

Your password is stored in /etc/shadow file

Your encrpted password is not stored in /etc/passwd file. It is stored in /etc/shadow file. In the good old days there was no great problem with this general read permission.

 Almost, all modern Linux / UNIX line operating systems use some sort of the shadow password suite, where /etc/passwd has asterisks (*) instead of encrypted passwords, and the encrypted passwords are in /etc/shadow which is readable by the superuser only.

DNF Replace Yum

               The Fedora project has announced that "YUM" will be replaced by "DNF." DNF is currently available in Fedora 20 and is tentatively scheduled to replace Fedora’s package manager Yum entirely by the end of 2014.

                YUM (stands for Yellowdog Updater, Modified) is a free and open-source command-line based utility released under GNU General Public License and is primarily written in Python Programming language. YUM was developed to manage and update RedHat Linux at Duke University, later it got wide recognition and become the package manager of RedHat Enterprise Linux, Fedora, CentOS and other RPM based Linux distribution. It is often called as “Your Package Manager”, unofficially frequently by Linux Professionals.

Short comings of Yum that led to the foundation of DNF:
  1. Dependency resolution of YUM is a nightmare and was resolved in DNF with SUSE library ‘libsolv’ and Python wrapper along with C Hawkey.
  2. YUM don’t have a documented API.
  3. Building new features are difficult.
  4. No support for extensions other than Python.
  5. Lower memory reduction and less automatic synchronization of metadata – a time taking process.
Ale¨ KozumplĂ­k, the developer of DNF project is a RedHat Employee. He says:he has no choice other than forking YUM and develop DNF. The YUM package maintainer were not ready to implement these changes. YUM has about 59000 LOC whereas DNF has 29000 LOC (Lines of Code).

Wednesday, December 24, 2014

Delete files that are X days old


                            Some time in Linux you want to clear out older files in a directory.so here is the command that will delete all files all the files that are older than seven days.

Let us look at the above command

find: This is the command that will search for the files.
/path/to/files :This is the top level directory to start searching.
-type f : This ensures we don't remove directories,but only files.
-mtime +7 : Removes files older than '7' days.Change to '+14' to delete files older than two weeks
-exec : This indicates what to do with the files we found.
rm -rf : Removes the files recursively and forcefully.
{}: This represents each file we find.
\;  : This is the end of the exec

                    You can also create a cron job to automate the process.The below crontab file will execute the above command every night at 2 am and delete all files older than 7 days in the folder.





Sunday, November 9, 2014

UNIX 2038 Bug

                                       
                                      The end of Unix Time will occur on January 19, 2038 03:14:07 GMT.  On January 19, 2038 03:14:08 GMT all computers that still use 32 bit Unix Time will overflow.  This is known as the Year 2038 problem

                                      Unix Time is represented by a 32 bit whole number (an integer) that can be positive or negative (signed).  Unix was originally developed in the 60s and 70s so the "start" of Unix Time was set to January 1st 1970 at midnight GMT (Greenwich Mean Time) - this date/time was assigned the Unix Time value of 0.  This is what is know as the Unix Epoch

                                       While Unix Time begins at 0 on January 1st 1970 it also has a pre-history and an ending.  A 32 bit signed integer can represent whole numbers between -2147483648 and 2147483647.  Since Unix Time starts at 0, negative Unix Time values go back in time from the Epoch and positive numbers go forward in time.  This means that Unix Time spans from Unix Time value of -2147483648 or 20:45:52 GMT on December 13th 1901 to Unix Time value of 2147483647 or 3:14:07 GMT on January 19 in 2038.  These dates represent the beginning, the pre-history and the end of Unix Time

                                       The fix for the Year 2038 problem is to store Unix Time in a 64 bit integer.  This is already underway in most 64 bit Operating Systems but many systems may not be updated by 2038.