Friday, 30 July 2010

A few basic commands in Linux

The common  file system commands that would make a beginner get started with linux are the following:

ls:command that lists all the files in the current directory
Variations in the use of the ls command would be found as the ls -l,ls -t...
cp source dest:command that is used to copy file 'source' to file 'dest'
mv source dest:moves the file 'source' to file'dest'
rm files:command used to remove a particular file
These commands when invoked would be looked in the directory /usr/bin
To check the presence of the 'cp' command use:
which cp
You would get back /usr/bin
There is a case where the use of a paricular command (say cp)would display in a message as follows
bash:cp command not found
Make use of the 'which' command to see if the cp command is present in the directory
which cp
There might be no response
Therefore the coreutil package needs to be reinstalled
apt-get install coreutils --reinstall coreutils
This would fix the problem.
The other basic commands would include the commands for printing the text:
cat filename:
pr filename:

Directories in linux contain files and subdirectories.Each user will be having his own home directory to whih he logs in at the beginning of a session.The user may then move on work in other directories which becomes his current directory.

The basic commands that are used in regard with the directories include the following

mkdir dirname:creates a new directory
cd dirname:change to the particular directory(provided that you are in the correct place)
To check whether you are in the correct place use
pwd
You would get back the 'current directory'
cd ..: is used to go the previous directory.
cd: moves to the home directory.

The shell-Basic facilities offered

Shell -the command interpreter.
There are many basic facilities offered by the shell.They include

1)Using shorthands for files(use of the asterisk '*')
For example the command
pr temp*
would print the contents of all files beginning with 'temp'
Similarly the echo command
echo *
will list all the files in the current directory

2)Input-Output redirection
Consider the case where we want to list the files of the directory but not in the terminal
So we redirect it to a file using the '>' operator
ls > filename
If the file 'filename ' is not already created it will be so,or else it will be overwritten.
Counting the number of lines in a particular directory is done as
ls >filename
wc -l<tfilename



3)Inorder to avoid the creation of a temporary file,PIPES are used for the input-output redirection
The vertical bar '|' is the pipe.
Instead of using
ls>filename
wc -l<filename
we use
ls|wc -l
for the redirection to be possible.

4)Tailoring the environment
As a user of UNIX,we could customize it in the way comfortable to us.
The 'stty' command helps us do that
for eg:
stty erase '^h'
enables the user to use ctrl-h for erasing a particluar character.
By storing it in the file .profile (present in the home directory),we need not type it each time we login
One of the most important tailoring comes during the setting up of paths
Again this could be made changed in the '.profile' file.
The current path would enable searches in the directories /usr/bin and /bin.
If we did want to augment another directory to the search path we do it as follows:
PATH=export $PATH:/usr/games
where usr/games would be the newly added search directory.
The augmented path would be obtained using the 'echo' command
echo $PATH
:/usr/bin:/bin:/usr/games

All these changes could be saved into the file named '.profile'