+ All Categories
Home > Documents > Linux Crash Course Selected snippets from CIS52. Long ago, in a galaxy far away … Computing power...

Linux Crash Course Selected snippets from CIS52. Long ago, in a galaxy far away … Computing power...

Date post: 02-Jan-2016
Category:
Upload: irene-rosalyn-porter
View: 213 times
Download: 1 times
Share this document with a friend
Popular Tags:
46
Linux Crash Course Selected snippets from CIS52
Transcript

Linux Crash CourseSelected snippets from

CIS52

Long ago, in a galaxy far away …

• Computing power was costly– UNIVAC cost $1 million

• CPU time was a premium– Most mainframes had less computing power than

a calculator on the shelf at Wal-Mart

• Jobs were submitted into a queue– Only one process at a time – scheduling

nightmare

What was needed• Allow multiple users to access the same data

and resources simultaneously

• Service many users more cheaply than buying each their own machine

• The ability to run multiple processes at once

• And do so while maintaining user segregation and data integrity

Enter Unix, pride of Bell Labs• Originally written in PDP-7 assembly

language by Ken Thompson

• To make it work on multiple architectures (portable), Thompson rewrote Unix in B

• Dennis Ritchie developed C, and with Thompson, rewrote Unix in C

What was so great about it?• Multiuser

• Multiprocess

• Non-proprietary

• Economical for business

• Initially given for free to colleges and universities (great tactic!)

What happened?• UNIX became commercialized

• Proprietary code, specialized distributions

• Costs started to become a hindrance

• So … let’s make our own Unix …

GNU• Richard Stallman decides that there should

be a free version of Unix available

• Forms the GNU project – GNU’s Not Unix

• Writes all of the system programs and utilities to mimic Unix variants

• Everything but a kernel (Hurd)

Final piece• Universities trying to teach Unix and OS

design can’t afford Unix

• Andrew Tanenbaum writes Minix

• Linus Torvalds, dissatisfied with Minix, writes his own – Linux

GNU-Linux• Torvalds has a perfectly functioning kernel –

but no system programs

• Finds a perfect candidate in GNU

• Together, the operating system world was changed dramatically

Why Linux?• Software

• Hardware

• Portability

• Standards

• $$$

Features Overview• Multiuser

• Multiprocess / Multitasking

• Hierarchical Filesystem

• BASH Shell command line interface / programming language

• Many useful utilities built-in

• Rich networking support

How do I start?• Console vs. terminal vs. terminal emulator

• Text-based vs. graphical

• Where’s the box at?

Consoles and terminals• Monitor, keyboard (and maybe mouse) attached

to the box

• The console often locked away in a closet or server farm somewhere

• Terminals usually found in mainframe environment

• Recently ‘thin clients’ gaining popularity again

Terminal Emulation• Using a separate system, connect a virtual

terminal to the server

• telnet, ssh, X Windows

• Most common way to interact with a Linux/UNIX machine

• Ubuntu – Applications->Accessories->Terminal

The Shell• Command interpreter

• Translates commands issued by user into commands sent to the kernel

• Common shells: bash, tcsh, csh, zsh, ksh

• Linux default is bash (Bourne Again Shell)

Administrative privleges• root or superuser

• Full read/write access to filesystem

• Can execute privileged commands and programs

• Use sparingly and with extreme caution

Admin Priv, con’t• We’re using Ubuntu, which treats root in a

unique fashion

• Don’t logon as root

• To execute privileged commands:– sudo [command] or gksudo [command]– Will prompt for your credentials – are you sure??

Getting help• Most GNU commands and utilities have built in

help and usage information

• --help (sometimes -h or -help)

• Too much information? Pipe results to less or more– ls --help | less

man Pages• man program_name

• Displays online documentation, formatted with a pager

• SPACE to advance, q to quit

• Depending on the system sometimes you can also use PAGE UP/DOWN

Typing Commands• Beware of special characters

• Characters that have special meaning to the shell

• Shell expands, modifies and interprets special characters before issuing the command

