A Few Shell Commands

Shell is a program running between the kernel and the user. The users are actually communicating with the shell not with the kernel.

Here are a few shell commands:

Filename shorthand

  • * – pattern matches any string of characters.

eg: wc ch1.*

  • ? – pattern matches any single character.

eg: ls -l ch?.1

  • […] – pattern matches any of the characters inside the bracket.

eg: pr ch[12345]*

To avoid special meaning of *, ?, etc.., we have to use single quotes. i.e. ls ‘?’

Output redirection

ls >filethe output is redirected to the file named file.

>> adds the output to the end of the file whereas > replaces the old file.

Input redirection

sort <temp – sorts the content of the file temp.

Pipes

If we want to redirect the output of a program to the input of another without creation of a temporary file we can use pipes(|).

who|sort – print sorted list of users.

Two programs could be run with one command by separating them with a semicolon(;).

date;who

Processes

To run a program in the background and return to the terminal can be done using an ‘&‘.

wc ch* >wc.out &

We can continue running a program even if we logout using the command ‘nohup’.

nohup command &

To start a process at some hour of a day we can use the command ‘at’

at 3am <file

Others

stty erase ‘^h’ –   makes control h equivalent to backspace.

PS1=’hai :’ –  makes the prompt appear as hai :

We can use variables for abbreviations of very long directory name. Add a name like

d=/shinu/frequent/directory

in our profile i.e. .profile file in the login directory. Now we can use the abbreviation as

cd $d

To find the login directory we can use the command pwd.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 10, 2010, in GNU/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: