Comments

Sunday, August 19, 2012

UNIX and SHELL Scripting : General Purpose Commands

Posted by on Sunday, August 19, 2012 Read our previous post
As everyone is aware of UNIX nowadays thanks to UBUNTU, which has made this platform very popular.

In this post we won't be learning about UNIX or its architecture but what we will be learning are the General Purpose Commands required for UNIX and SHELL Scripting.

UNIX has a lot of commands which perform different functions, and also it has different types of SHELLS like BASH, KORN SHELL. All the shells in unix has some or the other limitation on commands.

So we are considering our shell as BASH, as we all work in BASH shell normally.

GENERAL PURPOSE COMMANDS



* Display the manual pages for any command


The first and foremost important command is the man command. The man command helps as to display the manual of any command i.e. it formats and displays online manual pages.

Example :

$ man cat

The above command will display the manual page for cat command.

Therefore the basic syntax for man  command is :

$ man <command>

To force display all the pages, we can use :


$ man -a cat

* Display the List of Files and Directories



The command used to display the list of files and directories is ls.

$ ls -a 
$ ls -l
$ ls -t

The above are some variants of ls. The first command will help you to display the hidden files. The 2nd command will help you to display long listing i.e. it will show the permission on file, owner, last modified date and the last one  will help you to display the files in sorted order (sorting is done by Last Modification Time).


* Create and Remove Directory



These command come handy while writing scripts as we may require creating a directory and remove after it has been used.

To create a directory we use mkdir and to remove one we use rmdir. But the directory can only be removed if and only if it is empty.

SYNTAX

$ mkdir <directory_name1>,<directory_name2>....<directory_nameN>
$ rmdir <directory_name1>,<directory_name2>....<directory_nameN>

* Move around in the File System



Like in DOS Prompt we use cd to switch from one directory to another, here in UNIX we also use cd.

cd ~ : will take you to the home directory.

© 2010 Code 2 Learn