1 / 91

Introduction to Linux

Introduction to Linux. ITS Research Computing University of North Carolina at Chapel Hill Instructors: Mark Reed, C.D. Poon Emails: markreed@unc.edu, cdpoon@unc.edu. Course Design and Logistics. Course Design: Lecture – background & intro to commands (~30 min) Short Lab (~15 min)

sani
Download Presentation

Introduction to Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Linux ITS Research Computing University of North Carolina at Chapel Hill Instructors: Mark Reed, C.D. PoonEmails: markreed@unc.edu, cdpoon@unc.edu

  2. Course Design and Logistics • Course Design: • Lecture – background & intro to commands (~30 min) • Short Lab (~15 min) • Lecture – commands in detail (~40 min) • Final Lab (~35 min) • Lab is an integral part of course. • Please play along • learn by doing! • Please ask questions • Restrooms • Breaks

  3. Overview • Objectives • Operating Systems • History • Variations • User Interface • Commands • Conclusion

  4. Objectives • What this course is: • An introduction to Linux hopefully to put it into a context for better understanding • Gain the perspective to see what it is, what it can do, why use it • What this course isn’t: • Just a list of Linux commands and what they do (although there will be plenty of that :) • Not just to answer “How do I … ?”

  5. What is an OS (Operating System)? • The most important program that runs on a computer • Operating systems perform basic tasks : • recognizing input from keyboard and mouse • sending output to display screen • keeping track of files and directories on the disk • controlling peripheral devices such as disk drives and printers • networking, security, memory management, ....... http://www.webopedia.com/TERM/o/operating_system.htm

  6. Examples of OS’s • DOS, MS-DOS • MS Windows (95, 98, NT, XP, Vista) • Linux (RedHat, SuSE, Ubuntu, ...) • Unix (Irix, Solaris, AIX, ...) • MacOS, MacOS X/Darwin

  7. History of Unix/Linux • 1969 – First Unix was developed at AT&T Bell Labs by Ken Thompson and Dennis Ritchie. • 1977 - First BSD was released, spurred in part by sabbatical at UC-Berkeley by Thompson. Ken (seated) and Dennis (standing) at a PDP-11 in 1972.

  8. History of Unix/Linux • 1991 - Linux was introduced by Linus Torvalds, a student in Finland, who posted to the comp.os.minix newsgroup with the words. • Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. … • 1993 – FreeBSD project was coordinated by Nate Williams, Rod Grimes, and Jordan Hubbard for running on 386 machines. Linus Torvalds at LinuxWorld 1999

  9. History of Unix/Linux Cont’d • The GNU (Gnu’s Not Unix) was an effort to develop free and open source applications. • Torvalds combined his kernel with GNU software from Richard Stallman (of emacs fame) and the Free Software Foundation and Linux was off and running. • Linux grows with contributions world-wide. Richard Stallman

  10. Linux Overview • Linux Features: • Multi-tasking • many programs running • Multi-user • many users on the same machine at once • Multi-platform • runs on many different processor types

  11. Variations on a Theme • Two major branches of Unix • AT&T System V • BSD (Berkeley Software Distribution) • Lots of commercial Unix-like systems • AIX (IBM), IRIX (SGI), HP-UX (HP), OpenSolaris (Sun), MacOS X, … • Linux is a Unix-like system free of proprietary software for which source code is available and freely distributed. • There are minor variations among these. • much more alike than they are different

  12. Linux Distributions • There are many groups packaging Linux for distribution. • some freely available • others commercial • A partial listing (in no particular order): • Red Hat • CentOS • Ubuntu • Debian • SuSE • Fedora • and on and on … :)

  13. User Interface • The user interacts with the OS by giving it commands. This interface is either via • command line (e.g. through the shell) • graphical user interface (GUI) • Don’t confuse the user interface to the OS w/ the OS itself (which does much more). • Most OS’s can do both, e.g. Linux typically uses the command line but Konqueror is a GUI for Linux (web browser, file manager, document viewer).

  14. Shell • The Command Line Interface (CLI) for Linux is through the shell. • This is the application (program) that interprets what you type and carries out your directions. • Common Shells: • tcsh – exTended C SHell • bash – Bourne Again SHell • ksh – Korn SHell • csh – C SHell (early popular shell) • sh – the original shell, often a synonym for bash now

  15. OS as an Onion Heart of the OS • OS Modularization: • the kernel • an interpreter • and utilities The User Interface to the OS The Stuff you want the system to do

  16. Linux Commands • Man pages • Working with files and directories • pwd, cd, ls, mkdir, rmdir, cp, mv, rm, scp, cat, more, less • Wildcards • *, ?, [] • Permissions • chmod, chown, chgrp • Finding stuff • find, which, whereis, locate

  17. Linux Commands Cont'd • Packing and Unpacking stuff • tar, gzip, compress, gunzip, unzip, sort • Pipes and redirection • >, >>, <, | • Jobs and processes • ps, kill, pkill, ctrl-C, bg, ctrl-Z, &, fg, jobs • Quick and Easy: shortcuts and tricks of the trade • history, file completion, alias, environment variables

  18. Some Caveats • There’s always more than one way to do things under Linux. • These commands just cover some of the basics and the more useful options. • the proverbial tip of the iceberg!! (not to worry, you’re not the Titanic :) • The man pages are your friend. • Lean on them!!

  19. File System - Directory Structure

  20. Some fun unix-y quotes • linux: the choice of a GNU generation • "Unix is user-friendly. It's just very selective about who its friends are." • "The box said 'Required Windows 95 or better'. So, I installed LINUX." • “If you have any trouble sounding condescending, find a Unix user to show you how it's done.” - Scott Adams

  21. Some fun unix-y quotes "The university computer system was better than no computer at all. But Randy was humiliated. Like every other high-powered academic computing network, this one was based on an industrial-strength operating system called UNIX, which had a learning curve like the Matterhorn, and lacked the cuddly and stylish features of the personal computers then coming into vogue.” - Cryptonomicon by Neal Stephenson

  22. Commands in General(and a General Giving Commands :) • Commands are case sensitive. • Arguments typically are given with a dash “-”. • multiple arguments usually only require the leading dash • Commands are programs or applications that the user invokes. • The system finds the command by • specifying the full path • shell built in commands • looking in all directories in your PATH, typically this includes /bin, /usr/bin, … (but maybe not “.”) Eisenhower on D-Day

  23. man – Manual • man <command> • man formats and prints the online manual pages • -k keyword search • do keyword search for applicable man pages (same as the apropos command) in the whatis database • Note on the man pages that arguments that appear in square brackets […]are optional • Use these early and often

  24. more man • Options at the prompt: (the “more” command options) • h - help • spacebar – scroll forward one screen • <CR> - scroll forward 1 line (can change this to be whatever number of lines you wish) • b – back, go back a screen (does not work w/ all mores) • q – quit • /<regexp> - search for regular expression • To find out lots and lots about the shell: • man tcsh • man bash • man ksh • Browse them for what you need, no need to read them cover to cover (unless you want to feed your inner geek :)

  25. Working with Files and Directories

  26. pwd – Print Working Directory • “pwd” displays the full absolute path to your current location in the filesystem. • Absolute paths (/…) • Relative paths (../work/…, bin/…) • “.” dot always refers to your current directory • “..” dot-dot always refers to your parent directory (i.e. the one “above” you in the directory hieararchy) • emerald% pwd/afs/isis.unc.edu/home/c/d/cdpoonemerald%

  27. cd – Change Directory • cd <path> • Changes your current working directory to path (which can either an absolute or relative path). • a common relative paths to use is '..' (i.e. the parent directory of the current dir) • cd • by itself changes to your home directory • cd – • returns to previous directory • cd ~/projectA/run • ~ is a shortcut for your home directory

  28. cd Example emerald% pwd/afs/isis.unc.edu/home/c/d/cdpoonemerald% cd /etcemerald% pwd/etcemerald% cdemerald% pwd/afs/isis.unc.edu/home/c/d/cdpoonemerald% cd - emerald% pwd /etc emerald% cd .. emerald% pwd / emerald%

  29. ls – List • ls - lists the contents of a directory. • If no target is given, then the contents of the current working directory are displayed. • By default “ls” doesn't show you all the entries in a directory - files and directories that begin with a dot (.) are hidden (including '.' and '..' which are always present). • The reason for this is that files that begin with a “.” usually contain important configuration information and should not be changed under normal circumstances.

  30. ls – Useful Options • ls –a, show all files (or –A, exclude ., ..) • ls –l, long listing • shows properties such as the size, type and ownership of files • ls –t, sort by time • ls –d, list directory name, not contents • ls –h, human readable file sizes • ls –F, classify, appends symbol indicating type • these can be combined, “ls -a –l -h”  (or, equivalently) “ls -alh “ 

  31. ls -al ls -al (list directory with hidden files/directories in long listing) The command, ls -al, lists the contents of a directory including the hidden file/directory names starting with "." in a long listing.emerald% ls -altotal 1096drwxr-xr-x   27 root root   4096 2008-03-24 14:30 ./drwxr-xr-x   27 root root   4096 2008-03-24 14:30 ../drwxr-xr-x    2 root root   2048 2003-05-05 14:04 afs/-rw-r--r--    1 root root      0 2008-03-24 14:30 .autofsck...emerald%

  32. ls –l - List Content in Long Form The command, ls -l, lists the contents of a directory in long listing.

  33. mkdir - Make Directory • mkdir <New_Directory> • Creates a subdirectory called New_Directory in the current working directory. You can only create subdirectories in a directory for which you have write permission. • -p option • creates parent directories as needed, e.g. mkdir –p myprojects/projA/example2/test

  34. mkdir Example The command, mkdir, makes directories.emerald% cdemerald% pwd/afs/isis.unc.edu/home/c/d/cdpoonemerald% alias ls ls -F emerald% lsDesktop/   intel/  nsmail/    private/  public_html/dumpster/  ms@     OldFiles/  public/   temp/emerald% mkdir new_diremerald% lsDesktop/   intel/  new_dir/  OldFiles/  public/       temp/dumpster/  ms@     nsmail/   private/   public_html/emerald%

  35. rmdir/rm -r – Remove Directory • rmdir <uselessDirectory> • removes the subdirectory directory from the current working directory. You can only remove subdirectories if they are completely empty (i.e. of all entries besides the '.' and '..' directories). • Use “rm –r” to remove directories and contents in one step

  36. Lab Exercises • Please try out all or some of the exercises that follow to get your feet wet. Then try the “Treasure Hunt” which we hope you’ll enjoy! • Accounts: Use any Linux machine you have access to, such as emerald.unc.edu OR • Use the VCL! There is an image for classroom use in the Virtual Computing Lab with data files already installed • go to vcl.unc.edu • click “New Reservation” on the menu on the left • select “RC Class Image” from the drop down menu • select “Now” for the time and “2 hours” for Duration • click “Create Reservation” • use the password and IP address to ssh to the machine.

  37. Remote Login (Linux to Linux) • A secure shell is a program for logging into a remote machine providing encrypted communications between the machines: ssh [options] machine • options: • -l login name (or use ssh login@machine) • -Xsets environment variables for porting X-display, • -Y similar to -X, required for some programs. • Example: ssh emerald.isis.unc.edu –l cdpoon or ssh cdpoon@emerald.isis.unc.edu ssh emerald –X –l cdpoon

  38. Connecting to a Linux system(e.g. Emerald) from This Lab • Using ssh, login to Emerald, full name is emerald.isis.unc.edu. To start ssh: • Start->Programs->Remote Services ->SecureCRT 5.<x> • Click the Quick Connect icon at the top. • Hostname: emerald.isis.unc.edu • Login with your ONYEN and password

  39. Exercise 1 • Start up a terminal application (SecureCRT, F-Secure SSH Client, etc.) . • Log on a Linux machine (Emerald, Topsail, etc.) with your ONYEN and password. • 3. Enter the commands on the right at the prompt, hit "enter", and try to interpret the output. • Ask questions. • echo hello world • date • hostname • whoami • who am i • who • clear • history • cal 2008 • pwd • echo $SHELL

  40. Exercise 2 • Enter the commands in sequence on the right at the prompt, hit "enter", and try to interpret the output. • Encounter error, check out why. cdpwdcd /etcpwdcd /ls -alls -l cdmkdir temp_dircd temp_dirmkdir temp_subdircdls -lls -l temp*rmdir temp_dirrm -r temp_dir

  41. Wildcards

  42. Wildcards • Multiple filenames can be specified using special pattern-matching characters. The rules are: • '?' matches any single character in that position in the filename • '*' matches zero or more characters in the filename. • ‘[…]’ Characters enclosed in square brackets match any name that has one of those characters in that position • Note that the UNIX shell performs these expansions before the command is executed.

  43. Wildcard Examples Given: climate.01.2000.dat climate.06.2000.dat climate.07.2000.dat climate.12.2000.dat climate.02.2000.dat climate.06.2001.dat climate.08.2000.dat climate.total.dat climate.03.2000.dat climate.06.2002.dat climate.09.2000.dat Climate.txt climate.04.2000.dat climate.06.2003.dat climate.10.2000.dat seasonal.2000.dat climate.05.2000.dat climate.06.2004.dat climate.11.2000.dat seasonal.2001.dat • climate.0[6-8].*.dat • get only months Jun-Aug (ie. 6-8) for all years • clim*2001* • get only climate files for year 2001 • *.??.* • only files that have 2 characters between dots

  44. cp - Copy • cp <source-file(s)> <destination> • “cp” copy files or entire directories    • <source-file(s)> and <destination> specify the source and destination of the copy respectively. • To copy entire directories (including their contents), use a recursive copy: • cp -r source-directories destination-directory • This copies all files in all subdirectories below source.

  45. mv – Move/Rename • mv <source> <destination> • “mv” is used to rename files/directories and/or move them from one directory into another. • By default the destination will be silently overwritten by source. • -i option for interactive • this will prompt you before overwriting a file

  46. rm - Remove • rm <target-file(s)> • Removes specified files. Works as advertised, it really removes the file, there isno backupfile orundeleteoption. • -i for interactive • use this to be prompted before deletion • -r for recursive • removes directories, subdirectories and their contents (files). • -f for force • removes w/o prompting 

  47. scp – Secure Copy • “scp” is commonly used to copy files between any 2 hosts on a network using the ssh protocol. • commonly used to securely upload/download your files from your home machine to desired machine • Format: • scp [options] <host:file1> <host:file2> • form of host may be login@host (default login is your current login) • the “host:” is omitted if the target machine is the one you are on • file path is relative to your home directory • Options: • -r recursive (used for directories)

  48. cat – Concatenate • cat <target-file(s)> • displays the contents of target-file(s) to standard out (typically your screen) one after the other • useful for combining files together • more and less are better to just display file content

  49. more and less • more <target-file(s)> • “more” displays the contents of target-file(s)  on the screen, pausing at the end of each screenful and asking the user to press a key (useful for long files). • “less” is just like more, except that has a few extra features (such as allowing users to scroll backwards and forwards through the displayed file). • not a standard utility, therefore may not be present on all UNIX systems

  50. More of more and less • Options at the prompt: • h - help • spacebar – scroll forward one screen • <CR> - scroll forward 1 line (can change this to be whatever number of lines you wish) • b – back, go back a screen (does not work w/ all mores) • q – quit • /<regexp> - search for regular expression

More Related