Introduction to Unix The Windows User perspective Wes Frisby Kyle Horne Todd Johansen
What is Unix? Portable, multi-tasking, and multi-user operating system Software development environment Hardware independent History Bell labs, 1969 Distributed to government and academic institutions
What is Unix? Combines smaller programs (shell commands) instead of relying on large individual programs Good tool for distributed processing and multitasking Essential for the development of the Internet and networks
Unix Architecture kernel Core of the operating system Manages computer's hardware shell Command line interpreter Interface between user and kernel Sometimes called terminal Just a program
What's in a kernel? License Pentium vs Athlon Unix vs Linux
Why Use Unix Who uses it? IBM, Sun Microsystems, HP, NEC, SGI Where is it used? Backbone of the Internet Scientific Computing High Performance Computing Video Game Consoles PDAs and Cellphones
Graphical Programs Need X11 Start local X-server Cygwin Xming Exceed
What is X11? Allow for graphical interface Network transparent so a program on a remote machine can be used locally Client-Server design
Starting X-Server
Terminal emulator Secure remote login Free, open source PuTTY
Open PuTTY Session Connection Type Host Name: X11 PuTTY tutorial
Enable X11 Forwarding
Login as: Password: You're ready to work from the command line PuTTY tutorial
WinSCP file transfer protocol (FTP) client for Microsoft Windows Open source Uses similar protocols to PuTTY Can act as a remote editor Can be used simultaneously with PuTTY
Open WinSCP Session Host name: User name: Password: WinSCP tutorial
WinSCP Tutorial Left - local Right - remote Easy click and drag file management Refresh button
Lets talk about the command line
Command Line Requires previous knowledge from user Unfamiliar to many users today No or little mouse support Fastest way to do some things Very good remote connection support Requires only little instruction to be effective
Command line hint: Write down useful commands keep a list
Common Commands ls List directory contents cd Change directory mv Move a file cp Copy a file rm Delete (remove) a file mkdir Create a directory nano Edit a file less Display a file in a scrollable environment
ls List directory contents
Wildcards * matches zero or more charcters ls *.txt list all text files? matches one character
cd Change directory Programing C Fortran kfem Mixed Life test Templates
mv Move a file
cp Copy a file
rm Delete (remove) a file
nano edit a file
Getting help man command - returns a manual for command man ls
More commands Download file unixtut.tar.gz to Windows machine Copy to remote system using WinSCP Extract the files: tar xzvf unixtut.tar.gz We will talk about 'tar' later.
ls - list files Lets view the files that were extracted. $ ls unixtut/* Output: unixtut/lit: poe sonnet1.txt sonnet2.txt sonnet.tx t theraven.txt unixtut/poe: unixtut/sonnets:
mkdir - make directory Lets make a 'shakespeare' directory $ mkdir ~/unixtut/shakespeare
mv - move file Lets move the sonnets folder into the shakespeare folder. $ mv ~/unixtut/sonnets ~/unixtut/shakespeare/
cp - copy Lets copy the sonnets from ~/unixtut/lit/ to ~/unixtut/shakespeare/sonnets/ ~ - means home directory $ cp ~/unixtut/lit/sonnet* ~/unixtut/shakespeare/sonnets/ Lets verify the contents ls ~/unixtut/shakespeare/sonnets/ Output: sonnet1.txt sonnet2.txt sonnet.txt
rm - remove file Lets remove the sonnets in ~/unixtut/lit/ $ rm ~/unixtut/lit/sonnet* Be careful using this command
less - view file Commands arrow key up - one line up arrow key down - one line down f - page down b - page up q - quit $ cd ~/unixtut/shakespeare/sonnets/ ~ - means home directory $ less sonnet.txt
wc - word count Count the number of words in a file. $ wc -w ~/unixtut/lit/sonnet.txt Output: 118 sonnet.txt -w option counts the number of words Count the number of lines in a file $ wc -l ~/unixtut/lit/sonnet.txt Output: 14 sonnet.txt
tail What does it do? Outputs the last part of a file. Default 10 lines. $ tail ~/unixtut/shakespear/sonnets/sonnet.txt
head What does 'head' do? Outputs the first part of a file. Default 10 lines. $ head ~/unixtut/shakespear/sonnets/sonnet.txt
grep What does it do? Searches in files for patterns. Example: Search the unixtut files and print out all lines that have the word 'all' $ grep -r -w all ~/unixtut -r is for recursive search -w is for whole word match Count the number occurrences $ grep -r -w -c all ~/unixtut -c only prints out a count
stdin, stdout, and stderr Input/Output is handles in streams 3 standard streams stdout output stderr error messages stdin input from user
Redirection of stdin, stdout, stderr > file - redirect stdout to file >> file - append stdout to file < file - read file into stdin Example: $ who > users.txt who - prints users logged in $ sort < users.txt sort alphabetically users.txt This could have been done with piping $ who sort
Piping Allows output of one command to be sent as input to the next command Attaches stdout of one process to stdin of another Automation We will come back to this later
Console Multitasking Pause running program with CTRL-Z & put after command to start in background bg run last paused program in background fg run background or paused program in foreground jobs
Example on multitasking Start two xterms in the background $ xterm & xload& xeyes& View the jobs in the background $ jobs Output: [1]- Running xterm & [2]+ Running xterm & fg 1 kill it with ctrl-c fg 2 kill it with ctrl-c
Processes Every user has their own processes. But how do we kill a process?
Example on processes ps - prints a snapshot of processes $ ps -U username o prints processes running by username $ ps -C command o prints process ids (PID) for commands
More Process Examples What if you want to do both? $ ps -U username -C command o Does not work piping and grep to the rescue o $ ps -U username grep command o $ kill PID
ssh What is ssh? Secure, remote login shell Command line, no GUI PuTTY uses this protocol Forward connections through multiple hosts ssh -X username@hostname
scp What is scp? Secure file transfer protocol Also command line Uses ssh From remote computer: scp username@hostname:filename filename To remote computer: scp filename username@hostname:filename
Permissions Each file has an owner user and owner group Actions for user, group, and others
Example on permissions touch file.txt chmod 700 file.txt chmod 755 file.txt chmod u+rwx file.txt chmod g+xr file.txt
tar - archive (zip) Remember $ tar xzvf unixtut.tar.gz? Lets create a tar file of the files in unixtut. o $ cd Takes us to the home directory o $ tar czvf newfiles.tar.gz unixtut View contents and permissions of newfiles.tar.gz o $ tar tzvf newfiles.tar.gz Get more help: o $ man tar
Environmental Variables Start with a '$' Affect the behavior of programs Set using 'export' View all with 'printenv'
Running programs $PATH variable Most programs are in $PATH Current directory is often not in the path use './'
$PATH example What is the current path variable? o echo $PATH Add folder to path o export PATH=$PATH:/folder/
Any Questions? Questions
Text editors Lots of good text editors are available on Unix Syntax highlighting Search abilities Designed with programing in multiple languages in mind kate gedit medit nano vim emacs
kate The KDE Advanced Editor Intuitive Terminal File manager Standard part of KDE
gedit The GNOME editor Intuitive Simple Standard part of GNOME
medit Simple but useful Intuitive Terminal File manager Easy to add tools GTK based, but few dependencies
nano text only, but easy Text only Easy to use Not as feature-rich as emacs or vim
vim hard, but very powerful Many features but only through key commands Found on nearly any Unix machine
emacs like vim, just different Many features Rather hard to learn Standard GNU tool Many extensions
Shell Scripting (Bash) Execute a series of commands in sequence Execute in the Bash shell Automatation Job scripts on supercomputers
echo Commands contained in $() are executed first echo and $()
Aliasing Automatic replacement of one command with another Use certain options all the time
if for Flow Control
#!/bin/bash Sample Shell Script
Building Programs rxvt is an alternative to xterm Will be built from source code
Building Programs (cont)./configure --prefix=$home make install
Building Programs (cont)