Professional Documents
Culture Documents
Basic Unix I
Basic Unix I
Basic Unix I
Syllabus
Part 1 What is UNIX? Your first UNIX Session The UNIX File System Data Streams More Commands The Shells UNIX Security Policy vi Editor Part 2 Multi-Tasking System Management Devices E-mail Networking X-Windows NetBatch & CSD Revision Control
What is UNIX?
UNIX is
an operating system that is:
Interactive (not batch) Multiprocess Threaded (multi-processor) Multi-user Multi-purpose Open source Secure Networked Portable (Linux Laptop)
Today UNIX interfaces with Windows and shares files through software like Samba, VNC, & Exceed.
The Kernel
Kernel Drivers
Hardware
File System
Kernel
Network
Utilities
Hierarchical file system Data Streams: STDIN, STDOUT, STDERR, pipes, redirection, filter Shell sh, csh, Security login, passwd, permissions, groups Built-in mail system Network File System (NFS) Network Information System (NIS/YP) Domain Name System (DNS) X-windows
Quiz
Logging In
Login into a workstation, computer server, via: telnet, rlogin, rsh, ssh Enter username & password at login prompt Username will be visible Password will NOT be visible
Login Examples
% % % % % telnet pgli0003 rlogin pglw8019 rsh pghc0002 rsh insite.fm.intel.com -l ewee ssh insite.fm.intel.com
Remote Access
ssh pglc8010
A substitute for rsh is called ssh; which encrypts all information between the SSH client and server
xhost +
Bring up X Windows
Most UNIX workstations are not with GUI Use runx command to bring up the X windows Windows managers: fvwm2, fvwm95, twm, Default windows manager MYEC provides is fvwm2 fvwm2 environment startup file is $HOME/.fvwm2rc
Change password
Change your password at your first login after you received your account though mail or voicemail. If you havent, do it NOW. Make your UNIX password strong with 6 to 8 characters which combine with alpha-numeric + special characters ($ % ^ @ # ; : > <) no space
/usr/intel/bin/chpasswd
Lab
How?
1. 2. 3.
4.
Quiz
How do you change your password ? Who can see your password ? Who can change/reset your password ? How do you bring up X windows if its not GUI login prompt?
/usr
/include
/tmp
/bin
/mail
/var
/spool /mqueue
File System is a mounted disk space or partition available on the HDD. File systems are arranged like tree hierarchy branches.
A UNIX file
Has no length limit and any combination of alpha-numeric Cannot have ; as this is a separator at the command line Can be a device name
A UNIX directory
Is stacked by hierarchy tree pwd to display current directory Absolute path is the full pathname of the directory within the file system
All files with a . in front is invisible using ls command without a option. Your primary dot files - .login, .cshrc Some have .aliases which is sourced in .cshrc
Quiz
Describe the UNIX file system What are those locally mounted file systems ?
ls
pwd
cd gdf du mount
list the directory contents present working directory change directory, current . parent .. display file system info display usage info for a file/directory display all mounted file systems
More about ls
..
~
Directory/File Operations
mkdir
rmdir
rm mv touch
make directory remove directory remove file move or rename directory/file create or change file modification times
Lab
Create and remove directories/files:
% % % % % % % % % % % % cd mkdir unixclass cd unixclass mkdir emptydir rmdir emptydir touch file1 file2 file3 rm file1 mkdir dir1 cd dir1 touch file1 cd .. rm r dir1
Lab
Move and rename directories/files:
% % % % % % % cd ~/unixclass touch file1 file2 file3 file4 mkdir dir1 mv file1 dir1 mv file2 file2.new mv dir1 dir2 mv file3 file4 dir2
cat
more
less head tail wc vi
concatenate and display files browse or page through a text file opposite of more display first few lines of files deliver the last part of a file display a count of lines, words and characters in a file screen-oriented (visual) display editor based on ex (text editor)
Quiz
How to get the file size? How do you know the creation time of a file?
Lab
cd /usr/include
List files start with st List files start with an upper case letter List files start with letters from u-z
Data Streams
STDIN standard input, normally the keyboard STDOUT standard output, normally the screen STDERR Error output, normally the screen Pipes Connects one commands output to another commands input. Symbol: |
| wc -l
who
wc -l
Redirection with the concept of pipe, you can redirect your data output to a file or device
who who > file1 ls l file1 cat file1 wc l < file1 date >> file1
% % % % % %
Quiz
What are those 3 data streams in standard shell ? How do you get the data into a file ? How do you link a commands output to another commands input ?
Filters
Beside pipes, redirections, you can modify your data output with filters
grep
grep flags
dont want this (filter out) -i neglect lower/upper case -n give line numbers -c count lines
-v
sed
line
% cat /etc/passwd | sed s/bin/BIN/ % cat /etc/passwd | sed n 1,2s/bash/BASH/ % cat /etc/passwd | sed n 1,2s/bash/BASH/p
sed flags
-n
silent mode
awk
% cat /etc/passwd | grep root % cat /etc/passwd | grep root | awk F: {print $6} % cat /etc/passwd | awk F: {print $1}
sort
-d dictionary order
-n numeric -r reverse
Quiz
Lab
Run the command ypcat hosts | grep pglw and put the sorted second column of the output into a file: linux.ws List all the users logged in and sort them into a file, and display number of users logged in at the last line of the file
More Commands
Wild cards
* ? []
any character(s) one, and only one character a range of characters [0-9] [A-z]
Comparing Files
ln <oldfile> <newlink> Hard link Creates a new item, newlink which changes with oldfile rm resistant, non-nfs friendly, non-directory friendly ln s <oldfile> <newlink> Soft (symbolic) link Creates a new pointer (ala Windows shortcut)
Compressing Files
.gz
Smallest size!
.Z
.zip
tar
Extract files
% tar xvf <.tar>
Process Table
ps flags
ps ef
ps ax
Lab 4
Redirect man page of true to a file true.f Redirect man page of test to test.f Make a directory called lab cd to lab touch 3 files: a, b, c. List them all with l Remove a. List them again with l Remove lab
The Shells
The Shell
UNIX shells are command interpreter and a programming language, usually used by admin for automated operations There are more than one shell in UNIX world sh borne shell, most machines roots shell csh C shell, a favorite for most users, ECs default shell tcsh an enhanced C shell .cshrc your C shell environment file .login your C shell login setting file .aliases this is where you customize your shortcut keys
Shell Environment
env
TERM terminal types HOME home directory PATH - your search path for commands PROMPT your system prompt TZ time zone EDITOR default editor DISPLAY the display location of X UID your user ID GID your group ID
In csh / tcsh:
% % % % % % % set hi = Hello set there = world echo $hi $there set unset hi there echo $hi $there setenv DISPLAY `hostname`:0.0
Quiz
How to see your environmental variable? Where is $HOME first set? What kind of variables are these:
Lab
Shell Quotes
used to preserve white space characters string ` ` runs command within the shell
Put the following alias into your ~/.aliases, change the prompt if necessary:
To use it:
source ~/.aliases
Looping
while
while 1 $ date $ sleep 1 $ end
foreach
foreach x ( a b c) $ echo $x $ end foreach x (`env`) $ echo $x $ sleep 1 $ end
Lab
Create a loop routine to count down 10, 91 Use your knowledge of common Unix commands and utilities (filter, pipe, etc) to create 2 files: linux.ws.alive, linux.ws.dead
linux.ws.alive - all Linux workstation alive using ping command linux.ws.dead all linux workstation not responding using ping command
More on tcsh
!!
Repeats previous command. !!:p Prints out the previous command. !-2 Repeats second-to-previous command. !-2:p Prints second-to-previous command. !23 Repeats command 23 as specified in the history list. !cat Repeats the most recent command that started with cat. !?cat Repeats the most recent command that had cat in it. !$ use the last word from the previous command and substitute it for this command !* use all words except the first one from the previous command and substitute them for the command.
history Lists out the previous commands in a format like: 86 9:26 cd admin 87 9:26 ls status/ 88 9:26 cd .. 89 9:26 ls tmp/
Quiz
1) 2)
3)
4)
You have been entering a bunch of commands, and several commands earlier was a very long one that you need to enter again. Name at least four ways to enter this command: Type it in completely
Answers
1) 2) history, then !<num> 3) !<command> 4) arrow-keys
drwxrwxrwx
Type
Owner Group Others
Examples
drwxrwxrwx World read/writeable directory -rwxrwxrwx World read/writeable file -r-xr-xr-x Executable only
File/Directory Ownership
The umask command sets or displays the creation mask setting which defines default attributes for new files Settings are the complement of chmod
Sticky bit
sticky bit only works on directories It is to make sure all files inside the directory having same GID
Lab
Check its default permission and ownership Change its permission to rwxr-x--Change its GID to PDC Change its ownership to root. Can you?
Login access
rule-based password protection passwords have 3-month shelf life Protect .rhosts with 0600
Network access
xlock
UNIX security has to comply with Intels information security policies & guidelines. Non-compliance of UNIX security will put Intel in danger of losing Intellectual Property.
First level, external users cannot access Intel file systems. Second level, you can protect your files from other Intel users. For example, no one else should be able to read your mail since mail is private. Project databases and some other material are sensitive and are accessible only to some users. Keep your home directory non-group writable. No one should be allowed to write in your area. When working in project areas, make your files group writable if they are shared.
vi Editor
vi
UNIX users favorite editor - a headache to Windows users You can use for a text file:
Viewing Inserting Appending Deleting Moving Copying Going to shell from within vi
Modes within vi
command mode
h left, j down, k up, l right x erase character dd delete line, 10dd yy yank or copy, y1 p - paste u - undo . repeat the last vi command (favorite productivity) 0 move to beginning of line
cw change a word r replace a character / - initiate a search n search next pattern J merge lines G go to bottom of lines :# - go to line # :r read a file from shell :set nu, :set nonu set/unset line # ^F page down (forward) ^B page up (backward) :wq, :wq! - write & quit
i insert, I insert at the begin of line a append, A append at the end of line o open a new line, or append at the next line
Lab