linux basics i - university of delaware · linux basics i mills hpc tutorial series. objectives...

55
Linux Basics I Mills HPC Tutorial Series

Upload: others

Post on 08-Sep-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Linux Basics IMills HPC Tutorial Series

Page 2: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Objectives

● Command Line■ Window Anatomy■ Command Structure■ Command Examples

● Help● Files and Directories● Permissions● Wildcards and Home (~)● Redirection and Pipe● Create and Edit files

Page 3: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Line

Page 4: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Unix Basics

● Multi-user● Case-sensitive● Bash shell, command-line● Commands

Page 5: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Title bar

Click in the title bar to bring the window to the front and make it active.

Page 6: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Login banner

Appears as the first line of a login shell.

Page 7: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Appears at the beginning of a line and usually ends in $.

Prompts

Page 8: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Command input

Place to type commands, which may have options and/or arguments.

Page 9: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Place for command response, which may be many lines long.

Command output

Page 10: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Input cursor

Typed text will appear at the cursor location.

Page 11: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Scroll Bar

Will appear as needed when there are more lines than fit in the window.

Page 12: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Window Anatomy

Resize Handle

Use the mouse to change the window size from the default 80x24.

Page 13: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Structure

command [arguments]● Commands are made up of the actual command and its

arguments

command -options [arguments]● The arguments are further broken down into the

command options which are prefixed by a “-” and other arguments that identify data for the command.

Page 14: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Examples

Try these commands:

Page 15: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

More Command Examples

Try these commands:

Page 16: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Input Keys SummaryAt the command prompt ($), use

return

delete

A

to insert a character.

to erase character to left.

to enter the command.

to move to the left or right.

to retrieve previous command.

Tab for command line completion.

Page 17: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Input Keys Summary

Control-c or Ctrl-c or just C-c interrupts a running program

Control C

Control D Control-d or Ctrl-d or just C-dends text input for many UNIX programs

Control U deletes last line typed

At the command prompt ($), use

Page 18: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Command Output Summary

● Lines longer than the column width are wrapped.

● Lines are scrolled off the top and the prompt will appear at the bottom of the screen.

Use the mouse in the resize handle to increase the width of the screen and unwrap the lines.

Use the mouse in the scroll bar to see lines that have scrolled off the screen.

Page 19: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Help: man, info, apropos

Page 20: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Getting Help

man command● formats and displays on-line manual pages (i.e.,

documentation) for command.

info [subject]● formats and displays online documentation for a

particular subject that are easily searchable.

apropos keyword● searches the whatis database for commands containing

the keyword

Page 21: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Getting Help: man

man bash

Page 22: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Useful Keys: man

B

“Space bar” or 'f' move forward one screenful

‘b' move back one screenful

"Enter" or "Return" move down one line.

Q ‘q’ to quit.

F

Enter

Page 23: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Getting Help: info

info bash

Page 24: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Useful Keys: info

H

L

delete

“Space bar” to read linearly through all sections.

‘h’ special link to help.

Back up after “Space bar”.

‘l’ return from help link.

Q ‘q’ to quit.

Page 25: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Useful Keys: info

tab

L

return

Jump to next link or cross reference.

Back up to previous link.

Follow the link at the cursor.

‘l’ return from link.

Q ‘q’ to quit.

tab

esc

M ‘m’ to go to the menu.

Page 26: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Getting Help: apropos

apropos bash

Page 27: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Files and Directories

Page 28: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Files and Directories

Files● Data in UNIX is stored in files.

Directories● Files are organized hierarchically into directories.● Top-level directory is called “root” represented as a

slash (/).● Every file (and directory) is listed and separated by a

slash (/).

Page 29: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Files and Directories

The UNIX file system is like an inverted tree.

root

/home/its/ug1/ee51vn/report.doc

Page 30: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Files and Directories

List the contents of the current working directory including hidden files with -a

lsls -a

Create a directory called name and change to it, cd by itself always changes to your home directory

mkdir namecd namecd

Print the path of your current working directory

pwd

Page 31: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Working with Directories

Try these commands:

$ ls$ ls -a. .bash_profile .dbus .ssh .xauthAfjiN7.. .bashrc .lesshst .vim .Xauthority.bash_history .bash_udit .sav .viminfo .zshrc.bash_logout .config .smpd .vimrc$ mkdir Mytest$ lsMytest$ cd Mytest$ ls$ pwd/home/1201/Mytest$ cd$ pwd/home/1201$ cd Mytest$

Page 32: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Working with Directories

Rename a directory called name to newname

mv name newname

Remove a directory called name as long as it is empty

rmdir name

Remove the directory called name and everything in it including all files and subdirectories.*

rm -r name

* Note if rm is aliased to "rm -i", then you'll be prompted to examine each file before removing. To avoid this use \rm -r name to override this behavior..

Page 33: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Working with Directories

