170 likes | 318 Views
UNIX / Linux Primer. July 22, 2008 Nicholas F. Polys Ph.D. UNIX. Many flavors Enterprise / Industrial strength kernel Macs are based on BSD Unix Under Win, install CygWin Linux and Open Source are ‘Free’ as in Puppy- not ‘Free’ as in beer . The Command Line.
E N D
UNIX / Linux Primer July 22, 2008 Nicholas F. Polys Ph.D.
UNIX • Many flavors • Enterprise / Industrial strength kernel • Macs are based on BSD Unix • Under Win, install CygWin • Linux and Open Source are ‘Free’ as in Puppy- not ‘Free’ as in beer
The Command Line • Accessible through the wire • Real power to control the system through a terminal running a shell • Typical forms: $ somecommand –optiona value –optionb value $ somecommand –optionaoptionb • Cntrl-c will quit a running command
Commands • When you log in, you are in a ‘shell’ • You interact with the system by typing at the prompt or running scripts • To find out the options for a command, use manual e.g. $ man somecommand • :q will quit (like vi)
The Filesystem • Your home directory is ~username • Typically /home/username • pwd shows your current directory • ls –al list files in current dir • mkdir dira make a dir • touch filea create a file • mv filea fileb move • cp filea fileb copy • diff filea fileb difference • rm … remove …careful! -f forces it –r means recursive
Permissions • Files and folders can be owned and permissions set • chmod a+x targeta • user, group, other, all • +, - • read, write, execute
Inspecting files • more filea show the whole file • less filea show one screen atat • :q will quit (like vi) • tail filea show the last screen
Environment Variables • Your account has a default shell; env variables can be set there (for the bash shell, e.g. ~username/.bashprofile or .bashrc • Env shows your current settings such as your PATH • You can set you own env vars for a shell session with: export SOMEVAR=value
Processes • ps –ef show active processes • kill -9 pid kill the process with pid • mozilla & add ‘&’ to the end of a command to run it in the background (and keep your command prompt) Compression • tar wrap up multiple files/folders .tar -cvf wrap -xvf unwrap (force, verbose) • gzip ; gunzip (.gz)
Vi editor • Text editing on the remote files system (through a terminal shell) • Text editor for shell / keyboard interaction • Insert vs Command mode <esc> • See basic usage handout • Try it out • Takes practice
Other Typical Apps • cat – concatenates files • awk – manipulate rows and columns of data efficiently • grep / egrep – searching files for patterns (aka ‘regular expressions’)
Pipes • | send a stream of data • > write a stream of data to file • >> append a stream of data to file e.g. • ps -ef | grep ‘npolys’ • ls –al > filea.txt
Shell scripts Collect commands and env vars so you don’t have to type them every time • Typically use .sh file extension • Invoke with ./myscript.sh • File begins with #!/bin/sh • Perl • begins with #!/usr/bin/perl • Find where perl is: which perl
Connecting to other machines • Shell • ssh npolys@bug.sv.vt.edu • Files • secure copy (remote file copy program) • scp • interactive secure ftp sessions • sftp npolys@bug.sv.vt.edu • get file • put file • ‘cd’ versus ‘lcd’
Compilation • gcc GNU C and C++ compiler • Most apps have a configure script and a Makefile which automates compilation and installation; always check the README • Makefiles
Debugging • gdb • Requires flags during compilation (-g) which will create an a.out file • ‘gdb a.out’ will begin the debugger • See • http://sourceware.org/gdb/current/onlinedocs/gdb.html
Profiling • gprof • Requires flags during compilation (-pg) which will create an a.out file • Run the app once (eg $> ./a.out ) • Then ‘gprof a.out’ will begin the profiler, showing timings and the application’s call graph • http://sourceware.org/binutils/docs/gprof/index.html