Friday, November 9, 2012

What is .profile file in Linux


.profile is file containing commands that is executed automatically every time user logs in to the system. it may contain any Linux command including some system parameter initialization, setting alias,     exporting some variables etc.

.profile is basically to set user environment in Linux, each user can have their own .profile file located at users /home directory, globally it is located as /etc/profile.To see .profile file you can go to "/home/username"  directory , type "ls -a" (to list all files including hidden file) and then cat .profile.

example of .profile:


PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/ccs/bin:.
MAIL=/var/mail/$LOGNAME 
MANPATH=/usr/share/man:/usr/local/man 
PRINTER=printer1 
umask 022 
export PATH MAIL NNTPSERVER MANPATH PRINTER 
set -o vi
alias myw= cd /home/username/workdir/

Sunday, October 28, 2012

Command Redirection and Pipeing in linux


Unix/Linux command normally takes input from keyboard and display output to computer screen. something while doing some complex scripting or admin tasks, need arises to take input from a file or take input from some other command and output to a file.here is where we resort to command redirection and piping in Linux command.

  • Character ">" is used to redirect output of command to a file, if file already exist replace it.

          ls -l > Outputfile.txt

          To append the output to a existing file we can use “>>”

           date >> Outputfile.txt

  •  Character “<” is used to pass input from a file to a command


           grep “myword” < Imputfile.txt

  •   To redirect standard error to a file using “2>”


           Mycommand 2> errorfile.txt

  • We can also direct one command’s output to another command by using character “|” (pipe).


           ls -l | grep “myword” | sort -r

 In the above example firsts requests a “ls –l” command is being redirected using “|” pipe to                          “grep myword” command to search the "myword" from previous command output and ultimately      output is redirected to “sort -r” command to sort the result.

Saturday, October 27, 2012

How to change date in Linux?


Changing date in Linux is very simple, we can you use "date" command with date specified in particular format. we can do this in two ways.
1. using "date --set" or "date -s" command.
    date --set "8 April 2008 20:42:45"
    or 
    date -s "7 April 2008 20:42:45"

2. simply "date MMDDhhmmYYYY.ss" command. 
     date 070821442012.34
    Format: "MM DD hh mm YYYY ss" stands for 
    MM = month = 07
    DD = day = 08
    hh = hour = 21
    mm = minute = 44
    YYYY = year = 2012
    ss = second = 34

Thursday, October 25, 2012

What is Shell?


Computer understands the language of 0's and 1's called binary language. Every operating system kernel has inbuilt routine which communicate with system hardware in binary language.At the heart of UNIX based system is a kernel whose routines aren't easy to understand and use.

 The ‘shell’ is the interface between the user and the system.it is a user program or it is an environment provided for user interaction, it is a command language interpreter that executes commands read from the standard input device such as keyboard or from a file. The shell isn't only a command line interpreter that understands wildcards; it’s also a language with variables, arrays, functions and control structures. Command lines can be put into a file and executed. the shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.

 Several shells are available for Linux based system including:

• BASH ( Bourne-Again SHell ) - Most common shell in Linux. It's Open Source.
• CSH (C SHell) - The C shell's syntax and usage are very similar to the C programming language.
• KSH (Korn SHell) - Created by David Korn at AT & T Bell Labs. The Korn Shell also was the base for the POSIX Shell standard specifications.
• TCSH - It is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).

Please note that each shell does the same job, but each understands different command syntax and provides different built-in functions. Under MS-DOS, the shell name is COMMAND.COM which is also used for the same purpose, but it is by far not as powerful as our Linux Shells are!

Note: To find all available shells in your system type following command:

$ cat /etc/shells


Any of the above shell reads command from user (via Keyboard or Mouse) and tells Linux Os what users want. If we are giving commands from keyboard it is called command line interface ( Usually in-front of $ prompt, This prompt is depend upon your shell and Environment that you set or by your System Administrator, therefore you may get different prompt ).

Note: To find your current shell type following command

$ echo $SHELL


Note: Linux/Unix is a Case Sensitive, you have to write command in proper case.

Thursday, October 11, 2012

About Blog

I am a programmer by profession and do scripting regularly to make our job easy. you should be handy in scripting languages if you are in information technology field.to start scripting on any operating system we must be handy with basic commands of that particular operating system, we will discuss the commands specific to to Linux based Operating system.  this is how i started scripting out of my curiosity and requirement in workplace; I studied the basics first and then the knowledge sharing by some good scripters over the internet made me somehow comfortable in shell language; thanks to google and expert post over the internet!!

Here i am going to follow same thing, just share whatever i have learnt and may be someone who is new in this get assistance.

                                                         
 *******Good Luck*******