26
High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/ High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/ Information Technology Services Alan Scheinine, LaTech Workshop, Oct. 22, 2008 Alan Scheinine, LaTech Workshop, Oct. 22, 2008 Introduction to Linux/Unix Commands and vi Editor Alan L. Scheinine IT Consultant HPC @ LSU October 22, 2008

Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Introduction toLinux/Unix Commands

and vi EditorAlan L. Scheinine

IT ConsultantHPC @ LSU

October 22, 2008

Page 2: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Outline

●The basic Unix/Linux commands.●The vi editor.

Page 3: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

More documentation at

http://www.cct.lsu.edu/~scheinin/UnixVi_Tutorial/index.php

Page 4: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix CommandsLinux is case­sensitive.File name can contain letters, numbers, "." (dot), "_" (underscore), "­" (dash), plus some other characters not recommended.

“/” is equivalent to DOS “\”

A space separates commands and variables, so no spaces in file names, please. “\” protects special characters such as space, ( , ; , & etc.

Page 5: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

Directory commands:cd /home/alan/myprog                    ­­ change dir absolute pathcd dirname  ­­ relative pathpwd                    ­­ print working directorymkdir new_dirname     ­­ make new directory

Page 6: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedFile commands:cp orig_file to_file    ­­ copymv orig_file to_file   ­­ move, removes orig_filerm file ; rm ­r dir   ­­ remove ; remove recursivels                    ­­ list files in current directoryls ­l                 ­­ list with detailsls  /pathname  ­­ list /pathname file or dir

Page 7: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

File commands, more about “ls”:ls ­d   ­­ do not show inside dirs     compare “ ls /* ” with “ ls ­d /* ”ls ­a     ­­ show also .* (leading period)     in $HOME many application write a file     or directory such as .appname

Page 8: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedTo get a description of a filefile /lib/libm.so.6   /lib/libm.so.6: symbolic link to   `libm­2.5.so'file /lib/libm­2.5.so   /lib/libm­2.5.so: ELF 32­bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, not strippedfile /lib64/libm­2.5.so   /lib64/libm­2.5.so: ELF 64­bit LSB shared object, AMD x86­64, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped

Page 9: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedln ­s existing_file link_name  ­­ symbolic linkcat file1 [ file2 file3]    ­­ prints files to standard outputfind /dir many options    ­­ operate on tree of files and dirs under /dirgrep text file_list    ­­ search inside a list of filesmore / less  filename    ­­ view file showing one page at a time.  Examples:cat file | more ; ls * | more ; prog.exe | more

Page 10: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedsed   ­­ command­line editorawk   ­­ pattern scanning and processing languagewc file   ­­ word count or line countwhich executable   ­­ absolute path of executable   which executable depends on order of dirs in PATH

Page 11: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

df  ­­ show all file systems  (disk free)du ­sk   ­­ show sizes of files and dirs             k = 1024 bytes, default 512 B may               cause confusiondu ­sk * | sort ­n  ­­ useful for knowing                           what dirs need cleaning

Page 12: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

head filename   ­­ show top part of filetail filename   ­­ show last part of filetail ­f filename  ­­ continuously shows file as lines are appended (for example, by a program).  However, PBS jobs write in /tmp until job finishes.

Page 13: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

hostname  ­­ in case you have sessions on                      many computersid  ­­ shows your user name and grouptop   ­­ shows jobs running locallyqstat ­u username   ­­ for batch jobsps auxwww | grep keyword

Page 14: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedctrl­u  ­­ before end­of­line ret to cancel linectrl­c   ­­ cancel processEditors:vi (often actually vim, runs in existing text window)emacs [xemacs] (starts its own window, needs ­X tunneling when ssh is used)

Page 15: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedTo know more, local O/S will likely have installed basic information accessible usingman topicinfo topicman ­k keyword     ­­ all topics with keyword in titleman topics include C­language functionscmd ­­help

Page 16: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued

  > file   write standard output to a file 2> file   write standard error to a file >> file    append to a file

Page 17: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continued command &    detach process | (vertical line, “pipe”)     for concatenating commands \  (backslash)     continued onto next line, make sure there is no whitespace character such as blank or tab after the backslash

Page 18: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedtar cvzf file.tar.gz dir  ­­ create tar archivetar xvzf file.tar.gz   ­­­ extract from tar filechmod permissions filelistchmod ­R permissions dirchmod ugo+r file   ­­ anybody can readchmod go­rwx file  ­­ only you can read

Page 19: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Summary of Unix Commands, continuedSession:exit  or  control­D   ­­ exit windowxterm   ­­ new window if ­X tunnellingssh user@machine   ­­ loginhistory  ­­ what you didcontrol­p in bash to go back by one cmd

Page 20: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

$HOME/.bashrc# Source global definitions

if [ ­f /etc/bashrc ]; then

        . /etc/bashrc

fi

# User specific aliases and functions

# Change according to your personal preference.

alias rm='rm ­i'

alias cp='cp ­i'

alias mv='mv ­i'

alias ls='ls ­C ­a ­­color=tty'

alias ll='ls ­C ­a ­­color=tty ­l'

alias vi='vim'  # If O/S has vim.

Page 21: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Setting­up the user environment

Bash shell (bash):~/.bash_profile or ~/.profileand ~/.bashrc and ~/.soft

C shell (tcsh):~/.tcshrc or ~/.cshrcand ~/.login and ~/.soft

Page 22: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

Environmental VariablesTo see environment variables:bash: env    tcsh: setenvPATH and LD_LIBRARY_PATH are important for compiling and running, but on the LONI clusters use file ~/.soft to setup environment.

Page 23: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

vi EditorThe vi editor runs in a terminal in text modeStart: vi filename  (In Linux vi is often “vim”.)Two modes: edit and insert.Begin insert mode: either key “i” (input) or key “a” (append), “o” newline below, “O” newline above.Leave insert mode: key “esc” (escape)Save:  “:w”    Quit: “:q”

Page 24: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

vi Editor, continuedDo not save changes: “:q!”Write ro file: “:w!”Change cursor position with keys hjkl but almost always the arrow keys will move cursor.In general, single letters are commands.Find:  “/keyword”  ,  Find next: “n”Undo previous change: “u”

Page 25: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

vi Editor, continued

Delete previous character: backspace (control­h)Delete current letter: key “x”Delete line: “dd”Delete N lines: “dNd”

Page 26: Information Technology Services Introduction to Linux/Unix ...cct.lsu.edu/~scheinin/UnixVi_Tutorial/linux_cmds.pdf · High Performance Computing @ Louisiana State University - Information

High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/High Performance Computing @ Louisiana State University - http://www.hpc.lsu.edu/Information Technology Services

Alan Scheinine, LaTech Workshop, Oct. 22, 2008Alan Scheinine, LaTech Workshop, Oct. 22, 2008

BooksOnly the titles are listed because full information can be found on web sites such as Amazon, Barnes & Nobel and Borders.

UNIX for Dummies ; Unix in a Nutshell ;Unix Shell Programming ; Learning the vi Editor ;Learning Perl ; sed & awk ; Mastering Unix Shell Scripting ; Guide to UNIX Using Linux ; Learning the UNIX Operating System ; Learning the Vi and Vim Editors ; Learning the Bash Shell