MCSP044 Project Specification Jul 2018 Jan 2019
MCSP044 Project Specification Jul 2018 Jan 2019
o m
o t .c
s p
lo g
e . b
s it
o u
i g n
SESSION 1:
o m
filename1 filename2 --- moves a file (i.e. gives it a different name, or
•
moves it into a different directory (see below).
cp filename1 filename2 --- copies a file
o t .c
•
s p
rm filename --- removes a file. It is wise to use the option rm -i, which
lo g
will ask you for confirmation before actually deleting anything. You
can make this your default by making an alias in your .cshrc file.
•
. b
diff filename1 filename2 --- compares files, and shows where they
e
differ
s it
•
o u
wc filename --- tells you how many lines, words, and characters
there are in a file
i
•
g nchmod options filename --- lets you change the read, write, and
execute permissions on your files. The default is that only you can
look at them and change them, but you may sometimes want to
change these permissions. For example, chmod o+r filename will
make the file readable for everyone, and chmod o-r filename will
make it unreadable for others again. Note that for someone to be able
to actually look at the file the directories it is in need to be at least
executable.
• File Compression
o gzip filename --- compresses files, so that they take up much
less space. Usually text files compress to about half their
original size, but it depends very much on the size of the file
and the nature of the contents. There are other tools for this
purpose, too (e.g. compress), but gzip usually gives the
• printing
o lpr filename --- print. Use the -P option to specify the printer
name if you want to use a printer other than your default printer.
For example, if you want to print double-sided, use 'lpr -Pvalkyr-
d', or if you're at CSLI, you may want to use 'lpr -Pcord115-d'.
m
See 'help printers' for more information about printers and their
o
locations.
t .c
o lpq --- check out the printer queue, e.g. to get the number
o
p
needed for removal, or to see how many other files will be
s
lo g
printed before yours will come out
o lprm jobnumber --- remove something from the printer queue.
. b
You can find the job number by using lpq. Theoretically you also
e
s it
have to specify a printer name, but this isn't necessary as long
as you use your default printer in the department.
o u
o genscript --- converts plain text files into postscript for printing,
Finding things
• ff --- find files anywhere on the system. This can be extremely useful
if you've forgotten in which directory you put a file, but do remember
the name. In fact, if you use ff -p you don't even need the full name,
just the beginning. This can also be useful for finding other things on
the system, e.g. documentation.
• grep string filename(s) --- looks for the string in the files. This can
be useful a lot of purposes, e.g. finding the right file among many,
m
figuring out which is the right version of something, and even doing
o
t .c
serious corpus work. grep comes in several varieties (grep, egrep,
and fgrep) and has a lot of very flexible options. Check out the man
o
pages if this sounds good to you.
s p
•
lo g
write username --- lets you exchange one-line messages with
another user
e . b
it
• elm --- lets you send e-mail messages to people around the world
u s
(and, of course, read them). It's not the only mailer you can use, but
the one we recommend. See the elm page, and find out about the
n o
departmental mailing lists (which you can also find in
i g /user/linguistics/helpfile).
• whoami --- returns your username. Sounds useless, but isn't. You
may need to find out who it is who forgot to log out somewhere, and
make sure *you* have logged out.
• finger & .plan files
of course you can finger yourself, too. That can be useful e.g. as a
quick check whether you got new mail. Try to create a useful .plan file
soon. Look at other people's .plan files for ideas. The file needs to be
readable for everyone in order to be visible through 'finger'. Do
'chmod a+r .plan' if necessary. You should realize that this
o m
kill some X processes before you can start them again. These will
t .c
show only when you use ps -efl, because they're root processes.
o
kill PID --- kills (ends) the processes with the ID you gave. This works
p
•
g s
only for your own processes, of course. Get the ID by using ps. If the
process doesn't 'die' properly, use the option -9. But attempt without
b lo
that option first, because it doesn't give the process a chance to finish
.
it e
possibly important business before dying. You may need to kill
processes for example if your modem connection was interrupted and
u s
you didn't get logged out properly, which sometimes happens.
•
n o
quota -v --- show what your disk quota is (i.e. how much space you
i g have to store files), how much you're actually using, and in case
you've exceeded your quota (which you'll be given an automatic
warning about by the system) how much time you have left to sort
them out (by deleting or gzipping some, or moving them to your own
computer).
• du filename --- shows the disk usage of the files and directories in
filename (without argument the current directory is used). du -s gives
only a total.
• last yourusername --- lists your last logins. Can be a useful memory
aid for when you were where, how long you've been working for, and
keeping track of your phonebill if you're making a non-local phonecall
for dialling in.
% mkdir Student
. b
working Directory is Student, to change to the subdirectory Subdirectory1:
e
s it
% cd Subdirectory1
o u
i g n
5) Display Calender for the current Month.
To display Calender for the current month use the CAL command.
% CAL
To get the Directory listing of the parent directory, use the command
ls - list contents of directory.
Goto the parent directory and use ls command.
% ls
To see all the other users that are currently connected to system simply use
the following command who. This will simply print out a list of all the users
connected (just their usernames however, not their real names), the
terminal they're connected to, when they connected and where they
connected from.
% who
However to quickly see roughly what the other users of the system are up
to use the following command: % w
This will show a top line which contains the date, how long the systems
been running, how many users are on and whats called the “load average”
which is how many processes are contending for the CPU. This is shown
o m
as three numbers: the first is for 1 minute ago, the second 5 minutes ago,
t .c
the third 15. All you really need to know is that small numbers are good
here.
o
s p
g
After this w will show a header that says what the columns are for,
lo
e . b
username, tty, when that user logged in, how long they've been idle, the
JCPU and the PCPU and finally what the process is. JCPU is the total CPU
it
time used by all the processes attached to that terminal, the PCPU time is
s
u
just for the current process running in the foreground. Quite often these two
o
i n
numbers will be the same. Knowing exactly what these numbers mean or
g
how to use them isn't really essential knowledge, but can prove useful or
interesting.
SESSION 2:
m
11). Change your directory to the directory exercises. Create a file
o
.c
called example1 using the cat command containing the following text:
o t
Water, water everywhere
And all the boards did shrink;
s p
Water, water everywhere,
lo g
No drop to drink.
e . b
s it
Assuming that there is a directory called exercises,
u
To change to directory exercises from the current working directory, use the
o
i g n
CD command:
% cd exercises
% man finger
e . b
% ps
s it
u
And you will see a list that probably just includes your shell (tcsh). While
o
i n
this is fairly useful in and of itself you'll often find that you're logged in to two
g
or three TTYs at once doing various things, and so you'll need to find out
more than just the processes running on that login.
To see a list of all your running processes use:
% ps -U $USER
This will show you information about your processes with much more
information including the UID, PID, PPID, TTY and the command line and
all its arguments used to start the command.
If you wanted to know this about another user you could simply use:
% ps -fu username
Lastly if you want ps to show you information about all the processes
running on the system then you need to -e flag:
% ps -e
Most of time this isn't really needed, but sometimes you will want to be able
to find out information like this. It should also be noted that the -e flag can
be combined with the -f flag, to show all the processes on the machine and
full information about them.
o m
To find and list text files in the all the directories, use the FIND command:
it
error messages (arising from errors such as not being able to read the
s
u
contents of directories for which the user does not have the right
o
i g n
permissions).
Another way to find and list text files in the current directory is to use the
LOCATE command:
% locate ".txt"
will find all filenames in the file system that contain ".txt" anywhere in their
full paths.
Another option to find and list text files in the current directory is:
% ls -l *.txt ls
To copy any text file to another text file use the cp command:
o m
working directory and calls it file2.
o t .c
cp file1 file2 is the command which makes a copy of file1 in the current
s p
First CD to your current directory:
lo g
% cd ~/Student
e . b
Then, copy the text file,
s it
o u
% cp /unix/examples/copy.txt.
i g n
(Note: Don't forget the dot (.) at the end. Remember, in UNIX, the dot
means the current directory.)
ELSE
% cp file1 file2.
% rm file.txt
% lpr filename.txt
lpr
lpr queues the specified file for printing. If no file is specified, it reads
from the standard input. Options that may be specified include printer,
number of copies, processing and post-processing option.
lpq
The lpq program lists the job in the print queue.
o m
lprm
o t .c
The command lprm may be used to remove a print job from queue.
s p
The command options include the printer and job-id or user-name. If
lpc
lo g
the user-name is specified all jobs for that user will be dequeued.
. b
The command lpc is normally used interactively. It allows the super-
e
it
user to start/stop the daemons, enable/disable queuing or printing
s
o u
jobs, and monitor the status of a printer. The subcommand help prints
a short list of the commands that may be entered.
i g n
19) Send message to another user on your UNIX system, and get them
to reply.
The mail command enables the user to send and receive electronic mail
messages to and from users on both the Unix system and remote users.
To send a message to a user on your system, type:
% mail username
The cursor will move to the next line, and you will get a Subject: prompt.
You can now type in the subject of your message, and then press
<RETURN>. The cursor will go to the start of the next line and there will be
no prompt. You now type in the text of your message. Terminate each line
with <RETURN>. When you have finished the text of the message, type an
end-of-file character (usually ^D), or a full-stop character.
e . b
s it
UNIX uses two mailboxes to hold mail messages
u
system mailbox (/usr/spool/mail/)
o
i g n user mail box (..../.../mbox)
Mail arrives in the system mailbox, and is saved in your user mail box after
you have read it. The user mail box is normally located in their $HOME
directory
To save a current mail message to a file other than the default mailbox, use
the command save:
% s file name
When the mail program starts, it uses the default mail folder, which is the
system mailbox. Remember the save mail message command, which
saved the mail message to a file.
It was stated that the mail program treats this file as a mail folder.
% mail [email protected]
23) Try to move to the home directory of someone else in your group.
There are several ways to do this, and you may find that you are not
permitted to enter certain directories. See what files they have, and
what the file permissions are.
o m
o t
To move to the home directory of someone else in the group: .c
s p
% cd ~ user1
lo g
e . b
To list the files in the directory and their permissions:
s it
u
% ls –ldg
o
i g n
24) Try to copy a file from another user's directory to your own.
Before trying to copy the file, see the permissions that have been set for a
file, use the ls command with -l option
% ls –l
If the –r permission is set in the group’s option of the permission set, and
then the file can be copied.
Assuming –r to be set,
To copy a file from another users directory to home directory of current
user:
25) Set permissions on all of your files and directories to those that
you want. You may want to give read permission on some of your files
and directories to members of your group.
o m
read --> permission to view, print and copy -->
o t .c
abbreviated r
write -->
p
permission to change the contents -->
s
abbreviated w
lo g
execute --> permission to run an executable file --> abbreviated x
(for example, a program) OR
e . b
permission to change into a directory
s it
u
When setting file/directory permissions, Unix divides the world of users into
o
i g n
three classes:
Unix is not capable of permitting files and directories to individual users, but
(as explained below) files and directories are usually permitted so that
others cannot access them without knowing their absolute pathnames.
To see the permissions that have been set for a file, use the ls command
with -l option.
% ls -l
-rw-r----- 1 Student users 21 Jul 5 11:08 file1
The first 10 characters of the above line describe the type of the file and the
permissions which have been set for it.
o m
characters each. These 3 sets show the
t .c
permissions for the owner, the group and
o
others. Within each set, permissions are always
s p
described in the same order: read (r), write (w)
g
and execute (x). If the relevant letter (r, w or x)
lo
e . b
appears, permission exists. If a - (dash)
appears in its place, that kind of permission is
s it denied.
o u
i g n
Let's look at the permissions for another file:
o m
o t .c
s p
lo g
e b
This may be understood as follows:
.
Class Action Permission
o u (owner)
i g n g Group
o Others
- remove
permission
= set permission
w write
x execute
a all
where class, action and permission can be chosen from the table of options
at the right above.
More than one class and more than one type of permission can be set at
the same time using chmod. For example,
chmod u+x,o=rw file1
adds the execute permission for the owner (u) and sets the permission for
others to read and write explicitly (no matter what permissions others had
before).
If you do not specify a class, the new permission is applied to all three
classes. For example,
o t .c
For example, the command
s p
chmod 751 file1
lo g
e . b
would change the permission for file1 to read, write and execute for the
owner; read and execute for the group; and execute only for others. Values
s it
and the permissions they correspond to are shown below:
o u
i g n Value Permission
7 Rwx
Explanation
read, write and execute
6 rw- read and write
5 r-x read and execute
4 r-- Read
3 -wx write and execute
2 -w- Write
1 --x Execute
0 --- no access whatsoever
o
can change into a directory with the cd command or pass through am
directory as part of a search path.
o t .c
s p
When you permit a file, you will also need to give execute permission
g
to both your home directory and any subdirectories between your
lo
e . b
home directory and the file. When you do this, other users will not be able
to list the contents of these directories, but they will be able to read or copy
it
the file as long as they know the absolute pathname.
s
u
For example, user Student wants to give others permission to read and
o
i n
copy his file outline in subdirectory project1 in his home directory. To do
g
this, he would type the following commands:
chmod o=x /home/Student
chmod o=x /home/Student/project1
chmod o=r /home/Student/project1/outline
Since execute permission does not allow others to see the contents of his
directories, Student must tell his colleagues the absolute pathname of the
file, which is
/home/Student/project1/outline
% mkdir /Student/Subdirectory1
% mkdir /Student/Subdirectory2
% mkdir /Student/Subdirectory3
First determine the current directory using the pwd(print working directory)
command:
o m
% pwd
/home/Student
o t .c
s p
g
Within our home directory (Student), there are several files and a
lo
e . b
subdirectory which also contains files (see diagram):
Within our home directory (Student), there are several files and a
it
subdirectory which also contains files (see diagram):
s
u
It is possible that more than one person could have a file called
o
i n
bibliography. How does Unix distinguish
g
between files with the same name? The full name of each file includes the
"path" through the directory hierarchy to that file.
The full names of two different bibliography files might be:
% /home/Student/project1/bibliography and
% /home/Ignou/thesis/bibliography
The names of the two bibliography files shown above are absolute
pathnames. An absolute pathname starts with a / to represent the root
directory, then traces the path through various subdirectories to the file.
Another way to describe a file is by its relative pathname. Relative
pathnames do not begin with a /. A relative pathname shows how to get to
the file from the current working directory. If we are in the directory Student,
the relative pathname to our file bibliography is
% project1/bibliography
o
using any abbreviations, we would need to type (all on one line):m
cp /home/Student/project1/bibliography
/home/Student/project1/chapter3/data
o t .c
s p
Using the abbreviation for our home directory (~) and the abbreviation for
g
the current working directory (.) we would type only:
lo
cp ~/project1/bibliography .
e . b
s it
u
27) Try using wildcards (“*” and possibly “?”).
o
i g n
UNIX allows you to use wildcards (more formally known as metacharacters)
to stand for one or more characters in a filename.
The two basic wildcard characters are ? and *. The wildcard ? Matches any
one character. The wildcard * matches any grouping of zero or more
characters.
Assume that your directory contains the following files:
Chap bite
Chap6 it
Lit site
big snit
bin test.new
bin.old test.old
bit
Lit bit
lists only the files Lit and bit. The file snit was not listed because it has two
characters before "it". The file it was not listed because it has no characters
before "it".
The ? wildcard may be used more than once in a command. For example,
ls ?i?
o
characters, except that it will not match a period that is the first character of
a name.
s p
ls *it
lo g
Lit bit it snit
e . b
it
Using this wildcard finds all the files with "it" as the last two characters of
s
u
the name (although it would not have found a file called .bit).
o
i n
We could use this wildcard to remove all files in the directory whose names
g
begin with "test". The command to do this is
rm test*
Be careful when using the * wildcard, especially with the rm command. If
you had mistyped this command by adding a space between test and *,
Unix would look first for a file called test, remove it if found, and then
proceed to remove all the files in the directory!
Matching a range of characters with [ ]
The ? wildcard matches any one character. To restrict the matching to a
particular character or range of characters, use square brackets [ ] to
include a list. For example, to list files ending in "ite", and beginning with
only "a", "b", "c", or "d" we would use the command:
ls [abcd]ite
o m
The method described in the previous section matches a single character
t .c
or range of characters. It is also possible to match a particular string by
o
enclosing the string in { } (braces). For example, to list only the files ending
in the string "old", we would use
s p
ls *{old}
lo g
bin.old test.old
e . b
it
To list all files ending in either "old" or "new", use
s
ls *{old,new}
o u
i g n
bin.old test.new test.old
28) Put a list of the files in your directory into a file called filelist. (then
delete it!)
29) Create a text file containing a small story, and then use the spell
program to check the spelling of the words in the file.
30) Redirect the output of the spell program to the file called errors.
% spell story > errors
o m
SESSION 4: o t .c
s p
lo g
31) Type the command ls –l and examine the format of the output.
. b
Pipe the output of the command ls –l to the word count program wc,
e
s it
to obtain a count of the number of files in your directory.
The WC command is used to print the number of lines, words, and
o u
characters in a file. Syntax: wc [options] filename
i g n
To find the number of files in a directory, enter
% ls -l | wc –l
ls –l : For a long listing that shows file protections, size, and date
32) Use cut to strip away the reference material and leave just the text
field.
Cut command is typically used to extract a certain range of characters from
a line, usually from a file.
Syntax: % cut [-b] [-c] [-f list] [-n] [-d delim] [-s] [file]
-b
Bytes; a list following -b specifies a range of bytes which will be returned,
e.g. Flags which may be used include
t
Used in combination with -b suppresses splits of multi-byte characters
o
-d
s p
lo g
Delimiter; the character immediately following the -d option is the field
delimiter for use in conjunction with the -f option; the default delimiter
. b
is tab. Space and other characters with special meanings within the
e
s
necessary. it
context of the shell in use must be enquoted or escaped as
-s
o u
i g n Used to bypass lines, which contain no field delimiters when -f is
specified, unless otherwise indicated.
file
The file used (and accompanying path if necessary) to process as
input. If no file is specified then standard input will be used
33) Use tr to strip away any tags that are actually in the text(e.g.,
attached to the words), so that you are left with just the words.
The tr command (translate characters) is one of the true Unix filters. It
copies its standard input to its standard output, while replacing the first
character specified on the command line with the second character
specified.
34) Set a file to be read-only with the chmod (from change mode)
command. Interpret the file permissions displayed by the ls –l
command.
Consider file1 to be present,
To set the file to be read-only to all,
% chmod a+r file1
To see the permissions of the file, use the ls –l command. To see the
permissions of the entire directory use the ls –ld command.
35) Delete one or more directories with the rmdir command. See what
o m
happens if the directory is not empty. Experiment (carefully!!) with the
t
rm –r command to delete the directory and its content.
o .c
First let’s go to home directory of user Student: cd ~Student
s
Let us create a directory /Student/Directory2 p
% mkdir /Student/Directory2
lo g
e . b
If the Directory 2 is not empty, then we get an error message:
Directory2: Directory not empty.
it
To remove the directory and all its files and contents:
s
u
%rm –r Directory2
o
i g n
36) Experiment with the re-directing command output (e.g., ls –l >
file1). Try “>>” instead of “>” with an existing text file as the output.
To "redirect" output -- to take what the system would have displayed on the
screen and put it in a file instead.
On issuing the ls –l command, we can redirect the output to file1, as:
% ls –l >file1
When you redirect output to a file that already exists, any previous contents
are deleted before the command is completed. To prevent the accidental
overwriting of files, first issue the command:
set noclobber
then use % ls –l > file1
o m
t .c
37) See whether upper-case versions of any of these commands will
work as well as the lower-case versions.
o
s p
UNIX is *ALWAYS* case-sensitive.
lo g
e .
be told "command not found." b
If you want to list your files with the `ls' command, if you enter LS you will
s it
o u
i n
38) Use the who command to see users logged into the system.
g
% who lists all users currently logged into the system. if you want to list
your files with the `ls' command, if you enter LS you will be told "command
not found."
The general format for output is:
where:
comment
Comment line in inittab (4)
o m
t
39) Pipe the output of the who command to the sort command.
o .c
UNIX sort command to sort data
s p
lo g
either alphabetically or numerically (-n option)
b
•
•
e .
in ascending or descending order (-r -- sort in reverse option)
s it
By default sort sorts the file in ascending order using the entire line
o u
as a sorting key.
i g n
The sort command can be used in pipes or have its output redirected as
desired.
To pipe the output of the who command to the input of the sort command:
40) Search for your login name in whofile (file1) using the grep
command.
The grep command search for the pattern specified by the Pattern
parameter and writes each matching line to standard output. The grep
command displays the name of the file containing the matched line if you
specify more than one name in the File parameter. Characters with special
To find a word within some text, display all lines matching "pattern1",
SESSION: 5
41) Compare two text files with the diff command.
o m
The diff command is used to display two files and prints the lines that are
o t .c
different. It prints a message that uses ed-like notation (a for append, c for
change, and d for delete) to describe how a set of lines has changed. This
s p
is followed by the lines themselves. The < character precedes lines from
lo g
the first file and > precedes lines from the second file. The diff command
displays the only line that differs between the two files.
e . b
s it
Let's create an example to explain the output produced by diff. Look at the
contents of three sample files:
o u
i g n
test1 test2
apples apples oranges
test3
When you run diff on test1 and test2, the following output is produced:
The "wc" command stands for "word count". It counts the number of
characters, words, and lines that are contained in a text stream.
wc /etc/passwd
This command tells you the number of characters, words, and lines in the
/etc/passwd file.
wc -l /etc/passwd
This command tells you the number of lines (only) in the /etc/passwd file.
wc -w MyStory
o m
t .c
This command counts the number of words in the file named MyStory
o
p
(which can be useful if you're paid by the word!).
s
who | wc -l
lo g
. b
This command counts the number of users logged into your computer
e
it
system. The output of the who command is piped into the wc command,
s
u
which counts the number of lines in the who output.
o
i g n
ps -e | wc -l
% printenv | less
o m
the variable's value, not its name, to be used. You can also use ${NAME},
which avoids confusion when concatenated with text
o t .c
s p
lo g
44) Concatenate all files in a directory redirected to /dev/null and
. b
redirecting standard error to “error file”.
e
s it
To concatenate files in Unix use the cat command.
o u
i
*
n
% cat *> /dev/null/errorfile
o t .c
This generally means that the home directory containing
s p
the file must have the other-users-execute bit set (o+x).
lo g
% finger –s
e . b
To see other users: % finger username@domain
it
To see details in less/more than one page % finger
s
u
username@domain |less/more
o
i g n
46) If you wish, experiment with the sending and receiving mail using
the pine email program.
Pine is an easy to use, character based mail client. It supports full screen
editing of messages, binary attachments (such as GIF or ZIP files), and
other advanced message system features that were not possible using
older electronic mail clients.
Features of pine:
• Full Screen Capabilities
• Safety for New Users – confirmation of actions.
• On-Line Help
Using PINE:
1. Type pine at the UNIX prompt and you will see the pine screen.
2. Enter user name and password.
3. To compose mail, Use the compose command C - COMPOSE
MESSAGE to compose a message. After composing, to send the
m
mail, use Ctrl+X to send your message. Can you see the choice ^X
o
.c
Send in the menu bar at the bottom of the screen.
t
4. To see the mails you have received use the L - LIST FOLDERS
o
s p
command from the main menu to see your folders and choose the
INBOX folder. Use N - NextMsg to read the next message or P -
lo g
PrevMsg to read previous message.
. b
5. To reply use the R - Reply command, and to forward mail use the F
e
it
- Forward command.
mails.
u s
6. You can use the D - Delete command to delete your unwanted
n o
7. If you want to print (or read the message you want to print, then
47) Delete all files in the current directory whose name ends in “.bak”
To remove all files with the .bak extension, without asking for
confirmation
%rm -f *.bak
e . b
The command ex is used to invoke the editor. The format of this command
is:
s it
u
% ex [filename]
o
i n
The p command (for 'print') used to display lines in the file. The format of
g
this command is:
:[line_range] p
If no range is supplied the current line is displayed.
Pressing <RETURN> is equivalent to moving on to and displaying the next
line. With small files it is possible to display the entire file by pressing
<RETURN> until the end of the file is reached.
Line Ranges
Ranges of lines that can be given to edit commands include:
Absolute line number
6 refers to line 6
1,6 refers to lines 1 to 6
Relative line numbers
-2 refers to 2 lines before the current line
49) Count how many lines contain the word science in a word file
science.txt.
First find the word using the grep command and then pie it using the wc
commandb
% grep science science.txt | wc –l
o m
o t .c
50) List the statistics of the largest file(only the largest file) in the
current directory.
s p
lo g
e . b
One line script to find the largest file in the current directory is:
it
find . -type f -print | xargs ls -ladtr | cut -c34- | sort -n -r | head <1>
s
o u
i n
Note:
g
a) The above code should be executed in one line
(i.e. ignore word wrap)
SESSION: 6
o m
This command will kill all of your processes including your current log
in. The next time you log in, everything that was running or was
locked up will have terminated.
To run the process in background:
o t .c
•
s p
Suspend the process using Ctrl+Z, This suspends execution of the
lo g
process, and gives you a command line.
•
e . b
To move the suspended process to the background, type bg. The
it
process then resumes execution, exactly as if you had typed & when
u s
starting the process.
To later bring a background process back into the foreground, use
o
•
e.g:
Using ps to view what processes are running, this will give you the following
output:
53) List all users from etc/passwd in the alphabetically sorted order.
To list all users on a Unix system, even the ones who are not logged in,
look at the /etc/password file.
To see in detail, about all the users do: $ cat /etc/passwd
o m
t .c
to just see the Unix user names, use the command "$ cat /etc/passwd |
cut -d: -f1|sort
o
s p
lo g
54) Create a file with duplicate records and delete duplicate records
for that file.
e . b
s it
To delete duplicate files:
u
On a single line (you can copy-paste this directly to a shell):
o
i n
OUTF=rem-duplicates.sh; echo "#! /bin/sh" > $OUTF; find "$@" -type f -
g
print0 | xargs -0 -n1 md5sum | sort --key=1,32 | uniq -w 32 -d --all-
repeated=separate | sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-
])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF; chmod a+x $OUTF; ls -l $OUTF
Shell Script :
OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -print0 |
xargs -0 -n1 md5sum |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate |
sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >>
$OUTF;
Explanation:
1. write output script header
2. list all files recursively under current directory
3. escape all the potentially dangerous characters with xargs
4. calculate MD5 sums
5. find duplicate sums
6. strip off MD5 sums and leave only file names
7. escape strange characters from the filenames
8. write out commented-out delete commands
9. make the output script writable and ls -l it
o m
To create a duplicate copy of the file:
$ cp filename1 filename2
o t .c
s p
To remove the duplicate copy:
lo g
e . b
55) Use the “grep” command to search the file example1 for the
s it
occurances of the string “water”
o u
i g n $ grep water example1
-- Create table
create table TEACHER
(
T_NO VARCHAR2(3) not null,
F_NAME VARCHAR2(50),
L_NAME VARCHAR2(25),
SALARY NUMBER,
SUPERVISIOR VARCHAR2(3),
JOININGDATE DATE,
BIRTHDATE DATE,
o
-- Create/Recreate primary, unique and foreign key constraints m
alter table TEACHER
add constraint TEACHER_PK primary key (T_NO)
o t .c
using index
s p
tablespace SYSTEM
lo g
pctfree 10
initrans 2
e . b
maxtrans 255
s it
storage
o u
i
(
g n
initial 64K
minextents 1
maxextents unlimited
);
-- Create table
create table CLA
(
CLASS_NO VARCHAR2(3) not null,
T_NO VARCHAR2(3),
g initial 64K
minextents 1
maxextents unlimited
);
-- Create/Recreate primary, unique and foreign key constraints
alter table PAYSCALE
add constraint PAYSCALE_PK primary key (GRADE)
using index
tablespace SYSTEM
pctfree 10
initrans 2
maxtrans 255
Table: Teacher
t_no, f_name, l_name, salary, supervisor, joiningdate, birthdate, title
Table: Class
class_no, t_no, room_no
Table: Payscale
o m
min_limit, max_limit, grade
o t .c
s p
lo g
e . b
s it
o u
i g n
Exercise 1:
a)
Select *
from teacher
where birthdate = (select max (birthdate) from teacher);
b)
Select *
c)
Select *
from teacher
where join_date > ’10-jul-1995’
and salary in (select salary from teacher where joining date < ’10-jul-1995’;
e)
Select t.*
from teacher t, payscale s
where t.salary between s.min_limit
and s.max_limit
and s.grade = ’B’;
o m
f)
o t .c
Select t.*
s p
from teacher t , payscale s
lo g
e . b
where exists (select * from class c where t.t_no = c.t_no)
and (t.salary between s.min_limit and s.max_limit) and t.grade=C’;
s it
g)
o u
i n
Select *
g
from teacher
where supervisor =’YES’;
i)
Select t.*, c.*
from teacher t, class c
where t.t_no=c.t_no
and c.class_no between 1 and 5;
Exercise 2:
a)
Create view supervisor_details
as
select t_no, supervisior from teacher;
b)
Create index class_index on class(t_no) ;
o m
c)
o t .c
alter view supervisor_details
s p
as
lo g
e . b
select * from teacher where supervisior=’YES’;
d)
s it
select *
o u
i g n
from teacher
where to_char(joiningdate,'yyyy')+15 > to_char(sysdate,'yyyy');
e)
create TGT view
as
select * from teacher t where t.salary >=12000 and t.title=’TGT’;
f)
drop view TGT ;
g)
create index teacher_index on teacher(f_name);
i)
create view teacher_info
as
select t_no, f_name, salary, grade
from teacher t, payscale s
where t.salary between s.min_limit and s.max_limit and s.grade = ’B’;
o m
Exercise 3:
o t .c
s p
a) create or replace procedure EX3A(TNO in out varchar2, bonus out float)
is
sal integer;
lo g
e . b
it
begin
select salary into sal from teacher where t_no = UPPER(tno);
u s
o
if sal > 10000 then bonus := sal * 0.10;
n
elsif sal >10000 and sal <20000 then bonus := sal * 0.20;
g
elsif sal >20000 and sal <25000 then bonus := sal * 0.25;
i
elsif sal >25000 then bonus := sal * 0.30;
end if;
end EX3A;
begin
select count(1) into teacher_count from teacher t where t.salary = 20000;
end;
declare
cursor sel_tea is select * from teacher t where t.salary = 20000;
begin
if not sel_tea%isopen then
open sel_tea;
end if;
loop
fetch sel_tea into sel_tea_rec;
exit when sel_tea%notfound;
update teacher
set inc = sel_tea_rec.salary * 0.50
where t_no = sel_tea_rec.t_no;
end loop;
end if;
end;
close sel_tea;
o m
end EX3C;
o t .c
s p
lo g
e . b
s it
o u
i g n