Special Characters• & ; | * ? ‘ “ ` [ ] ( ) $ < > { } ^ # / \ % ! ~ +

• Plus whitespace (tabs, spaces, newlines)

• Do not use these in filenames unless you have to

• To use them, either put in single quotes, or proceed with a backslash– ls ‘filename with special chars!!’– ls \[cat\]

Utilities• Linux & Unix come with thousands of utilities

• Some used explicitly, others implicitly

• Some text-based, some GUI, some both

Some tips before we start• Tab completion

– When typing a filename or command name, you can type the first few letters then hit TAB to auto-complete the command

• Command history– Use the up and down arrow keys to cycle

through recently executed commands– You can edit them before issuing again

ls: LiSt files• Used to list files contained in a directory

• Can narrow the search using pattern matching

• Examples– ls displays ‘all’ the files in the directory– ls cats displays the file cats in the directory– ls ca* displays files starting with ‘ca’

cat: catenate a file• Displays the contents of one or more files

• Beware – don’t try with binary files

• Examples– cat myfile displays contents of myfile– cat file1 file2 displays contents of file1

followed by contents of file2

cp: CoPies files• Usage: cp sourcefile destinationfile

• Creates a copy, leaves sourcefile intact

• If destinationfile exists, it will be overwritten– Unless you use –i option

• Example:– cp myfile myfile.backup

mv: MoVe files / change name• Usage: mv existingfile newfile

• Just like cp, can overwrite with –i option

• Renames a file, which can also move it to another directory

• Examples:– mv myfile foshizzle– mv /dir1/myfile /dir2/myfile

Editing Files• gedit filename

– Similar to notepad in Windows

• Do you have rights to edit?– If a system/service file probably not– gksudo gedit filename– We’ll have to edit some config files manually;

mostly we’ll try and use Webmin

Hierarchical Filesystem• Directories can contain other directories

and/or ordinary files

• Concept different from reality – in implementation everything is a file

• Directories, devices, named pipes, ordinary files – all really just files

Lingo• Root directory

• Subdirectories

• Parents, children

Filenames• Each file within a directory must have a

wholly unique filename

• Can be up to 255 characters – make them longer to avoid confusion

• Special characters must either be escaped out (using backslash) or in quotes

• Only illegal characters are / and carriage return

Filenames con’t• Spaces and other special characters a bad

idea

• Instead of spaces use underscores or periods– Ex: my_file or my.file

Hidden Files• To make a file hidden, start it with a period

– Ex .plan

• A normal ls will not show hidden files

• Use ls –a to reveal ALL files

• Startup files, containing configuration settings for your account, hidden

mkdir – create directory• Syntax: mkdir directory

• Directory can be a relative or absolute pathname (we’ll get to that in a minute)

• You can use ls –F to show directories with a forward slash at the end of the name

• If using a color terminal, directories will be a different color than ordinary files

Working Directory• The directory you are currently working in

• pwd will tell you what your working directory is

• Helpful to know when using relative pathnames (again, coming up)

Home Directory• Not to be confused with working directory

• The directory you start in when you first logon

• Most users it is /home/username

• For root, it is /root

• Can be changed by system administrator

cd – change working directory

• Syntax: cd [directory]

• Again, directory can be absolute or relative

• If no argument given, changes working directory back to your home directory

Absolute Pathnames (finally)• Absolute pathname for a file gives the file’s

location relative to the root of the filesystem

• Sometimes long

• Ex: /home/jhowell/Assignment1/animals

• Shortcut: ~ represents your home directory

• So the above could also be ~/Assignment1/animals

Relative Pathanmes• A pathname relative to the current working

directory

• Make sure you know what your working directory is!

• Shorter

• Ex, in my home directory:Assignment1/animals

. and .. Directories• . is an alias for the working directory

• .. is an alias for the parent of the current working directory

• These pointers are placed in every directory when created by mkdir

• Can be used in relative pathnames

Common Directories• / (root) – root of the filesystem

• /bin – essential system binaries (commands)

• /boot – files for the bootloader

• /dev – device files

• /etc – system configuration files

• /home – user home directories

• /lib – standard libraries and modules

Common con’t• /mnt – mount point for temporary filesystems

(floppies, CD-ROMs, non-native partitions)

• /opt – optional add-on software

• /proc – kernel and process information

• /root – root’s home directory

• /sbin – essential system binaries

• /tmp – temporary space (not swap)

Common con’t• /usr – common area for data / program users

use frequently

• /var – frequently changing data like system logs, caches, spools and mailboxes

• That said, all these can reside on the same partition

• Only / and a swap partition required

Permissions• Use a ls –l (for long view) and you might see

something like this:

drwxr-xr-x 2 jhowell jhowell 4096 Aug 18 15:46 Desktop

-rw-rw-r-- 1 jhowell jhowell 0 Sep 4 18:08 myfile

drwxrwxr-x 2 jhowell jhowell 4096 Aug 22 15:32 public_html

Type of file

File Permissions

# of links

user

group

size

Date and time created / accessed

filename

chmod – CHange MODe• Changes permissions

• Syntax: chmod [ugoa][+-][rwx]

• Ex: grant everyone (all) read and writechmod a+rw myfile

• Ex: remove execute permission for otherchmod o-x myfile

Permissions Caveats• To execute a shell script you must allow both

read and execute permissions

• To get into a directory, you must have execute permission

• root can still read and write to files without read and write permissions


Recommended