Posts Tagged ‘basic unix commands’

Shell Scripting Commands for beginners – Part 1

July 16th, 2010

I’m presently working on Solaris Sun server and hence I needed to use unix shell scripting commands for working on it. I went through various tutorials and gained some knowledge about it and now I’m writing the commands with example for your reference. Let me know if you have any query.

What is Shell Scripting?

A shell is a command interpreter turns text that you type (at the command line) in to actions runs a program, allows you to edit a command line and can establish alternative sources of input and destinations for output for programs.

Unix uses shells to accept commands given by the user, there are quite a few different shells available. The most commonly used shells are SH(Bourne SHell), CSH(C SHell) and KSH(Korn SHell), most of the other shells you encounter will be variants of these shells and will share the same syntax, KSH is based on SH and so is BASH(Bourne again shell). TCSH(Extended C SHell) is based on CSH.

Basic Unix Commands:

1)      ls : Lists all the files and folders in the current directory.

-a    Lists all entries, including those that begin  with  a dot (.), which are normally not listed.

-i    For each file, prints the i-node number in  the  first column of the report.

-l    Lists in long format,  giving  mode,  ACL  indication,  number of links, owner, group, size in bytes, and time of last modification for each file (see above). If the file  is  a  special file, the size field instead contains the major and minor device numbers. If the  time of  last  modification is greater than six months ago, it is shown in the format `month date  year’  for  the POSIX  locale. When the LC_TIME locale category is not set to the POSIX locale, a  different  format  of  the time  field  may  be  used.  Files modified within six months show `month date time’. If the file is  a  symbolic  link,  the filename is printed followed by “->” and the path name of the referenced file.

Eg: ls –a | ls –l etc.,

2)      mkdir: Creating a new directory in the current directory.

Eg: mkdir ajay -> Will create a new directory named “ajay”.

3)      grep: Search a keyword in the current context.

Eg: ls –l |grep “ajay”

Here we are listing all the files in the current directory and searching whether any file or directory has the name “ajay”. “|” (pipeline symbol) is used to combine both the commands together.

4)      echo: Print the variable.

Eg: echo “ajay” or echo ajay

This will print ‘ajay’ in the next line and will return to the next line for getting next command.

5)      cd: Change directory. Used for changing from current directory to some other directory.

cd .. – used for going back to the previous directory.

cd <directory_name> – moves to the directory mentioned if it is present inside the  current directory.

Eg: cd ajay

This will move the control to the directory named “ajay”.

P.S. Enough for the day. Will get you more commands in the coming posts.

Share this post:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter
  • Add to favorites
  • email
  • Yahoo! Buzz