Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
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
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.
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
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 casesensitive.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.
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
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
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
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 `libm2.5.so'file /lib/libm2.5.so /lib/libm2.5.so: ELF 32bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, not strippedfile /lib64/libm2.5.so /lib64/libm2.5.so: ELF 64bit LSB shared object, AMD x8664, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped
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
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 commandline 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
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
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.
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
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, continuedctrlu before endofline ret to cancel linectrlc cancel processEditors:vi (often actually vim, runs in existing text window)emacs [xemacs] (starts its own window, needs X tunneling when ssh is used)
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 Clanguage functionscmd help
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
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
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 gorwx file only you can read
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 controlD exit windowxterm new window if X tunnellingssh user@machine loginhistory what you didcontrolp in bash to go back by one cmd
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.
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
Settingup the user environment
Bash shell (bash):~/.bash_profile or ~/.profileand ~/.bashrc and ~/.soft
C shell (tcsh):~/.tcshrc or ~/.cshrcand ~/.login and ~/.soft
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.
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”
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”
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 (controlh)Delete current letter: key “x”Delete line: “dd”Delete N lines: “dNd”
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