• ITVidya.com One Purpose...One Dream...One Vision..One Mision..Your Wealth Creation through Knowledge, Networking and Opportunity

LINUX COMMAND

Linux Basics :
For Linux newbies a quick lesson on every day Linux commands.
Welcome! We meet again. It has been some time now since I've heard you swear at your computer so I assume your Linux installation went well and you have been experimenting with your new system However If you are one of those wanderers who ever so often chance upon random webpages on the net, here you will find a detailed guide to installing Linux.
Now during installation you chose a 'root' password which you used to login when you were prompted for a username and a password for the first time. 'Root' on Linux is the centre of all power. He is the System Administrator who has access to all files and folder and can add or delete users or change their passwords.
Now absolute power can corrupt absolutely. For eg. If you put in a virus infected floppy as Root ,(Not that there are many viruses for Linux, as of now I have come across just two ) the virus might be able to infect all files , since you have access to all of them. Users other than root however have write access to a limited part of the file-system which often excludes crucial library and configuration files thus reducing the risk of damage due to such incidents. So you must create a new user for yourself and when not performing administrative tasks should log in using that username rather than root.
Lets create a new user.
First open the Linux Console which is found on the Panel at the bottom of your screen generally shown by an icon that looks like TV switched off with a black screen. The following commands are to be type in the console, pressing enter after you have entered the full command.
The 'useradd' Command
The general syntax for the useradd command is :
useradd -d home_directory -e expire_date -g initial_group -p password login_name
home_directory : Is the main directory within which the user is expected to story all his files and subdirectories.
For a user named 'foo' the home directory generally is /home/foo
expire_date : This is the date on which the user's account expires and he/she cannot access the computer
anymore unless the account is renewed. This is somewhat similar to your ISP account
expiring in 6 months or one year. The expire date is in yyyy-mm-dd format (2002-08-30)
initial_group : Every user in Linux belongs to a group which affects his file permissions. The initial group
must be a group which already exists.
Password : This will be the user's password to access his account
login_name : This will be the user name with which the user will access his account.
Eg :
useradd -d /home/einstein -e 2002-08-30 -g root -p relativitysucks einstein
creates a user named einstein on my computer.
His home directory is /home/einstein
His expirty date is 30th august 2002
He belongs to the 'root' group
His password is relativitysucks
His username is einstein.
Incase you do not enter one of the parameters group, home, expire or shell they are replaced by their default values. These default values can be viewed using the " useradd -D" command and can also be changed which however we will cover in a later document.
The ls command
The ls command is equivalent of the DOS dir command. It lists the files and subdirectories contained within the present directory.
Some possible flags which can be used with the ls command are :
ls -a
List all files (Some configuration files starting with a dot '.' are otherwise not listed). Often the number of files in a directory is too large to be fitted within one screenfull of data. In such a case we use dir/p for DOS. For linux a similar command is
ls | more
Lists files and directories page after page on keystroke. The above command actually is a combination of two commands. It introduces a new concept called 'Piping'. It is done using the logical OR or | character found just above the Enter key on your keyboard. In Linux it is possible to give the output of one command to another command as an input.The ls command lists files & subdirectories and the more commands divides its input into page length views. Thus piping the ls output to more results in page length views of files and subdirectories.
ls -R

It lists the files and subdirectories of a directory and further lists the contents of each subdirectory recursively. The output of this command is usually large and is best seen when piped through more.
The pwd command
The pwd or the present working directory command gives you the path to the directory in which you presently are. It is used without flags simply as 'pwd'
The su command
Many a times you might have logged in as a normal used and might need to be root to install a software or for some other small task. You could logout then login as root complete the work logout and login back as a normal user. Instead, you can just use the su command. The format is :
su username
eg : su root
when you 'su' to become root from a normal user, you are asked for the root password. But if you are root, you can use 'su' to become any user without using a password. Once your work is finished, use 'exit' to become yourself.
The whoami command
Sorry folks! This command won't solve your teenage identity crisis but it will tell you which user you are logged in as. Useful when you have used 'su' many times and now don't know who you are.
The cp command
This one copies files / directories from one place to another it's syntax is
cp source_file_with_path destination_path
eg : cp /home/aarjav/secret.txt /ftp/pub
This would make all my secrets public :). But my secrets wouldn't fit on my 8.4 Gb hard-disk ;) The cp command can be used with some useful flags also :
cp -i

Interactive copying, prompts before overwriting files or directories
cp -l source_file_with_path destination_path

Makes a link (shortcut) to the source_file at the destination path instead of actually copying it there.
cp -p
Preserve file attributes while copying if possible
cp -R
Copy Recursively . Used when copying directories. This command also copies the contents of the subdirectories.
cp -u
Update i.e. Copy only if the source file is newer than the destination file or the destination file does not exist.
The rm command
The rm command is used to remove or delete files or directories. Its general format is:
rm -flag file_or_directory_with_path
eg : rm /home/aarjav/waste.txt
Some flags which can be used with the rm command are
rm -v file.txt
Remove verbosely, explain what is being done.
rm -r my_directory
Remove the directory and its contents recursively.
The mkdir command
This command is used to create new a new directory. Its syntax is
mkdir -optional_flag directory_name
The possible flags are
mkdir -v directory_name

