UNIX Development Environment
The Basic Knowledge
The General Command
Unix Shell
Makefile
The Basic Knowledg
Unix/Linux systems are multi-user and multi-tasking
Have multiple users on the same system
Run multiple programs, seemingly simultaneously
Maintain permissions that determine which users have access to which files and programs
Regulate the amount of disk space each user can use
Store user-specific settings in “hidden” files
Login In
When you first connect to one of the Unix computers you will see the prompt
Login
At the login: prompt, type in your username
Password
Once you have typed in your username you will be prompted to type in your password.
Initialization Files
When you login the Unix/Linux program finally, starts up a command “shell”
Users do not deal with the operating, system directly. Most of your interaction with a Unix system takes place in a shell, a program that is run every time you log in, and displays the “$” prompt. The shell is known as a command interpreter, you give it commands, and it runs them.
Shell
Sh: Bourne Shell
Ksh: Korn Shell
Csh: C shell based on C language
Tcsh: another version of C shell
Using the System
Finally you are logged in! You will see a prompt like one of the following:
$/#
Just waiting for you to type something. We will use $ to indicate the computer’s “ready” prompt.
Okay, let’s try a simple command
$ ls
Ls is the program to list files in a directory, Just plain ls won’t list hidden files(files whose names start with”.”, like login). Now trying
$ ls –a
Cd
Use cd to change your directory to the /bin directory. Type:
$ cd /bin
%pwd
Which prints your current(“or “working”) directory
Using the On-line Man Pages
Most Unix commands have very short and sometimes cryptic names like ls. This can make remembering them difficult. Fortunately there are on-line manual pages which allow you to display information on a specific program (to list all the flags of ls, for example) or list all the information available on a certain topic
Man
Pwd(print working directory)
To fined out which directory you are in type
%pwd
This will show you the full path to your current working directory
Relative to the root directory(/)
Rm(remove files or directories)
The command rm file will remove the specified file.
Some useful options for rm include
%rm –i(interactive mode – you will be prompted to confirm file deletion)
%rm –f(force remove- overrides interative mode and removes file without a prompt)
%rm –r(recursive –remove the contents of directories recursively)
Cp(copy files and directories)
To copy a file, do
% cp oldfilename newfilename
Or to copy a afiel to a new directory, while keeping the old filename d
% cp filename direcotryname/
To ensure you don’t overwrite any existing files you can use the ‘-I’ option:
% cp –I oldfilename newfilename
This command will prompt you to confirm if there is already a file with the name newfile
Mv(move files)
This command allows you to rename a file as in:
% mv filename directoryname/
A with cp, it si a good idea to use the ‘-I’ option with mv, so you don’t mistakenly overwrite your existing files.
The special directory
You may have noticed when you typed ls –a that there were listings dot(.) and not-dot(..). These represent your current working directory (.) and it’s parent directory(..)
For example, typing:
% cd ..
% cd.
% cp /vol/emamples/tutorial/secience.txt .
% cd ~will always bring you back to your home directory
% cd ~/homework will bring you to the ‘homework’ directory
Display the contents of a file on the screen
Clear(clear screen)
Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood.
At the prompt, type
% clear
This will clear all text and leave you with the % prompt at the top of the window.
Cat(concatenate)
The command cat can be used to display the contents of a file on the screen. Type
% cat scienct.txt
As you can see, the file is longer than tan the size of window, so it scrolls past making it unreadable.
Less
The command less writes the contents of a file onto the screen a page at a time. Type
% less science.txt
Press the [space-bar] if you want to see another page, type [q] if you want to quit reading.
Head
The head command writes the first ten lines of a file to the screen
First clear the screen then type
% head science.txt
Tail
The tail command writes the last ten lines of a file to screen Clear the screen and type
% tail science.txt
Searching the contents of a file
Simple searching using less
Using less, you can search though a text file for a keyword(pattern)
For example, to search thought science.txt for the word ‘science’, type
% less scince.txt
Then, still in less(i.e. don’t press[q] to quit), type a forward slash[/] followed by word to search.
/scinence
As you can see, less finds and highlights the keyword, Type[n] to search for the next occurrence of the word.
Greep
It searches files for specified words or patterns, First clear the screen then type.
% greep science science.txt
As you can see, grep has printed out each line containg the word science.
Try typing
% grep Scinece science.txt
The grep command is case sensitive; it distinguishes between Science and science.
To ignore upper/lower case distinctions, use the –I option, i.e. type
% grep –I science science.txt
To search for phrase or pattern, you must enclose it in single quotes. For example to search for spinning top, type
% grep –I ‘spinning to’ science.txt
Some of the other options of grep are:
-v display those lines that do Not match
-n precede each matching line with the line number
-c print only the total count of matched lines
Don’t forget, you can use more than one option at a time, for example, the number of lines without the words science or Science is
% grep –ivc science science.txt
Wc(word count)
A handy little utility is the wc command, short ofr word count, to do a word count on science.txt,type
% wc –w science.txt
To find out how many lines the file has, type
% wc –l science.txt
Redirecting the output
We use the > symbol to redirect the output of a command. For example, to create a file called list1 containing a list of fruit, type
% cat > list1
Then type in the names of some fruit. Press[Return] after each one.
Pear
Banana
Apple
^D(Control D to stop)
What happens is the cat command reads the standard input(the keyboard) and the > redirects the output, which normally goes to the screen, into a file called list1
To read the contencts of the files, type
% cat list1
The form >> appends standard output to a file. So to add more items to the file list1, type
% cat >> list1
Then type in the names of more fruit
Peach
Grape
Orange
^D(Control D to stop)
To read the contents of the file, type
% cat list1
Create another file called list2 containing the following fruit: orange, plum, mango, grapefruit.
We will now use the cat command to join(concatenate) list1 and list2 into a new file called biglist, Type
What this is doing is reading the contents of list1 and list2 in turn, then outputting the text to the file biglist
To read the contents of the new file, type
% cat biglist