How to configure the user environment?
set, unset
.cshrc - configuration file for csh or tcsh
.profile - configuration file for sh or bash
set - set environment variable
env, printenv - show environment variables
unset "name" - unset variable
hostname - print name of the current host system
set HOST = `hostname` - set variable HOST
source "file" - execute other comands from "file"
Home directory
setenv HOME /home/mary - set home directory
echo $VAR - show the variable VAR
echo $HOME - show the variable HOME
set TEST = "$HOME/test" - set variable TEST
Command cd - change directory
cd ~ ( = cd ) - go to the home directory
cd ~/dirname - go to subdirectory /dirname in the home directory
i.e. cd $HOME/dirname
cd ~username - go to the home directory of specified user
pwd ( = "dirs -l" ) - print the full pathname of the current directory
pwd is the Bourne shell built-in command and there is
analogous command dirs in C-shell
Set prompt
prompt - C shell prompt
set prompt = "%/ ! %"
%/ is replaced by current directory
! is replaced by current event
% is printed "as is"
Set path
set path = ($PATH /usr/local /usr/etc )
setenv path ${PATH}:/opt/sybase
- add new path
rehash - evaluate the internal hash table
echo $path ( or $PATH ) - show variable PATH
Redirection and Pipe
> - redirect output
>> - append to file
< - redirect input
| - pipe output
stdin - standard input
stdout - standard ouput
stderr - standard error
ls -l | more - pipe for two commands
i.e. stdout of ls is stdin for more
ls -a > file1 - redirect the ls stdout to the file "file1"
ls -l *.c >> file1 - append the ls stdout to the file "file1"
cat /etc/xxx >& file1 - redirect the cat stderr to the "file1" ( C shell )
cat /etc/yyy >>& file2 - append the cat stderr to the "file2" ( C shell )
command < infile > outfile
- get input from infile and redirect output to outfile
Change Permission and Ownership
chmod - change the permission mode of a file
chgrp - change file group ownership
chown - change file ownership
Example:
A) Start status: owner = "rafael" and group = "other"
readable and writable for owner,
readable for group and others
# ls -l xxx
-rw-r--r-- 1 rafael other 59 Nov 25 13:08 xxx
B) Change owner of file xxx to "daps"
# chown daps xxx
# ls -l xxx
-rw-r--r-- 1 daps other 59 Nov 25 13:08 xxx
C) Change group of file xxx to "daps"
# chgrp daps xxx
# ls -l xxx
-rw-r--r-- 1 daps daps 59 Nov 25 13:08 xxx
D) Change back owner to "rafael"
# chown rafael xxx
# ls -l xxx
rw-r--r-- 1 rafael daps 59 Nov 25 13:08 xxx
E) To be "xxx" executable
# chmod +x xxx
# ls -l xxx
-rwxr-xr-x 1 rafael daps 59 Nov 25 13:08 xxx
chmod digit parameters
user: r - 400 group: r - 40 other: r - 4
w - 200 w - 20 w - 2
x - 100 x - 10 x - 1
chmod 777 file - read-write-execute permission for all
chmod 751 file
- read-write-execute permission by owner(7),
read-execute permission by group(5),
execute only permission by others(1).
A forth digit may precede the sequence "XXX"
chmod 1777 file - "1" means to set sticky bit
Who
u - user ( owner )
g - group
o - other
a - all ( default )
chmod a+r file - add read permission for all
chmod u+wx file - add write-execute permission for user
chmod a-wx,a+r file - remove write-execute permission for all
and read permission for all
grep - search a file for a pattern
Search one or more files for lines match a regular expression
grep "pattern" *.c - search "pattern" in all files *.c
grep -i "pattern" *.h - ignore upper/lower case
grep -i "own" *.c | grep -v "down" - all lines except pattern "down"
grep -n "pattern" "file" - precede each line by its line number
grep -c "pattern" *.c - print only a count of lines
grep "pattern" f1 f2 f3 - search in files f1, f2, f3
grep "patern" *.c | more - display grep output by more
ls -l | grep "pattern" - ls output is the input for grep
Ambiguity
The command
grep [A-D]* vers[1-2]
could be interpreted by the shell as
grep Atlas.c Big.c Check.c vers1 vers2
and would the try to find the pattern Atlas.c
in files Big.c, Check.c, vers1, vers2
To avoid ambiguity - use quotes:
grep "[A-D]*" vers[1-2]
Metacharacters in match examples
voice - string "voice"
^voice - string "voice" at beginning of line
grep "^voice" *.c - search the string "voice" at beginning of line
fax$ - string "fax" at the end of line
grep "fax$" *.c - search the string "fax" at the end of line
^.....$ - any line containing exactly 5 characters
man | fax | wine - search one of words "man", "fax" or "wine"
Command egrep
Command egrep supports the special regular expression
that aren't supplied by grep, such as +, ?, | and ()
egrep "l(ist|ast)" *.c
- search "list" or "last"
Multi processing and multi users
ps -ef - display all processes
ps - display all processes for current user
kill "pid" - kill process with ID "pid" ( Process ID )
kill -9 "pid" - kill process by force
whoami - Who is current user ?
finger - display all users are in system
^Z - suspend the current foreground job
bg - runs the current job in the backround
fg - brings the current job in to foreground
jobs - display the bg jobs from current shell
Superuser - user with username "root"
su - become super-user or another user
su - - The default user name is root ( super user )
/var/adm/sulog - Log all attempts to become another user
su "username" - login as a new user with old environment
su - "username" - login a new user with new environment
rlogin "hostname" -l "username"
- login in the other workstation
passwd - change login password
The new password is entered twice
Each password must contain 2 alphabetic chars and
at least numeric or special character.
Each password must differ from the user login name
The password must differ from old by 3 chars
/etc/default/passwd contains a variable PASSLENGTH
For example, PASSLENGTH = 6 - minimum length of each password
/etc/passwd - password configuration file
Pattern line from this file:
rafael:x:108:100:My comments:/export/home/rafael:/bin/tcsh
where:
108 - group number,
100 - user number
/export/home/rafael- home directory that user login with
/bin/tcsh - shell that user login with
yppasswd - change login password if Yellow Pages are used in the system
useradd - administer a new user login on the system
useradd -c "Tests" -d /export/home/rafael -g 108 -u 100 -s /bin/tcsh "login_name"
where:
-c "Tests" - comment
-d /export/home/rafael
- home directory
-g 100 - group number 100
-s - Full pathname of the program used as the user’s shell
Hosts and Services
/etc/hosts - local database of hosts and IP addresses
Pattern lines from this file:
140.1.120.5 dbs
140.1.120.1 router
ftp dbs - instead of "ftp 140.1.120.5"
rlogin dbs - instead of "rlogin 140.1.120.5"
/etc/services - information regarding each service available
through the Internet ( port/protocol)
Examples:
ftp 21/tcp - this ftp port is the constant for all world
telnet 23/tcp - this telnet port is the constant for all world
Boot and Shutdown
stop + "A" ( i.e. type button STOP and A simultaneously)
- stop UNIX work
go - continue UNIX work
boot - start the system kernel
reboot - restart the operating system
Don’t turn off UNIX machine without shutdown!
shutdown -y -g0 -i5
- shutdown the UNIX
Only superuser available to do shutdown!
[Home]
[Five UNIX Tips]
[Tip 1 - File system and UNIX shell]
[Tip 3 - UNIX windows]
[Tip 4 - NFS protocol and shareable systems]
[Tip 5 - More about file system]
[UNIX vendors, Home Pages, Workstations, FAQs, News Groups]
Maintained by Rafael Stekolshchik
Last updated: July 4, 1998
klivlend1@yahoo.com
This page hosted by
Get your own Free Home Page