Tell what is going on.
mkdir -p directory_with_path
This is a cool command. Suppose you need a directory named SEIT within another directory called PVPP in /usr/local and the parent directory PVPP itself does not exist, then you can use :
mkdir -p /usr/local/PVPP/SEIT
This command creates the PVPP directory and the SEIT subdirectory in one go.
The man command
For someone new to linux, the man command is one of the most important commands. The syntax is:
man command_name
Suppose you have not understood fully one of the above commands or want to find out about a new command you have learnt , the man command provides a manual for that command
Thus
man cp
will show you a manual on the cp command and so on.
I think that is enough material to keep you busy for a few hours and get you through some of the elementary tasks in Linux. So farewell friends, until we meet again.

Setting up Squid as your caching HTTP/FTP proxy
By Trevor Warren

Posted: ( 2000-10-23 07:35:41 EST by )

Squid is a proxy caching server for HTTP/FTP requests. It caches data off
the net on your local network. So the next time the same data is being
accessed, whether it is html or a gif, it gets served up from the local
server rather than over the Internet -- saving you significant bandwidth.
Lets use the most commonly available proxy server for Linux and the most
stable one around, Squid. Installing and configuring it is a breeze as
you'll soon find out. To make things simpler I would suggest that you get
the Squid RPM from any of the download on the net for your distro.The
latest Stable release of Squid is squid-2.3.STABLE1-5.i386.rpm. If you are
not able to find it on your distro's CD then i would suggest you try out
www.rpmfind.net. After having downloaded the RPM install it with the
following command.
Assuming you have downloaded the squid-2.3.STABLE1-5.i386.rpm release
the installation command is as follows.
bash# rpm -ivh squid-2.3.STABLE1-5.i386.rpm

And please do note that "bash#" stands for the shell prompt and you do not
need to replicate it in your command.
Having installed Squid successfully, now open the file /etc/squid.conf
using your favorite text editor. Some distributions put this file in
/etc/squid/. This is where it gets interesting and confusing too so read
carefully.
Scroll down till you come to the line

#http_port 3128

This option sets your HTTP proxy port to 3128 which is the default port
that squid runs on. You can uncomment this line and set it to whatever
port you want. It is advisable to avoid port 80 since, if you are running
a Web Server on the Linux machine Apache would be listening on that port.

Scroll down till you come to the line
#cache_mem 8 MB

This option sets a limit on the amount of memory that squid may make use
of to store it's transient and cached objects temporarily in memory. This
limit that you may impose on squid is the soft limit and at any given
point of time Squid may double or triple the size of occupied memory all
depending on the size and the requirement of in-transient cached objects.
Uncomment this line and change the size of your Memory cache from 8 MB to
what ever size you want it too be. Keep in mind the amount of RAM that you
have on your machine when you allocate memory to SQUID. But for your
knowledge this occupancy of the specified Memory Limit is dynamic.
Scroll down until you come to the following lines
# LOGFILE PATHNAMES & CACHE DIRECTORIES
#--------------------------------------------------------------------------
The following options are relative to setting up and tuning your web
cache. So lets get gunning pals. Here the first and most important one.
#cache_dir /var/squid/cache 100 16 256

Isn't this getting a little confusing, one parameter and three values to
it! C'mon let's demystify the whole thing. The values given here are the
values the Squid will use by default. So if the 'cache_dir' option isn't
implicitly mentioned then Squid resolves to maintaining the cache in
/var/squid/cache. Uncomment this option 'cache_dir' if you want to
customize the parameters.
The first parameter '/var/squid/cache' is the path to the cache files. You
may change this to suit whatever you want too, but remember whatever path
you may mention out here make sure that those directories exist because
Squid will never create the directories on it's own. Also a point to be
noted is that the directories should be writable by the Squid process. If
you are a novice and all of this is sounding too geekish then I suggest
you stick to the default values.
The next value '100' is the amount of space in MegaBytes(MB) that Squid
can utilize to store the cache contents. Modify this to whatever you think
is appropriate to suit your needs.
The next value referred to as 'Level-1' is the number of sub-directories
that Squid can create under the current Cache directory. I suggest that
for starters leave this as it is.
The next option is referred to as 'Level-2' is the number of Second Level
directories that Squid can create under each 'Level-1' directory. The
default is fine for the moment.
Scroll down till you come to the line:
# ACCESS CONTROLS
# -----------------------------------------------------------------------------

The following lines define Access Control Lists for your Network. Squid
allows you to define various kinds of ACL's out here. So make it a point
to read this whole section of Access Controls carefully.
In this "ACCESS CONTROLS" section scroll down till you come to the
following lines.
#Default configuration:

http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR
# CLIENTS
#
http_access deny all
What you need to do out here, is to setup your own ACL's (Access Control
Lists), else just comment out the last line as shown above and put the
following line in.
http_access allow all
So now your rule section should look like this.
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR
# CLIENTS
#http_access deny all
http_access allow all
Three cheers and your proxy has been setup. Now you only need to make sure
that Squid starts every time your Linux box boots.
If your using RedHat then you can start in the following manner. Login as
Admin or "su" to root & use the "setup" command. Now enter the System
Services sub menu and enable Squid.
If your using SuSE then start YaST and go to "System Administration", then
go to "Change config File", then scroll down till you come to "START
SQUID" & just enable it from "NO" to "YES".
The next time you reboot your machine your Proxy will start automatically.
Before you start using squid you need to create the swap directories. Do
this by
/usr/sbin/squid -z
This just has to be done the first time.
To start Squid right now use the following command
bash#/etc/rc.d/init.t/squid start
There, you have setup, configured and started your proxy. Just make sure
your client's web browsers have the http proxy port setup as the same port
in your /etc/squid.conf file.

kamlesh7880's picture