Скачать презентацию 2 0 0 3 Introduction to the Скачать презентацию 2 0 0 3 Introduction to the

93efe46c4752a559e12c2ab34302bb9a.ppt

  • Количество слайдов: 30

2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 Introduction to the Shell – Session 1 · Getting started at a shell prompt · · · Working with files and directories · · · Navigating through the file system Moving yourself and your files around Viewing and editing files · · · Accessing a UNIX system Commands in UNIX Common editors Viewing files A few useful file and command tools and tips Introduction to the Shell – Session 1 1

2. 0. 0. 3 – Introduction to the Shell What is a Shell? · 2. 0. 0. 3 – Introduction to the Shell What is a Shell? · Shell prompt = command line · Text interface that allows user to type commands which the OS then executes · A more direct (and powerful) way to interact with your computer Linux command line DOS command line Introduction to the Shell – Session 1 2

2. 0. 0. 3 – Introduction to the Shell Accessing a UNIX / Linux 2. 0. 0. 3 – Introduction to the Shell Accessing a UNIX / Linux Shell Prompt · If you are at the GSC, your user account allows you to log on to any Linux machine on our network · Other ways to access UNIX/Linux: · Linux server set up by Sheldon: Access from other Linux systems or using eg. Putty from Windows · UBC Roadmap to Computing (http: //www. roadmap. ubc. ca/): free access to tutorials and UNIX shell · Canadian Bioinformatics Resource (http: //cbr-rbc. nrc-cnrc. gc. ca/): free academic access to bioinformatics tools and databases, web and UNIX command-line · Cygwin (http: //www. cygwin. com/): a free Linux emulator for computers running Windows · Linux (http: //www. linux. org/) : install Linux on your own computer – Linux itself is free to download and install; versions with full installation instructions and support Linux and UNIX are also available commercially Linux is a UNIX-like operating system, which is open-source (free, code can be contributed by anyone). The command line and command line tools for UNIX systems and Linux are basically identical. Introduction to the Shell – Session 1 3

2. 0. 0. 3 – Introduction to the Shell Logging In · To access 2. 0. 0. 3 – Introduction to the Shell Logging In · To access a shell prompt you will have to log in to a UNIX system using a username/password · How you do this will depend on what the system is · Once you are logged in to one computer, you can connect to a different computer on the same network using rlogin (remote login) or ssh (secure shell) – ssh is better as it encrypts any information you send · Get back out using exit (if you opened another shell) or logout (if this is the shell you started with) Introduction to the Shell – Session 1 4

2. 0. 0. 3 – Introduction to the Shell Basic UNIX Command Structure command 2. 0. 0. 3 – Introduction to the Shell Basic UNIX Command Structure command · Command: · Any UNIX command or program to run · Options: Spaces · Modifiers of the command, usually preceded by – ls –la README · Files or other things: · When appropriate, a file name, string, etc. that the command will act on Command Options File My prompt just says > You can determine what the text at the prompt is. It can be the date, current directory, or your favorite saying. Details in session 2. 0. 0. 3. 2. Introduction to the Shell – Session 1 5

2. 0. 0. 3 – Introduction to the Shell UNIX Help: man, info and 2. 0. 0. 3 – Introduction to the Shell UNIX Help: man, info and apropos · Look up usage of a command with man info · Accesses the manual pages for the given command · To exit man, type q (man uses less to display) · Also try --help apropos · To find a command you can try Introduction to the Shell – Session 1 6

2. 0. 0. 3 – Introduction to the Shell The UNIX File System · 2. 0. 0. 3 – Introduction to the Shell The UNIX File System · When you log in, you will be in your home directory, in my case /home/egarland · Files are arranged in directory trees: Parent directory: next directory up in tree (directory which contains current directory) hom e Child directory: all directories down in tree (directories which are contained by current directory) Watch out for Caps lock! UNIX files are CASE SENSITIVE, so eg. there is no /Home/egarland, and you can have a file “myfile” AND a file “Myfile”. Many people just avoid using capitals altogether. Introduction to the Shell – Session 1 7

2. 0. 0. 3 – Introduction to the Shell Navigating Through Directories: cd and 2. 0. 0. 3 – Introduction to the Shell Navigating Through Directories: cd and pwd · Check current directory with pwd · Change directories with cd · Specify directory: cd · cd only will go to your home directory · cd – will go to previous directory What are all those dots? Current directory is called “. ” Parent directory is called “. . ” The home directory is also called “~” Introduction to the Shell – Session 1 8

2. 0. 0. 3 – Introduction to the Shell Absolute and Relative Pathnames · 2. 0. 0. 3 – Introduction to the Shell Absolute and Relative Pathnames · You have to specify exactly where the shell should look for a directory home egarland relative unix_intro dir 1 absolute dir 2 Absolute pathname: How to get to a directory or file starting in the root directory / Relative pathname: How to get to a directory or file starting in the current directory Introduction to the Shell – Session 1 9

2. 0. 0. 3 – Introduction to the Shell Seeing What’s There: ls · 2. 0. 0. 3 – Introduction to the Shell Seeing What’s There: ls · To list directory contents use ls · Common ls options: -a -l -t -h list all files (including. and. . ) list “long” file info list in reverse chronological order (newest first) list file size in “humanreadable” format (use with –l) Options can be combined: ls –lt does both –l and –t (only if the options do not require any additional info) Introduction to the Shell – Session 1 10

2. 0. 0. 3 – Introduction to the Shell Moving and Copying Files: mv 2. 0. 0. 3 – Introduction to the Shell Moving and Copying Files: mv and cp · To rename or move a file, use mv · To copy a file (while preserving the original), use cp · Common cp options: -I -r ask before copying over a file copy recursively (directory and all its contents) Naming files Files and directories can contain any characters except “/”. However, using spaces or other “special” characters (such as “*”) will cause you problems later. Avoid them! Instead of a space, use an underscore “_”. To refer to a file that has a space in it, use quotes: cp “my file” myfile Introduction to the Shell – Session 1 11

2. 0. 0. 3 – Introduction to the Shell Creating Links to Files: ln 2. 0. 0. 3 – Introduction to the Shell Creating Links to Files: ln · If you want to create a “shortcut” or “pointer” to a file or directory, make a link using ln · Editing the link will change the original file · Common options: -s: “symbolic” link: removing the link does not remove the original file Introduction to the Shell – Session 1 12

2. 0. 0. 3 – Introduction to the Shell Creating and Copying Directories: mkdir 2. 0. 0. 3 – Introduction to the Shell Creating and Copying Directories: mkdir and cp · Create a directory with mkdir · Copy whole directory structures using cp –r Wildcard characters * Matches any string of characters ? Matches any single character Introduction to the Shell – Session 1 13

2. 0. 0. 3 – Introduction to the Shell Getting Rid of It: rm 2. 0. 0. 3 – Introduction to the Shell Getting Rid of It: rm and rmdir · Remove a file using rm · Remove a directory using rmdir · Common rm options: -I -r ask before deleting a file remove recursively (directory and all its contents) Be very wary of rm * ! This will remove all files in your directory! For safety, always use the –i option (or, even better, use an alias: see session 2. 0. 0. 3. 2). Introduction to the Shell – Session 1 14

2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and 2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and emacs Editors · pico: simple text editor; intuitive · Just start typing · Commands listed at bottom · ^X to exit (hold control and push X) · ^O to save · ^R to open Introduction to the Shell – Session 1 15

2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and 2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and emacs Editors · Vi (or vim): not so simple · Two modes: command insert · Type a or i to start inserting · Esc to get back to command mode · Commands are in form : · : q to quit Insert mode Command mode Introduction to the Shell – Session 1 16

2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and 2. 0. 0. 3 – Introduction to the Shell Creating Files: pico, vi, and emacs Editors · emacs: full-featured but more intuitive than vi · Once a file is opened, just start typing · Common commands: · Cntl-X F to open (hold control while typing X and then F) · Cntl-X S to save · Cntl-X C to exit · “Meta” key is either Alt or Esc · If started without a filename, you first have to “find” (open) a new file with cntl-X F What are all these extra files in my directory? Emacs automatically creates autosave files (#filename#) when you don’t save before exiting and backup files (filename~) whenever you save changes Introduction to the Shell – Session 1 17

2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less 2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less and less is More · To output the contents of a file to screen, use cat · With long files, this scrolls past too fast to see Introduction to the Shell – Session 1 18

2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less 2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less and less is More · To view a file a bit at a time, use more · Navigating in more: · Go down 1 line: Enter · Go down 1 screen: Space · Go back 1 screen: b · Exit: q or Cntl-c Help! Let me out! Control-c is a general UNIX “exit” command. It will end whatever command you are running. For more commands like this, see “job control” in session 2. 0. 0. 3. 3. Introduction to the Shell – Session 1 19

2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less 2. 0. 0. 3 – Introduction to the Shell Viewing Files: more is Less and less is More · To view a file a bit at a time with full navigation and searching, use less · Navigating in less: · Go down 1 line: Enter · Go down 1 screen: Space or Pg. Down · Go up 1 screen: Pg. Up · Go to beginning of file: Home · Go to end of file: End · Search down: / · Search up: ? · Exit: q (Cntl-c does NOT work!) Introduction to the Shell – Session 1 20

2. 0. 0. 3 – Introduction to the Shell Printing From the Command Line: 2. 0. 0. 3 – Introduction to the Shell Printing From the Command Line: lpr · In an application, you can just hit “print”. What if you just want to quickly print a text file? lpr · Common options: -P[printername] print to specified printer -K[# copies] print specified # copies -V verbose: tells you everything it’s doing · Don’t print a non-text file with lpr! (You will print meaningless symbols, and lots of them) Default printer (and other defaults) You can set the default printer (and all kinds of other cool and useful things) using environment variables – see session 2. 0. 0. 3. 2. Introduction to the Shell – Session 1 21

2. 0. 0. 3 – Introduction to the Shell More About Your Files: stat 2. 0. 0. 3 – Introduction to the Shell More About Your Files: stat (and touch) · UNIX stores more information about a file than just its contents · Size · Owner · Permissions · Modification and access times · To look at this info, use stat · To update a file’s modification touch time, use What’s the –rw-r--r--? These are the file’s permission settings, which determine who can read, write, or execute the file. More on permissions in session 2. 0. 0. 3. 2. Introduction to the Shell – Session 1 22

2. 0. 0. 3 – Introduction to the Shell More About Your Files: file 2. 0. 0. 3 – Introduction to the Shell More About Your Files: file · UNIX does not require 3 -character filetype specifications (eg. wordfile. doc), so just by looking at the name you can’t determine of what type a file is · Instead, use file · Possible types are specified in /usr/share/magic Introduction to the Shell – Session 1 23

2. 0. 0. 3 – Introduction to the Shell A Text File is a 2. 0. 0. 3 – Introduction to the Shell A Text File is a Text File? Using dos 2 unix · Windows-created text files can be read in UNIX and vice versa, but they use different line break characters · Linux uses only the linefeed (n) character · Windows uses both the carriage return (r) and linefeed (n) characters · Result: · Not all Windows programs (eg. Notepad) will correctly display newlines · UNIX programs (eg. xemacs) will display newlines with an extra ^M · View these “hidden” characters with cat -A dos 2 unix · Convert Windows-type to UNIXtype with Introduction to the Shell – Session 1 24

2. 0. 0. 3 – Introduction to the Shell Now Where Did I Put 2. 0. 0. 3 – Introduction to the Shell Now Where Did I Put That? Searching for Files with find · Search for files using Matching name find · Can search entire directory trees · Find based on things like: · Filename (Where did I put that? ) · Last modification time (What was I just working on? ) · Size (What’s taking up so much space? ) · Owner (Is there anything of mine here? ) · Multiple search terms can be Check the man page! combined UNIX commands (especially powerful ones like find) have many options. You are never going to remember them all, so use man often! Modified in last 40 min. Larger than 1000 KB Introduction to the Shell – Session 1 25

2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make 2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make Your UNIX Life Easier: tab · You don’t have to type out those long filenames · Use tab autocompletion · When partway through typing a command, filename, etc. , hit tab · If there is only one name that starts that way, the shell will complete it for you · If there is more than one name, it will list all the possibilities Introduction to the Shell – Session 1 26

2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make 2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make Your UNIX Life Easier: history · You don’t have to retype that complicated command · You can scroll through previous commands by using the up and down arrows · You can see all your previous commands using history · Some options: “text” Cntl-r Cntl-s) history 10 !500 show last command containing “text” (navigate matching commands with Cntl-r and see only last 10 commands repeat command #500 Introduction to the Shell – Session 1 27

2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make 2. 0. 0. 3 – Introduction to the Shell A Few Tips to Make Your UNIX Life Easier: Moving Around and Copy/Paste · Moving the cursor on the command line: · Move to the beginning of a line with Cntl-a · Move to the end of a line with Cntl-e · Copy text from one place to another: · Select the text in one place · Move the mouse place you want to put the text · Press the middle mouse button (or both left and right together, if you don’t have 3 buttons) to paste the text Introduction to the Shell – Session 1 28

2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 Introduction to the Shell – Session 1 · Now you know…. · · · How to form UNIX commands How to create, edit, view, delete, move, copy, find, and learn about files and directories How to learn more with man How UNIX users type so fast (they don’t – they use tab!) Next you’ll learn…. · · · Permissions Customizing your UNIX environment Pipes, redirection, and running command line programs Introduction to the Shell – Session 1 29

2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 2. 0. 0. 3 – Introduction to the Shell 2. 0. 0. 3. 1 Further Readings · Introduction · Learning the UNIX Operating System Ch. 1 · Linux Cookbook Ch. 2 · Files and directories · Learning the UNIX Operating System Ch. 3. 1, 3. 2, 4 · Linux Cookbook Chapter 6 · Viewing and editing text · Learning the UNIX Operating System Ch. 4. 1 · Linux Cookbook Chapter 10, 11 Introduction to the Shell – Session 1 30