Introduction to Linux Xiaoxu Guan High Performance Computing, LSU January 31, 2018

Introduction to Linux Xiaoxu Guan High Performance Computing, LSU January 31, 2018

p. 1/40 Introduction to Linux Xiaoxu Guan High Performance Computing, LSU January 31, 2018 Information Technology Services LSU HPC Training Series, Spring 2018 p. 2/40 Outline • What is an OS or Linux OS? • Basic commands for files/directories • Basic commands for text processing • Linux globbing wildcards • The process basics • File permission and management • Basic vi/vim editing Information Technology Services LSU HPC Training Series, Spring 2018 p. 3/40 What is an Operating System (OS)? • An OS is a software suite that controls and manages a computer’s hardware along with providing a platform or environment we can run applications and programs on; • Essential features on most systems: ◦ Manage and maintain memory system (load applications, allocate and free up memory space); ◦ Provide low-level support to interact with hardware (system calls); ◦ Support Input/Output (I/O); ◦ Multi-task OS even on a single-core system; ◦ A modern OS is multi-tasking, multi-user, and multi-processing system; ◦ Environment (CLI/GUI) supporting a user interaction with OS; Information Technology Services LSU HPC Training Series, Spring 2018 p. 4/40 Linux and Unix • Unix was created by Ken Thompson, Dennis Richie, and others (Bell Labs) in C in the late 1960s and early 1970s; • A variety of UNIX systems available: AIX (IBM), HP-UX (HP), IRIX (SGI), Solaris (SUN), BSD, MINIX, . .; • Most Unix systems are commercial; • Linux kernel was created by Linus Torvalds in 1991 in C and it was greatly influenced by MINIX; • “Linux is a Unix clone written from scratch ...” • Linux has a number of distributions: Red Hat, CentOS, Debian, SUSE, Ubuntu, . .; • Almost 97% of HPC clusters (TOP 500) are based on Linux; • Linux is free[doom] (nothing to do with price)! • Richard Stallman’s GNU Project; Information Technology Services LSU HPC Training Series, Spring 2018 p. 5/40 Basic commands for files/directories (ls, pwd, cd, cp, mv, rm, mkdir, and rmdir) Information Technology Services LSU HPC Training Series, Spring 2018 p. 6/40 Basic commands for files/directories • How to login to a cluster (without X11-Forwarding): • $ ssh [email protected] • $ ssh -l username qb.loni.org Command Explanation ls list information for files and directories pwd show the work directory cd change to a directory cp copy files or directories mv rename files or directories rm remove files or directories mkdir make a new directory rmdir remove a directory Information Technology Services LSU HPC Training Series, Spring 2018 p. 7/40 The ls command • The ls command is used to list files and directories; Option Explanation -a list all files including hidden files (beginning with a dot) -F mark directories, exes, and links separately -r sort the list in reverse order -l long format with 7 attributes -d list only directories -t sort the list by last modification time • Without any options, the default list is ordered in sequence of numbers, uppercase and lowercase; • Our alias for ls is ls –color=auto to mark files, dirs and exes in different colors; Information Technology Services LSU HPC Training Series, Spring 2018 p. 8/40 cd, pwd, and relative pathnames • The cd command: change directroy; • The pwd command: print work directroy; • Relative pathnames: ◦ A single dot (.) is for the current directory; ◦ A double dot (..) is for the parent directory; ◦ All pathnames that begin with the above symbols are called relative pathnames; $ pwd /home/xiaoxu/dir1/dir2/source_code $ cd .. ; pwd /home/xiaoxu/dir1/dir2 $ cd source_code $ cd ../../ ; pwd /home/xiaoxu/dir1 Information Technology Services LSU HPC Training Series, Spring 2018 p. 9/40 Rename and remove commands • The mv command: move file and directories (rename); $ mv my.dat ../. $ mv my.dat my.dat.bak $ mv mydir mydir.orgi • The rm command: remv files and directories (unlink filename and data); $ rm my.dat $ rm -i my.dat $ rm ../source_code/parameters.h $ rm -r mydir $ rm -rf mydir • rm supports many flags: -i (prompt before removing), -f (never prompt before removing); • The above two commands work on both files and directories; Information Technology Services LSU HPC Training Series, Spring 2018 p. 10/40 Making and removing directories • The mkdir (make directory) command creates new directories; $ mkdir test $ mkdir bin examples doc • The rmdir (remove directory) command removes existing directories; • Directories can also be removed with the rm command; $ rmdir doc $ rmdir doc bin • Some common errors: $ mkdir: cannot create directory ‘mydir’: File exists $ rmdir: failed to remove ‘emtest’: Dir. not empty Information Technology Services LSU HPC Training Series, Spring 2018 p. 11/40 Basic commands for text processing (head, tail, cat, less, and more) Information Technology Services LSU HPC Training Series, Spring 2018 p. 12/40 Basic commands for text processing • Basic commands for text processing: Command Explanation head display the beginning part of text file tail display the bottom part of text file cat display, combine, or create text files tac inverse of cat less view text files more view text files Information Technology Services LSU HPC Training Series, Spring 2018 p. 13/40 The head and tail commands • The head command shows the beginning part of a text file; $ head my.dat # default is top 10 lines. $ head -20 my.dat # show top 20 lines. $ head -n 20 my.dat # show top 20 lines. $ head 20 my.dat # what happens to this one? • The tail command shows the bottom part of a text file; $ tail my.dat # default is last 10 lines. $ tail -20 my.dat # show last 20 lines. $ tail -n 20 my.dat # same last 20 lines. • What happens if I don’t how many lines to head or tail? $ head -n -2 my.dat # all lines except last 2 lines -n -. # all lines except the top 3 lines -n +. $ tail -n +4 my.dat Information Technology Services LSU HPC Training Series, Spring 2018 p. 14/40 The cat and tac commands • The cat and tac commands can view, create, copy, and combine text files; $ cat my.dat $ cat my.dat > mynew.dat # redirect to a new file. # combine them into a new file. $ cat a.out aa.out b.out > allout.dat # combine them into a new file. $ cat my[0-9].dat > mynew.dat $ cat > my.dat # create an empty file. • What is tac? $ tac my.dat # inverse of cat. Information Technology Services LSU HPC Training Series, Spring 2018 p. 15/40 The less command • View text files without directly opening it (page based): $ less [options] filename # start with 10th line from the beginning: $ less +10 myroutine.f90 ◦ Page navigation: Spacebar or f to next page (b for backward); ◦ Forward search mode: /pattern (n for next match, N for previous match). Backward search mode: ?pattern (n for next match, N for previous match); ◦ Jump to the start of file: g, Jump to the end of file: G ◦ File information: = ◦ Quit: q ◦ Useful to pipe output to the less command; Information Technology Services LSU HPC Training Series, Spring 2018 p. 16/40 Linux globbing wildcards (?, *, [], and [!]) Information Technology Services LSU HPC Training Series, Spring 2018 p. 17/40 Globbing wildcards • Two types of wildcards: (1) globbing wildcards (2) regular expressions (regex) • Globbing wildcards are used by commands on multiple files names; • Regex handles content of text files (searching, parsing, or manipulation); • Six globbing wildcards: ?, *, [], [!], {}, and \ ◦ ? (question mark): any single character; ◦ * (asterisk): any number (including zero) of characters (except a leading dot in hidden file names); ◦ [] (square brackets): one character in a list or range; ◦ [!]: negate of []; ◦ . Information Technology Services LSU HPC Training Series, Spring 2018 p. 18/40 Globbing wildcards $ ls ?.dat $ ls -ltr abc?? $ ls * $ ls *.???? $ rm out*.dat $ cat o[a,t,i]d $ ls -ltr o[a-c]d $ ls -ltr *[a-c]* $ rm -f a*[0-9][0-9][0-9] $ mv ../[!a-d]*.out . $ ls -ltr a*[!0-9][!0-9][!0-9] Information Technology Services LSU HPC Training Series, Spring 2018 p. 19/40 The process basics (ps, kill, bg, fg, and jobs) Information Technology Services LSU HPC Training Series, Spring 2018 p. 20/40 The process basics • A program is an executable file held in storage; It can be a binary file or a type of script file; • A process is an executing or running instance of a program (also known as task); It has a lifetime; • A process can create other new processes (child processes); • A process has many attributes including security attributes and state (pid, ppid, uname, rss, etime, tty, cmd, etc); • A process can run in the background or in the foreground; • Linux kernel handles processes including scheduling, maintaining state and security attributes, allocating memory space, and other resources; Information Technology Services LSU HPC Training Series, Spring 2018 p. 21/40 Basic commands for process management Command Explanation ps provide info for current processes jobs display current status of jobs bg resume stopped jobs and run them in background fg resume stopped jobs and rum them in foreground kill kill processes by sending signals Information Technology Services LSU HPC Training Series, Spring 2018 p. 22/40 The ps command • The ps (process status) command provides a lot of info about current processes; • A process can have many attributes pid, ppid, uname, rss, etime, tty, cmd, etc; $ ps [options] • ps supports both GNU syntax (with -), BSD syntax (w/o -), and long option syntax (with --); $ ps ax # list all processes (a). $ ps -e # list every process (-e). $ ps aux # list all process with details (username u). $ ps -ef # list every process with details (-f). Information Technology Services LSU HPC Training Series, Spring 2018 p. 23/40 The ps command # list all processes of a user (-u) with details. $ ps -u xiaoxu -f $ ps -C bash # search the process by command name.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    40 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us