36-711 Using Unix

Total Page:16

File Type:pdf, Size:1020Kb

36-711 Using Unix 36-711 Using Unix References: http://www.sun.rhbnc.ac.uk/unix/unix.html, http://www.ussg.iu.edu/usail/index/concepts.html, http://www.mcsr.olemiss.edu/unixhelp/ (Frankly, http://www.google.com is another good choice!) 8 major aspects of Unix 1. Input/Output. This is how UNIX goes about translating data between screens, keyboards, disks, tapes and so on. 2. The Command Interpreter is that part that of the operating system that inter- faces with the user. It deals with keyboard input and calling programs. In UNIX it is called the SHELL. 3. Data Management is that part of the operating system that allows you to use files and directories and the tools to manipulate them. 4. Program Development Tools in UNIX include compilers, debuggers and ed- itors and source code revision systems. There are also many non-essential tools that tend to get added over the years. 5. Time Sharing - UNIX is a time-sharing operating system - time is shared between the processes that can run at any one time. 6. Security - all multiple user operating systems and those that connect to other computers by modems or networks need to consider security. In UNIX this has been designed into the file system. Every user has a username and a group that (s)he belongs to and the users and groups can restrict access to others. 7. Communications - UNIX uses the TCP/Internet suite of protocols, for elec- tronic mail, file transfer, logging on to other machines, etc. 8. Accounting - UNIX provides accounting facilities that are required in a multi-user environment to control resource utilization like CPU time and use of file space. 1 Features of the Kernel Creation and management of processes A filesystem Communications A means to start the system Features of Shells (Command Interpreters) Program execution Variable and filename expansion I/O redirection Pipeline hookup Environment control Interpreted programming language (scripts) There are several common shells: sh, csh, tcsh, bash. You may be able to see which one you are using by typing echo $version. The csh Shell 1. Initialization: .cshrc (.login) 2. Entering commands (a) tab cause filename completion; ctrl-d shows completion list (b) semicolon separates multiple commands (c) arrows, backspace, ctrl-d, ctrl-k, etc. are active (d) end with enter 3. Command interpretation (a) line of command input is read and broken into words by looking for ¢ separating space or &, , ;, ¡ , , (, or ) (b) words are placed on the history list (c) words are parsed: i. history substitution: !!, !n, !str or !?str ii. command alias substitution (alias dir ’ls -al | less’) 2 iii. I/O redirection iv. variable substitution ($str), except inside single quotes v. command substitution (backquotes) ¡ ¢ ¢ vi. filename substitution (*, ?, [...], str,str,... , , user) (d) Find first word, find it in hash table based on $PATH and execute it; remaining words are the command/runstring arguments; terminating ampersand (&) causes program to run in the background (e) ctrl-c cancels a foreground job, ctrl-z suspends a foreground job (f) override special characters with backslash, e.g. \& 4. Built in-commands (not run in a new process) (a) echo, history, printenv (b) alias, unalias, set, unset, setenv, unsetenv (c) jobs, fg, bg, nice, kill (d) exit, popd, pushd, rehash, source (e) if, switch, foreach, while, shift 5. Utility programs (find program file and run in a new process) (a) whoami, apropos, man, whatis, where, which, ps, expr (b) pwd, cd, ls, file, cat, more, less, head, tail, wc (c) mkdir, cp, mv, rm, chmod, rmdir (d) emacs (or xemacs), clean i. Searching: ctrl-s, ctrl-r, alt-% (or esc, %) ii. Files: ctrl-x then ctrl-f, ctrl-r, ctrl-s iii. Splitting: ctrl-x then 2, 1, £ (e) find pathname -name filename [-type d] -print (f) grep [-n -v] what filename (g) sftp, mail, pine, exmh, ssh (h) sort, uniq, diff (i) gcc, f77 6. Redirection (a) stdin, stdout, stderr ¢ ¢ ¡ ¢ (b) ¢ , , , , with &, with grep 3 Shell Scripts (batch files, basic scripting tool) Create with emacs; line 1 is “#!/bin/csh”; do “chmod u+x myname”. # is the comment character To first line, add -n to check only, -v for verbose (before substitution), -x for ver- bose (after substitution). Use $1, $2, etc. for runstring parameters. Use $# for number of runstring parame- ters. ¡ Can use n for newline, t for tab, f for formfeed, for backslash if (myexpression) mycommand if (myexpression) then ... else if (myexpression2) then ... else ... endif In more complicated cases, use switch/endsw. Expressions can use ! for “not”, ==. !=, && for “and”, for “or”, +, -, *, /, and % for “remainder”. (Surround by spaces.) Expressions can include -e myfilename for “file exists”, -d myfilename for “file is a directory”, etc. ¡ The expression mycommand is true if the command executes successfully. Script files often use “set” to create variables. Be sure to precede the variable name with a dollar sign when using it after it is set. Variables can have multiple elements: set junk = (fee fi fo fum) echo $junk[2] set junk = ‘wc ˜/.login‘ echo $junk if ($junk[2] > 20) echo My .login has more than 20 words. shift [myvar] drops the first element from the runstring or myvar. 4 The at sign is used to replace the contents of an existing c-shell variable with the results of a calculation, e.g. set one = 1 set three = 1 @ three = $three + 2 set sum @ sum = $three + $one echo $sum unset one three Other control structures: foreach myvar (mylist) ... end while (myexpression) ... end 5.
Recommended publications
  • Disk Clone Industrial
    Disk Clone Industrial USER MANUAL Ver. 1.0.0 Updated: 9 June 2020 | Contents | ii Contents Legal Statement............................................................................... 4 Introduction......................................................................................4 Cloning Data.................................................................................................................................... 4 Erasing Confidential Data..................................................................................................................5 Disk Clone Overview.......................................................................6 System Requirements....................................................................................................................... 7 Software Licensing........................................................................................................................... 7 Software Updates............................................................................................................................. 8 Getting Started.................................................................................9 Disk Clone Installation and Distribution.......................................................................................... 12 Launching and initial Configuration..................................................................................................12 Navigating Disk Clone.....................................................................................................................14
    [Show full text]
  • Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA
    NESUG 2007 Programming Beyond the Basics Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA ABSTRACT Regular Expression (Regexp) enhance search and replace operations on text. In SAS®, the INDEX, SCAN and SUBSTR functions along with concatenation (||) can be used for simple search and replace operations on static text. These functions lack flexibility and make searching dynamic text difficult, and involve more function calls. Regexp combines most, if not all, of these steps into one expression. This makes code less error prone, easier to maintain, clearer, and can improve performance. This paper will discuss three ways to use Perl Regular Expression in SAS: 1. Use SAS PRX functions; 2. Use Perl Regular Expression with filename statement through a PIPE such as ‘Filename fileref PIPE 'Perl programm'; 3. Use an X command such as ‘X Perl_program’; Three typical uses of regular expressions will also be discussed and example(s) will be presented for each: 1. Test for a pattern of characters within a string; 2. Replace text; 3. Extract a substring. INTRODUCTION Perl is short for “Practical Extraction and Report Language". Larry Wall Created Perl in mid-1980s when he was trying to produce some reports from a Usenet-Nes-like hierarchy of files. Perl tries to fill the gap between low-level programming and high-level programming and it is easy, nearly unlimited, and fast. A regular expression, often called a pattern in Perl, is a template that either matches or does not match a given string. That is, there are an infinite number of possible text strings.
    [Show full text]
  • A First Course to Openfoam
    Basic Shell Scripting Slides from Wei Feinstein HPC User Services LSU HPC & LON [email protected] September 2018 Outline • Introduction to Linux Shell • Shell Scripting Basics • Variables/Special Characters • Arithmetic Operations • Arrays • Beyond Basic Shell Scripting – Flow Control – Functions • Advanced Text Processing Commands (grep, sed, awk) Basic Shell Scripting 2 Linux System Architecture Basic Shell Scripting 3 Linux Shell What is a Shell ▪ An application running on top of the kernel and provides a command line interface to the system ▪ Process user’s commands, gather input from user and execute programs ▪ Types of shell with varied features o sh o csh o ksh o bash o tcsh Basic Shell Scripting 4 Shell Comparison Software sh csh ksh bash tcsh Programming language y y y y y Shell variables y y y y y Command alias n y y y y Command history n y y y y Filename autocompletion n y* y* y y Command line editing n n y* y y Job control n y y y y *: not by default http://www.cis.rit.edu/class/simg211/unixintro/Shell.html Basic Shell Scripting 5 What can you do with a shell? ▪ Check the current shell ▪ echo $SHELL ▪ List available shells on the system ▪ cat /etc/shells ▪ Change to another shell ▪ csh ▪ Date ▪ date ▪ wget: get online files ▪ wget https://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz ▪ Compile and run applications ▪ gcc hello.c –o hello ▪ ./hello ▪ What we need to learn today? o Automation of an entire script of commands! o Use the shell script to run jobs – Write job scripts Basic Shell Scripting 6 Shell Scripting ▪ Script: a program written for a software environment to automate execution of tasks ▪ A series of shell commands put together in a file ▪ When the script is executed, those commands will be executed one line at a time automatically ▪ Shell script is interpreted, not compiled.
    [Show full text]
  • Block Icmp Ping Requests
    Block Icmp Ping Requests Lenard often unpenned stutteringly when pedigreed Barton calques wittingly and forsook her stowage. Garcia is theropod vermiculatedand congregate unprosperously. winningly while nonnegotiable Timothy kedges and sever. Gyrate Fazeel sometimes hasting any magnetron Now we generally adds an email address of icmp block ping requests That after a domain name, feel free scans on or not sent by allowing through to append this friendship request. Might be incremented on your Echo press and the ICMP Echo reply messages are commonly as! Note that ping mechanism blocks ping icmp block not enforced for os. This case you provide personal information on. Send to subvert host directly, without using routing tables. Examples may be blocked these. Existence and capabilities is switched on or disparity the protocol IP protocol suite, but tcp is beat of. We are no latency and that address or another icmp message type of icmp ping so via those command in this information and get you? Before assigning it is almost indistinguishable from. Microsoft Windows found themselves unable to download security updates from Microsoft; Windows Update would boost and eventually time out. Important mechanisms are early when the ICMP protocol is restricted. Cisco device should be valuable so a host that block icmp? Add a normal packet will update would need access and others from. Now check if you? As an organization, you could weigh the risks of allowing this traffic against the risks of denying this traffic and causing potential users troubleshooting difficulties. Icmp block icmp packets. Please select create new know how long it disables a tcp syn flood option available in specific types through stateful firewalls can have old kernels.
    [Show full text]
  • L3pdffield-Choice Module Commands to Create Choice Fields LATEX PDF Management Testphase Bundle
    The l3pdffield-choice module Commands to create choice fields LATEX PDF management testphase bundle The LATEX Project∗ Version 0.95i, released 2021-08-28 1 l3pdffield-choice Introduction This is the documentation for choice fields, for general information about form fields check the documentation l3pdffield. Please keep in mind • Not every PDF viewer supports choice field. • The handling can depend on settings in the PDF viewer. In adobe reader for example I had to disable an option to avoid that it tries to create an appearance itself • Standards like pdf/A disable features of form fields too (as you typically can’t change the PDF). 2 Choice fields Choice fields are drop down menus or scrollable lists where the user can selectoneor more entries. They can also contain a field where users can insert a free text. The export value and the displayed value can differ. Some values can be preselected. This means that various data will have to be set, and the sorting matters. The module here will assume that the various values are stored in sequences: checkifexportoraltname... Only the first sequence is required. Empty values in the display sequence are possible, then the normal value is used. 2.1 Types Choice fields can be a drop down menu (called Combo), which can contain an editable field. setfieldflags={Combo,Edit} or setfieldflags={Combo} If Edit is set, one can also set DoNotSpellCheck. Or they can be a list. ∗E-mail: [email protected] 1 unsetfieldflags={Combo,Edit,DoNotSpellCheck} For both types it is possible to set or unset MultiSelect and CommitOnSelChange.
    [Show full text]
  • Shell Scripting, Scripting Examples
    Last Time… on the website Lecture 6 Shell Scripting What is a shell? • The user interface to the operating system • Functionality: – Execute other programs – Manage files – Manage processes • Full programming language • A program like any other – This is why there are so many shells Shell History • There are many choices for shells • Shell features evolved as UNIX grew Most Commonly Used Shells – /bin/csh C shell – /bin/tcsh Enhanced C Shell – /bin/sh The Bourne Shell / POSIX shell – /bin/ksh Korn shell – /bin/bash Korn shell clone, from GNU Ways to use the shell • Interactively – When you log in, you interactively use the shell • Scripting – A set of shell commands that constitute an executable program Review: UNIX Programs • Means of input: – Program arguments [control information] – Environment variables [state information] – Standard input [data] • Means of output: – Return status code [control information] – Standard out [data] – Standard error [error messages] Shell Scripts • A shell script is a regular text file that contains shell or UNIX commands – Before running it, it must have execute permission: • chmod +x filename • A script can be invoked as: – ksh name [ arg … ] – ksh < name [ args … ] – name [ arg …] Shell Scripts • When a script is run, the kernel determines which shell it is written for by examining the first line of the script – If 1st line starts with #!pathname-of-shell, then it invokes pathname and sends the script as an argument to be interpreted – If #! is not specified, the current shell assumes it is a script in its own language • leads to problems Simple Example #!/bin/sh echo Hello World Scripting vs.
    [Show full text]
  • Unix (And Linux)
    AWK....................................................................................................................................4 BC .....................................................................................................................................11 CHGRP .............................................................................................................................16 CHMOD.............................................................................................................................19 CHOWN ............................................................................................................................26 CP .....................................................................................................................................29 CRON................................................................................................................................34 CSH...................................................................................................................................36 CUT...................................................................................................................................71 DATE ................................................................................................................................75 DF .....................................................................................................................................79 DIFF ..................................................................................................................................84
    [Show full text]
  • Chapter 10 SHELL Substitution and I/O Operations
    Chapter 10 SHELL Substitution and I/O Operations 10.1 Command Substitution Command substitution is the mechanism by which the shell performs a given set of commands and then substitutes their output in the place of the commands. Syntax: The command substitution is performed when a command is given as: `command` When performing command substitution make sure that you are using the backquote, not the single quote character. Example: Command substitution is generally used to assign the output of a command to a variable. Each of the following examples demonstrate command substitution: #!/bin/bash DATE=`date` echo "Date is $DATE" USERS=`who | wc -l` echo "Logged in user are $USERS" UP=`date ; uptime` echo "Uptime is $UP" This will produce following result: Date is Thu Jul 2 03:59:57 MST 2009 Logged in user are 1 Uptime is Thu Jul 2 03:59:57 MST 2009 03:59:57 up 20 days, 14:03, 1 user, load avg: 0.13, 0.07, 0.15 10.2 Shell Input/Output Redirections Most Unix system commands take input from your terminal and send the resulting output back to your terminal. A command normally reads its input from a place called standard input, which happens to be your terminal by default. Similarly, a command normally writes its output to standard output, which is also your terminal by default. Output Redirection: The output from a command normally intended for standard output can be easily diverted to a file instead. This capability is known as output redirection: If the notation > file is appended to any command that normally writes its output to standard output, the output of that command will be written to file instead of your terminal: Check following who command which would redirect complete output of the command in users file.
    [Show full text]
  • Bash Guide for Beginners
    Bash Guide for Beginners Machtelt Garrels Garrels BVBA <tille wants no spam _at_ garrels dot be> Version 1.11 Last updated 20081227 Edition Bash Guide for Beginners Table of Contents Introduction.........................................................................................................................................................1 1. Why this guide?...................................................................................................................................1 2. Who should read this book?.................................................................................................................1 3. New versions, translations and availability.........................................................................................2 4. Revision History..................................................................................................................................2 5. Contributions.......................................................................................................................................3 6. Feedback..............................................................................................................................................3 7. Copyright information.........................................................................................................................3 8. What do you need?...............................................................................................................................4 9. Conventions used in this
    [Show full text]
  • Delimit — Change Delimiter
    Title stata.com #delimit — Change delimiter Description Syntax Remarks and examples Also see Description The #delimit command resets the character that marks the end of a command. It can be used only in do-files or ado-files. Syntax #delimit cr j ; Remarks and examples stata.com #delimit (pronounced pound-delimit) is a Stata preprocessor command. #commands do not generate a return code, nor do they generate ordinary Stata errors. The only error message associated with #commands is “unrecognized #command”. Commands given from the console are always executed when you press the Enter, or Return, key. #delimit cannot be used interactively, so you cannot change Stata’s interactive behavior. Commands in a do-file, however, may be delimited with a carriage return or a semicolon. When a do-file begins, the delimiter is a carriage return. The command ‘#delimit ;’ changes the delimiter to a semicolon. To restore the carriage return delimiter inside a file, use #delimit cr. When a do-file begins execution, the delimiter is automatically set to carriage return, even if it was called from another do-file that set the delimiter to semicolon. Also, the current do-file need not worry about restoring the delimiter to what it was because Stata will do that automatically. Example 1 /* When the do-file begins, the delimiter is carriage return: */ use basedata, clear /* The last command loaded our data. Let's now change the delimiter: */ #delimit ; summarize sex salary ; /* Because the delimiter is semicolon, it does not matter that our command took two lines. We can change the delimiter back: */ 1 2 #delimit — Change delimiter #delimit cr summarize sex salary /* Now our lines once again end on return.
    [Show full text]
  • Introduction to Perl
    Introduction to Perl Science and Technology Support Group High Performance Computing Ohio Supercomputer Center 1224 Kinnear Road Columbus, OH 43212-1163 Introduction to Perl • Setting the Stage • Functions • Data Types • Exercises 3 • Operators • File and Directory Manipulation • Exercises 1 • External Processes • Control Structures • References • Basic I/O • Exercises 4 • Exercises 2 • Some Other Topics of Interest • Regular Expressions • For Further Information 2 Introduction to Perl Setting the Stage • What is Perl? • How to get Perl • Basic Concepts 3 Introduction to Perl What is Perl? • Practical Extraction and Report Language –Or: Pathologically Eclectic Rubbish Lister • Created by Larry Wall • A compiled/interpreted programming language • Combines popular features of the shell, sed, awk and C • Useful for manipulating files, text and processes – Also for sysadmins and CGI • Latest official version is 5.005 – Perl 4.036 still in widespread use –Use perl -v to see the version • Perl is portable •Perlis free! 4 Introduction to Perl How to Get Perl • Perl’s most natural “habitat” is UNIX • Has been ported to most other systems as well – MS Windows, Macintosh, VMS, OS/2, Amiga… • Available for free under the GNU Public License – Basically says you can only distribute binaries of Perl if you also make the source code available, including the source to any modifications you may have made • Can download source code (C) and compile yourself (unlikely to be necessary) • Pre-compiled binaries also available for most systems • Support available
    [Show full text]
  • [D:]Path[...] Data Files
    Command Syntax Comments APPEND APPEND ; Displays or sets the search path for APPEND [d:]path[;][d:]path[...] data files. DOS will search the specified APPEND [/X:on|off][/path:on|off] [/E] path(s) if the file is not found in the current path. ASSIGN ASSIGN x=y [...] /sta Redirects disk drive requests to a different drive. ATTRIB ATTRIB [d:][path]filename [/S] Sets or displays the read-only, archive, ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] [d:][path]filename [/S] system, and hidden attributes of a file or directory. BACKUP BACKUP d:[path][filename] d:[/S][/M][/A][/F:(size)] [/P][/D:date] [/T:time] Makes a backup copy of one or more [/L:[path]filename] files. (In DOS Version 6, this program is stored on the DOS supplemental disk.) BREAK BREAK =on|off Used from the DOS prompt or in a batch file or in the CONFIG.SYS file to set (or display) whether or not DOS should check for a Ctrl + Break key combination. BUFFERS BUFFERS=(number),(read-ahead number) Used in the CONFIG.SYS file to set the number of disk buffers (number) that will be available for use during data input. Also used to set a value for the number of sectors to be read in advance (read-ahead) during data input operations. CALL CALL [d:][path]batchfilename [options] Calls another batch file and then returns to current batch file to continue. CHCP CHCP (codepage) Displays the current code page or changes the code page that DOS will use. CHDIR CHDIR (CD) [d:]path Displays working (current) directory CHDIR (CD)[..] and/or changes to a different directory.
    [Show full text]