Monday, August 4, 2008

UNIX console

Logging in

Before we can start we need to login to UNIX. You will be asked for your username and password every time you want to use UNIX. Simply type your username and password to login.

Username: johnny
Password:

Your password will not be printed on the screen when you type it in for safety reasons.

Once you have logged in you will see the command prompt which looks like this:

$

It might also look like this:

#

You are now ready to start entering commands.

Basic UNIX commands

The first command we will learn is whoami. This command will print the name of who you are logged in as. Here is an example:

$who am i
johnny

The passwd command is used to change your password. You might have to enter a password that is at least a certain length and that has both letters and numbers in it.

$passwd
New password:
Confirm password:

You can use the pwd command to print the directory you are currently working in. It should print the path of your home directory at the moment.

$pwd
/home/johnny

The ls command lists the files in the current directory.

$ls
documents/
first.ksh
hello.c

A wildcard (*) can be used with ls to print any files starting or ending with certain letters.

$ls *.c
hello.c

To see hidden files and directories you must use ls -a.

$ls -a
.mail/
documents/
first.ksh
hello.c

Anything that follows a command with a hyphen(-) in front of it is called a switch. Switches are a way of making a command do more things or do things in a different way. Entering any command with the --help switch usually gives you a list of switches for that command.

You know that an item on a file list is a directory if it is followed by a forward-slash(/). Some people will find that on the UNIX they are using the directories are not followed by a forward-slash.

The ll command does a long listing of your files. Some people will not be able to use the ll command on their UNIX. If you do not have ll then you must use ls -l.

$ll
OR
$ls -l

drwxr-x--- 1 johnny users Jan 10 12:01 documents/
-rwxr--r-- 1 johnny users Feb 11 13:12 first.ksh
-rw-r--r-- 1 johnny users Mar 12 14:23 hello.c

You can use more than one switch at a time in the following 2 ways:

$ls -l -a
OR
$ls -la

drwxr-xr-x 9 johnny users 4096 Oct 17 20:45 ./
drwxr-xr-x 3 root root 4096 Sep 27 16:43 ../
drwxr-x--- 1 johnny users Dec 25 23:59 .mail/
drwxr-x--- 1 johnny users Jan 10 12:01 documents/
-rwxr--r-- 1 johnny users Feb 11 13:12 first.ksh
-rw-r--r-- 1 johnny users Mar 12 14:23 hello.c

The mkdir command creates a new directory. You must also type the name of the directory you want to create.

$mkdir newdir

You will not get a message telling you that the directory was created. If you do get a message then it will be an error message from typing the command in wrong. Use the ll or ls -l command to see if your new directory has been created.

$ll
OR
$ls -l

drwxr-x--- 1 johnny users Jan 10 12:01 documents/
drwxr-x--- 1 johnny users Apr 1 1:23 newdir/
-rwxr--r-- 1 johnny users Feb 11 13:12 first.ksh
-rw-r--r-- 1 johnny users Mar 12 14:23 hello.c

You can change to another directory using the cd command.

$cd newdir

You can use the pwd command to see that you are now in the new directory.

$pwd
/home/johnny/newdir

You can go up a directory by changing to that directory or by using cd ..

$cd /home/johnny
OR
$cd ..
$pwd

/home/johnny

Now we can delete the directory using the rmdir command.

$rmdir newdir
$ls

documents/
first.ksh
hello.c

You can use the touch command to create a new, empty file.

$touch myfile.txt
$ls

documents/
first.ksh
hello.c
myfile.txt

The rm command is used to delete a file.

$rm myfile.txt
$ls

documents/
first.ksh
hello.c

The mv command is used to move files. Create a file called move.txt and a directory called new/ and then move move.txt to new/ like this:

$touch move.txt
$mkdir new
$mv move.txt new/
$ls new

move.txt

The ls command was used in the above example to print the contents of new/ without changing to the directory.