$ pwd/home/1201/Mytest$ mkdir Mysub1 Mysub2$ lsMysub1 Mysub2$ mv Mysub1 Mysub3$ lsMysub2 Mysub3$ rmdir Mysub2$ lsMysub3$ cd$ ls MytestMysub3$ rmdir Mytestrmdir: failed to remove `Mytest/': Directory not empty$ rm -r Mytest$

Try these commands:

Page 34: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Working with Files

Changes the timestamp of the file called name or creates it

touch name

Copy the file called name to newname

cp name newname

Rename a file called name to newname

mv name newname

Remove the file called name or interactively prompt with -i

rm namerm -i name

Page 35: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Working with Files

$ cd$ touch mytest$ lsmytest$ cp mytest mytest.new$ lsmytest mytest.new$ mv mytest mytest.old$ lsmytest.new mytest.old$ rm mytest.old$ lsmytest.new$ rm -i mytest.newrm: remove regular empty file `mytest.new'? n$ lsmytest.new$

Try these commands:

Page 36: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Permissions

Page 37: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Permissions

Each file or directory has access (rwx) permissions defined for the owner (user), group and others.

● read access - file can be read, directory can be listed

● write access - file contents can be changed, directory contents can be changed (create new, delete and rename files)

● execute access - file can be executed, directory can be changed to (cd into that directory)

● - access - permission denied for that access

-rwxr--r-- man chmod

u g ofile type

Page 38: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Try these commands:

The items in red tell us mytest.new is a file and Mytest is a directory. Both show permissions for user(traine) and group (it_css).

Permissions

$ mkdir Mytest$ lsMytest mytest.new$ ls -l mytest.new-rw-r--r-- 1 traine it_css 0 Aug 21 11:58 mytest.new$ ls -lad Mytest/drwxr-xr-x 2 traine it_css 6 Aug 25 08:43 Mytest/$

Page 39: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Wildcards and Home (~)

Page 40: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Wildcards and Home (~)

$ lsMytest mytest.new$ cp mytest.new Mytest/mytest1.new$ cd Mytest$ lsmytest1.new$ ls ~Mytest mytest.new$ cp ~/mytest.new mytest2.new$ lsmytest1.new mytest2.new$ cp *.new ~/$ cd$ lsMytest mytest1.new mytest2.new mytest.new$ rm mytest?.new$

Try these commands:

Page 41: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Wildcards and Home (~)

$ lsMytest mytest.new$ cp -r Mytest Mytest1$ lsMytest Mytest1 mytest.new$ rm -r Mytest*$ lsmytest.new$

Try these commands:

* rm -r name allows you to remove a directory and all its contents recursively. If you forget the -r it won't work because it is a directory.

Page 42: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Redirection and Pipe

Page 43: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Creating Files: Redirection(STDOUT)

^D (Ctrl-d for EOF)

^D (Ctrl-d for EOF)

Try these commands:

Page 44: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Creating Files: Redirection

Try these commands:

Page 45: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Creating Files: Append and Pipe

^D (Ctrl-d to stop)

Try these commands:

Page 46: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Creating Files: Redirection (STDIN) and Pipe

Try these commands:

Page 47: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Create and Edit Files

Page 48: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Editors

nano● Quick and easy to use

vim (vi)● Uses modes, usually smaller and faster to load, but

not as customizable

emacs● Highly customizable including a large number of

features

Page 49: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

vim Basics

The VIM editor has two modes:

● Command: interprets a letter or sequence of letters as a command.

● Insert: puts anything typed into the file. The ESC key ends insert mode and returns you to command mode.

Command line entry at the bottom of the screen appears when the command “:” is typed. VIM starts up in command mode.

Page 50: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

vim Basics

Start vimvi filenamevi -r filename

End vim:wq, :q, :q!ZZ

Moving aroundh, j, k, lw, e, b

Inserti, a, o, A, OESC - to return to command mode

Deletex, dw, dd

Undou

Page 51: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

vimtutor

The Vim(vi) tutor is useful for people that want to learn their first Vim(vi) commands.

To start the Vim(vi) tutor, type

It copies the tutor file first, so that it can be modified without changing the original file. Takes ~ 25-30 minutes to complete.

$ vimtutor

Page 52: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Exercises

Page 53: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Exercise 1

Review the Unix/Linux Tutorial for Beginners

● Use the exercises at the end of Tutorial One through Five to test your understanding of the material.

● http://www.ee.surrey.ac.uk/Teaching/Unix/

Page 54: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Exercise 2

Choose an editor and complete the tutorial.

● nanohttp://www.udel.edu/001401

● vi (vim)http://www.jerrywang.net/vi/

● emacshttp://www.gnu.org/software/emacs/tour/

Page 55: Linux Basics I - University of Delaware · Linux Basics I Mills HPC Tutorial Series. Objectives Command Line Window Anatomy Command Structure Command Examples Help Files and Directories

Need Help?

● Email: [email protected] you make the first line of the email message

Type=Cluster-Mills

your question will be routed more quickly.

● Phone: (302) 831-6000● Text: (302) 722-6820