Академический Документы
Профессиональный Документы
Культура Документы
Utilities
init , the first process created during boot, is responsible for activating the
daemons. init makes use of the files: rc and rc.local
init /etc/rc
cron /var/spool/cron/crontabs
at /var/spool/cron/at*
% at 1:00
at> tar cvf /dev/rst8
% at 13:07
at> batchfile
% at 0815 Jan 24
at> who_is_on > who_was
% at now+1 day
at> make_proj big-project-file
% at 5 pm Friday
at> echo Backup for `date` started
at> backup_files all
-s Standard (Bourne) shell (sh) is used to execute the job. By default, the
SHELL environment variable determines which shell to use.
Doesn’t exist on some systems.
-e Puts users into an editor, where they can edit their file
/var/spool/cron/crontabs/username
-l (list) Displays the user’s file, if it exists.
-r (remove) Removes the user’s file.
-d -d instead of –r on some systems.
crontab -e
Addition/deletion of lines
in the private database
:wq /var/spool/cron/crontabs/user
Structure of the crontab file collection of lines:
minutes hours day-of-month month day-of-week
command
© Amplify Mindware Pvt. Ltd
crontab – cont’d
Field Format Example Meaning
Number 0 12 1 1 * new_year Will run at 12:00 on New
Year
Asterisk 30 * * * 1 MonProg Will run hourly, on the half
hour, on Mondays
set of numbers 0 0 * 4,6,9,11 * prog2 Will run daily at 00:00 in
months with 30 days
range of 0 8-16 * * * users Will run throughout work
numbers hours, on the hour
As in all compilers in UNIX, the default name of the execution file created by
compilation is a.out.
The compiler generally operates on files with the extension “.c”. cc can also be
run on assembler files (extension “.s”) and on object files (extension “.o”).
Options:
-o file Changes the name of the execution file created from a.out to file.
-O Optimized compilation.
-g Creates a symbol table for debugging.
-c Skips stage ld in the compilation. This option is used to compile
program modules. The output is a file of the same name with the
extension “.o”.
After the command is executed, the new user can work at the terminal, but the
working environment remains unchanged.
The shell (csh/sh) run for the new user is not a login shell, and therefore the
.login (.profile) file is not executed. The .cshrc file (in the case of the
csh) is executed.
su prompts the new user for a password as if login was being performed.
%su - username
Executes a full user substitution including running the login file.
% su -f username
[On some systems: % su username –f ]
Does not execute the .cshrc file for csh.
% su username -c command
Switches to a new user in order to execute the command. Then returns to the
original user.
On some systems - If the group wheel in the file /etc/group does not contain
an empty list, only the users listed there are permitted to execute su to root,
even if unlisted users know the root password.
Exercise:
Try executing su to user root. Were you prompted to enter the root
password?
Type the command exit in the new user shell. The user terminates the
shell and reverts to the first user.
suspend suspends the shell of the new user without killing the process.
Recall that suspend is equivalent to Ctrl-z for the new user's shell.
cmp
This command compares two files, byte by byte, and reports the first occurrence
of a different byte.
This command can be used for comparing binary files.
Option:
% cmp -l f1 f2
Gives all the differences between the files. The output includes the ordinal
number of each byte that is different and the octal value of the bytes that
are different.
% cmp -l f1 f2
13 146 163
14 151 145
15 162 143
16 163 157
17 164 156
18 40 144
19 146 40
20 151 146
21 154 151
22 145 154
23 56 145
24 12 56
cmp: EOF on f1
%
By default, the command reports about the three above groups in three
columns.
Options:
% comm -1 f1 f2
Drop column 1 from the output (lines in the first file only).
% comm -12 f1 f2
Display column 3 only (lines in both files).
The output is the different lines and the change required to make the files
identical.
% diff f1 f2
Compares files f1 f2.
% diff d1 d2
Compares files of the same name in subdirectories d1 d2.
This command opens a new file named typescript, in which anything appearing on
the screen will be saved.
% script filename
Replaces typescript with filename
% script -a [filename]
Append anything displayed on the screen to the existing typescript file.
A calculator that uses a simple C-like “language” for calculating and interpreting
expressions.
Examples:
23*(90+78.88)
3884.24
sqrt(90)
9.4868...
s(3.14)
0.00159
a=e(c(0.25))
a
2.635
© Amplify Mindware Pvt. Ltd
bc – cont’d
Additional structures:
define, for, while, if
Command description
Command name
in the manual
The section in the
manual containing
the command
The command whatis is used when we know the command we want to check -
unlike cases when we do not remember the exact name (in which case we use
the command
man -k copy).
% who
joanne ttyp0 Sep 12 13:09 (212.32.122.11)
sujin ttyp1 Sep 12 07:40 (62.33.26.130.myISP1.net)
eddie ttyp2 Sep 12 12:43 (62.33.26.132.myISP1.net)
anna ttyp3 Sep 12 09:02 (anna)
jerry ttyp4 Sep 12 08:57 (localhost.locald)
benny ttyp5 Sep 12 10:52 (indy5:0.0)
ho ttyp6 Sep 12 11:22 (star.com)
kareem ttyp7 Sep 12 11:47 (aloha)
yitzy ttyp9 Sep 12 14:17 (minney)
whoami display the user name that opened the current shell.
%id
uid=279(alon) gid=104(eng)
groups=104(eng),42(sela),114(database),123(mahonadm),
134(commando)
Answer
Find file system which occupied the most disk space. The result should be a single
line showing the status of this file system.
Answer
Answer
Answer
5. Display all the lines which have five characters or more in a given file; try your
solution on file less_than_five .
Answer
Answer
Answer
Following this, display a list of files located in one of the directories, ex_dir2 and
test-dir but not in both.
Answer
9. Create a list of files in a given directory tree which have not been modified
during the last 7 days. Test your solution on the directory /etc.
Answer
Write a command which finds all the files from your home directory down which
were accessed during the last 7 days, and displays their content on the screen.
Answer
Answer
Answer
Answer
13. Write a list of commands that will display only the digits from the output of the
command date.
Answer
14. Write a list of commands that will print information about all of your sub-
directories, and count them.
Answer
csh stores a list of variables, at all times, which can be referred to and
used.
There are some variables with predefined names, which fulfill specific
functions.
Examples:
% set name = Yitzy
% echo $name
Yitzy
% set names = ( Yitzy Alon )
% echo $names
Yitzy Alon
Exercise:
Assign a list of values to a variable without using parenthesis and
see what you© get.
Amplify Mindware Pvt. Ltd
Variable Substitution
The $ sign preceding a variable name causes the csh to replace the
variable name with its content.
The $# signs preceding a variable name causes the shell to replace the
variable with the number of elements in the variable.
% set names = ( iris victor )
% echo $#names
2
Indexing Options:
$var[index] The value in the index entry.
$var[-index] The values up to the index entry.
$var[from-] The values from the index entry.
$var[from–to] The values between from and to.
Examples:
% set a = (a b c d e f)
% echo $a[2]
b
% echo $a[-2]
a b
% echo $a[4-6]
d e f
© Amplify Mindware Pvt. Ltd
Delimiting Variable Names: { }
Using curly brackets { }
% set prefix = X
% cat ${prefix}files
The truth is out there … somewhere!
Exercise:
Run the previous commands in your ~/class directory without the
{} brackets and see what you get. Explain what you see!!
A list of all the defined variables and their values are obtained by means of the
command set.
Important examples:
Example:
ksh
Example:
$ ls *.o
The command ls does not know the meaning of the “*o” argument.
The shell interprets the “*.o” to be the list of files that end with “.o”,
and passes this list as arguments to the ls command.
Asterisk *
Matches all strings (including an empty string)
Question mark ?
Matches one character only
Squared brackets [ ]
Matches on character of the set in brackets.
$ ls
xy ab abcbcx abcx
abx acx xaabby xaby
$ ls x*(ab)y
xy xaby
$ ls x+(ab)y
xaby xababy
$ ls a*([bc])x
abx acx abcx abcbcx
$ echo *a
a aba abba
$ echo *aa
*aa
Standard output redirected to a file by means of > (creates a new file) and >>
(appends to a file):
This is an irreversible action. In order to avoid such behavior use the following
command:
$ set –o noclobber
$ set +o noclobber
The HISTFILE variable contains the name of the file (by default .sh_history).
In order to edit / execute the N last commands users can user the fc command:
$ fc <# First Command> <# Last Command>
This command will open the standard editor window (depending on the variable
FCEDIT). When quitting the editor, all the commands currently displayed in the
editor window will be executed.
Edit mode vi – edit the line as in the vi editor. <esc> key, move to
escape-mode. In escape mode, the line up/down keys (k, j) move
through the history.
Edit mode emacs – edit the line as in the emacs editor, the line
up/down keys (Ctrl-p , Ctrl-n) move through the history.
Syntax:
alias <name>=<command>
For example:
alias h=history
alias ll=“ls –l”
Find all file names which a lower case letter between two upper case
letters.
History:
Set the variable HISTSIZE with the number of the last command you want
to save.
Set the HISTFILE to .my_sh_history
Display your previous typed commands.