You can't normally delete a directory without emptying it first. rm is usually used for deleting files and not directories but if you use it with the -rf switches it will delete a directory and all of its contents.

$rm -rf new

mv can also be used to rename files.

$touch file1.txt
$mv file1.txt file2.txt
$ls

documents/
first.ksh
file2.txt
hello.c

The man command is one of the most important commands. You can use the man command to read the manual of any command. Here is and example of getting help for the ls command:

$man ls

This opens up the manual page for ls and tells you everything you want to know about it. When you are finished you must press "q" to go back to the command prompt.

File permissions

File permissions determine if a user is allowed to access a file. We must first look at a long file listing to understand file permissions.

drwxr-x--- 1 johnny users Jan 10 12:01 documents/
-rwxr--r-- 1 johnny users Feb 11 13:12 first.ksh
-rw-r--r-- 1 johnny users Mar 12 14:23 hello.c

The first part of the long listing tells you if the item is a file or a directory and the file permissions. The first "d" in the following example means the item is a directory. A hyphen(-) means that an item is a file.

drwxr-x---

The rest of the first part is made up of 3 sections which are owner, group and others. The letters show what access writes users have for the file.

u g o
d|rwx|r--|r--|

u - Owner
g - Group
o - Others
a - All(ugo)

r - Read
w - Write
x - Execute

We can use the chmod command to change file permissions. The following example gives the group execute rights:

$chmod g+x first.ksh

You can change more than one permsission on a file like this:

$chmod u-rwx first.ksh

Sunday, August 3, 2008

privacy policy

unix-ads.blogspot.com Privacy Statement

What follows is the Privacy Statement for all unix-ads.blogspot.com websites (a.k.a. blogs) including all the websites run under the unix-ads.blogspot.com domain.

Please read this statement regarding our blogs. If you have questions please ask us via our contact form.

Email Addresses

You may choose to add your email address to our contact list via the forms on our websites. We agree that we will never share you email with any third party and that we will remove your email at your request. We don’t currently send advertising via email, but in the future our email may contain advertisements and we may send dedicated email messages from our advertisers without revealing your email addresses to them. If you have any problem removing your email address please contact us via our contact form.

Ownership of Information

unix-ads.blogspot.com is the sole owner of any information collected on our websites.

Comments/Message Boards

unix-ads.blogspot.com websites contain comment sections (a.k.a. message boards). We do not actively monitor these comments and the information on them is for entertainment purposes only. If we are alerted to something we deem inappropriate in any way, we may delete it at our discretion. We use email validation on most of our message boards in order to reduce “comment spam.” These email addresses will not be shared with any third party.

Cookies

Currently we assign cookies to our readers in order to save their preferences. This data is not shared with any third party. Accessing our websites is not dependent on accepting cookies and all major browsers allow you to disable cookies if you wish.

Third Party Cookies

Many of our advertisers use cookies in order to determine the number of times you have seen an advertisement. This is done to limit the number times you are shown the same advertisement. unix-ads.blogspot.com does not have access to this data.

Traffic Reports

Our industry-standard traffic reporting records IP addresses, Internet service provider information, referrer strings, browser types and the date and time pages are loaded. We use this information in the aggregate only to provide traffic statistics to advertisers and to figure out which features and editorials are most popular.

Legal proceedings

We will make every effort to preserve user privacy but unix-ads.blogspot.com may need to disclose information when required by law.

Business Transitions

If unix-ads.blogspot.com is acquired by or merges with another firm, the assets of our websites, including personal information, will likely be transferred to the new firm.

Links

unix-ads.blogspot.com websites frequently link to other websites. We are not responsible for the content or business practices of these websites. When you leave our websites we encourage you to read the destination site’s privacy policy. This privacy statement applies solely to information collected by unix-ads.blogspot.com

Notification of Changes

When unix-ads.blogspot.com makes changes to this privacy policy we will post those changes here.

Contact Information

If you have any questions regarding our privacy policy, please contact us. halimyanuar@yahoo.com