More regular expressions, synchronizing data, comparing files

Size: px
Start display at page:

Download "More regular expressions, synchronizing data, comparing files"

Transcription

1 More regular expressions, synchronizing data, comparing files Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP

2 Regular expressions POSIX regular expressions are divided in two sets: basic and extended The frst thing about regexes: anything is a regex; in the case of regular strings, like banana, a regex composed exclusively of literal characters Metacharacters, on the other hand, have special meanings and are responsible for the fexibility and power of regexes The metacharacters in basic regular expressions are: ^. [ ] $ *

3 Regular expressions As can be seen, some of these metacharacters have special meaning to the shell as well, so it is essential to enclose a regex in quotes to avoid trouble The meanings of the metacharacters for basic POSIX regexes are:. : any one character (including the period itself) ^ and $ : anchors to the beginning or end of the line, respectively [ and ] : enclose a character class, as we ve seen before (using the dash gives us a range, e.g., [a-z]); within these, the ^ means negation * : zero or more occurrences of something specifc As we saw earlier, the meaning of a metacharacter can change depending on where it occurs!

4 Regular expressions The caret (^) only has special meaning when it is either: The first character in the regex (in which case it is an anchor, it represents the beginning of the line) Or the first character aftter the [ that starts a character class (in which case it means negation: match characters that are not in the class) In any other place, a caret is literally just a caret The same happens with the other anchor: the $ sign In this case, the sign has just one special meaning: it represents the end of the line, but only if it is the last character in the regex Anywhere else in the pattern, the dollar sign just matches a dollar sign

5 Examples '[i^g]' : will match lines that contain i and/or ^ and/or g '[^ig]' : will match lines that contain characters other than i and g (even if those line also contain i and/or g) '^[ig]' : will match lines that start in i or g '[ig$]' : will match lines that contain i and/or $ and/or g '[ig]$' : will match lines that end in i or g Except for - and an initial ^, all other metacharacters lose their special meanings when between [ and ] Between characters in a class, the - sign behaves the same way as in shell expansions: it means a range oft characters, e.g., [a-z]

6 Quiz time! Go to the Moodle site and choose Quiz 30 (beware time limits!)

7 We have seen the Basic Regular Expressions (BRE) in the POSIX standard But there are also Extended Regular Expressions (ERE) available in POSIX Regular expressions The ERE include everything that is in the BRE and adds a few more metacharacters Again, the metacharacters in BRE are: ^. [ ] $ * The ERE include, in addition: ( ) { }? +

8 Regular expressions Now we have the full set: ^. [ ] $ * ( ) { }? + Again, some of the metacharacters have special meanings to the shell, so always enclose the regex in quotes The ERE metacharaters have the following meanings: : alternation, or; A B C means match A or B or C ( ) : group some parts of the regex, and save the match? : match an element zero or one time + : match an element one or more times { } : match an element a specific number (or a range) of times

9 Important! What if one wants to search the text for characters that are usually metacharacters? We have to escape them, as mentioned last week Escaping strips the metacharacter of its special powers Escaping is done by putting a back-slash (\) before the character: '\(..(aa bb cc)\)' : will match a ( followed by two characters and either aa or bb or cc and a ) Putting the back-slash before a character that is not a metacharacter, on the other hand, can change its meaning, for some tools! For example: \n : line break \1 : back reference

10 Regular expressions The ( ) can group parts of the regex, like in arithmetic operations: ^aa bb cc is diferent from ^(aa bb cc) The frst: match lines that (start with aa) or (contain bb) or (contain cc) The second: match lines that (start with aa) or (start with bb) or (start with cc) The matches to the subexpressions created when the ( ) is used will be saved and can be accessed in back refterences called \1, \2, \3 etc. (for the frst, second, third etc. subexpressions) Example: '([i^g])..(aa bb cc)' : will save any matches to '[i^g]' in \1 and any matches to 'aa bb cc' in \2 Back references can be useful in substitutions, for example, by sed

11 A sed example Let s say you have fle /data/distros, which has dates in the third column (in the remote server, ) However, the dates are in a format you do not like; for example: Fedora 10 11/25/2008 You would prefer to have those dates written in the YYYY-MM-DD format sed can, with one (ugly) command, do that editing all at once: sed -r 's/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/\3-\1-\2/' /data/distros See that we have used an option (-r) to tell the program to use extended regular expressions We also had to escape the / character, writing it as \/ instead sed can use other characters to separate the regex and replacement: sed -r 's#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#' /data/distros

12 A sed example sed -r 's#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#' /data/distros Let s dissect that example, looking just at the regex: 's#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#' substitution command, using # as separator ([0-9]{2}) ([0-9]{2}) ([0-9]{4}) \3-\1-\2 match 2 digits, match 2 digits, match 4 digits, replacement, put in \1 put in \2 put in \3 with - between each match

13 A sed example All of the following work just as well: 's#([0-9]{2})/([0-9]{2})/([0-9]{4})#\3-\1-\2#' 's*([0-9]{2})/([0-9]{2})/([0-9]{4})*\3-\1-\2*' 's%([0-9]{2})/([0-9]{2})/([0-9]{4})%\3-\1-\2%' 's ([0-9]{2})/([0-9]{2})/([0-9]{4}) \3-\1-\2 ' 's.([0-9]{2})/([0-9]{2})/([0-9]{4}).\3-\1-\2.' etc. etc. etc. But: 's/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/\3-\1-\2/'

14 Regular expressions Some programs support just basic regular expressions, but other support those plus the extended ones Sometimes, it is necessary to tell the program which kind of regex you want it to use For grep, one can explicitly ftorce the use of BRE with the -G option, or of ERE with the -E option; alternatively, you can use the egrep command, and always use ERE sed uses BRE by default, but the -r option turns on ERE support

15 Regular expressions As seen earlier, {2} specifes that a match requires two occurrences of the character (or group of characters, if parentheses are used) But the { } metacharacters can also specifes ranges or a minimum or maximum number of occurrences Some examples of the quantifcation formats are: 'a{4,8}' : match if there are 4 to 8 letters a in sequence 'a{,4}' : match if there are up to 4 letters a in sequence 'a{4,}' : match if there are at least 4 letters a in sequence 'a{4}' : match if there are 4 letters a in sequence Notice that, if you use just the pattern 'a{,4}' above, for example, string aaaaaaa will match! That is because we have said nothing about what comes aftter the up to 4 letters a that we required

16 Quiz time! Go to the Moodle site and choose Quiz 31 (beware time limits!)

17 Now you do it! Go to the Moodle site, Practical Exercise 29 Follow the instructions to answer the questions in the exercise (and beware any time limits!) Remember: in the PE, you should do things in practice before answering the question!

18 Syncing data We have learned how to transfter data to and ftrom remote computers, specially using scp While a great tool, scp always copies everything you tell it to Wait Isn't that what we want anyway!? Actually, there is a better way: transferring only what has been updated after the previous transfer The rsync program is a great Unix tool for mirroring and backing up directories rsync can sync local and remote files, and its commands take the form: rsync options source destination The source and destination fles can be either local-local, local-remote, or remote-local (but not remote-remote)

19 Syncing data rsync frequently uses a few options : -a : archive mode, short-hand for several options most importantly, recursive copy and keep permissions (see man page) -z : compress data on-the-fy for transfer; more use for transfers over the network -v : verbose messages, gives details of the sync and a summary when the operation has fnished As usual, the options can be combined, for example: rsync -azv local_dir computer_name:remote_dir It is customary to create cron jobs to periodically and automatically run rsync commands that synchronize data between machines or between a machine and external storage, for example

20 Syncing data Try it on the remote server ( ) Let's sync a local directory into your home directory: time rsync -av /data/jc JC The time command is not needed! It is here just to measure how long it took to run the command that comes after it There was no JC directory in your area; rsync automatically creates a destination directory if it does not exist Since this is a transfer within the same computer, the -z option is not necessary; but does it hurt to use it? Try it! Now that you know the time that it took to sync the data without compression, either delete the JC directory created in your area or use a diferent destination (e.g., JC2), and run rsync again, this time with -z

21 Syncing data If you did everything correctly, you must have noticed that using compression took about 10 times more time than not Compressing the data takes time, so it is only worth doing if you are transferring data to a remote computer, using a slow network connection What happens if you now try to sync the data to a directory where you have already saved it previously? Do it! In our example: rsync -av /data/jc JC As you can see, nothing was copied this time; rsync looks for updated fles (looking at modifcation time stamps) and only copies those

22 About time Now, let s look at a few (other) CLI commands that deal with time There is one command that simply waits for a certain amount of time: sleep sleep has no options (besides --help and --version, a.k.a the common options of the core utilities package) ; it only takes the time to wait: sleep 10 Will wait 10 seconds before returning the prompt sleep 5m ; echo 'BOOM!' Will wait 5 minutes before running echo The deftault unit is seconds (s), but one can also use minutes (m), hours (h) or days (d)

23 Quick parenthesis... ( ) To emphasize what we saw in the previous slide: you can give the system more than one command at once Separate the two or more diferent commands with a semicolon, i.e., ; As seen ealier: sleep 5m ; echo 'BOOM!' Will tell the system to run the two commands, one after the other, independently There is no redirection or any other infuence of the command preceding the semicolon on the one after it

24 About time We have seen the time command, which tells us how long it took for a command to run There is another command in Unix that tells the system to stop executing a program if it has not fnished running after a certain amount of time: timeout Like time, timeout is placed right before the command it will afect The main option is the amount of time (by default, in seconds) timeout 2d command -x filex Will run the hypothetical program command (with option -x, on fle filex) for no more than two days If the program fnishes beftore that deadline, timeout does not do anything; otherwise, it kills the program

25 About time The date command allows us to perform some operations on dates Without any options, date prints the current date and time in the system With the +%s option (and nothing else), date prints the number of seconds since :00:00 UTC (the Unix epoch) The -d option specifes which date to use (default is today); for example: Will print: date -d ' ' Mon Jan 1 00:00:00 BRST 2018

26 About time date also understands human language ; for example: date -d '180 days' date -d '37000 minutes ago' date -d '-10 days 5 hours' +%s option is a ftormat option, and there are many such formats available for date (see the man page) For example: date -d 'Jun 14' +%j Will print 165: June 14 th is day number 165 in the year

27 About time Another useful tool for dealing with dates is cal or ncal It can print calendars and, in the case of ncal, the date of Easter ncal -e 2017 cal 10 cal cal -3 These commands print, respectively: the date of Easter Sunday in 2017; the calendar for year 10 (yes, 2008 years ago); the calendar for October 2018; and the calendar for this month, the previous and the next It is also possible to display the old Julian calendar

28 About time Yet another tool for dealing with time is tzselect (time zone selection) This tool allows one to fnd the ofcial name (in English) of any time zone, as well as see the current time there tzselect does not take any options, but is rather an interactive program Try it on the remote server: tzselect...and follow the instructions on the screen As can be seen, the program also accepts geographical coordinates (latitude and longitude)

29 Now you do it! Go to the Moodle site, Practical Exercise 30 Follow the instructions to answer the questions in the exercise (and beware any time limits!) Remember: in the PE, you should do things in practice before answering the question!

30 Comparing file content It is often useful to see what the diferences (or commonalities) between two text fle are The comm program accepts two sorted fles and prints out three columns: Lines unique to the frst fle Lines unique to the second fle Lines common to both fles comm can be specially useful when one has two long lists of items to compare Example: comm -3 file1 file2

31 Comparing file content comm -3 file1 file2 This will output only the lines that are unique to file1 and to file2, but not those that are shared by both fles Try it! In the remote server, run: comm -3 /data/file_coma /data/file_comb This will print in one column all lines that are unique to file_coma and, in the other, all that are unique to file_comb 1 2 w 3 h s

32 Comparing file content While comm is quite useful, it is not very powerful The diff program is used a lot, specially by programmers (e.g., comparing diferent source code versions) and system administrators (e.g., comparing confguration fles), to compare fles Diferently from comm, for diff fles do not need to be sorted actually, they should not be sorted just in order to run diff! diff is used to create the so-called dif file, which allows us to use another tool (patch) to transftorm one file into the other There are many options to control what should be taken into account when comparing fles: how to treat blank space, empty lines, case sensitivity etc. diff can compare ftull directories (and their subdirectories, recursively, if told to), fle by fle

33 Comparing file content The main advantages of a dif (or patch) fle are that: It is very small compared to the full size of the original fles It concisely shows the changes between the fles, allowing one to quickly evaluate the diferences diff can list the diferences between two fles in diferent ways: Deftault ftormat, the shortest (but hardest to read) Context ftormat, shows lines around the changes, for context Unified ftormat, eliminates redundancies of the context format Let s try! In the remote server, run: diff /data/darwin_1 /data/darwin_2

34 Quiz time! Go to the Moodle site and choose Quiz 32 (beware time limits!)

35 Now you do it! Go to the Moodle site, Practical Exercise 31 Follow the instructions to answer the questions in the exercise (and beware any time limits!) Remember: in the PE, you should do things in practice before answering the question!

36 Recap Extended regular expressions (ERE) include a few more capabilities to the basic set: ( ) { } +? egrep or grep -E and sed -r are able to use ERE in searching and editing of text fles rsync is a great tool for incremental transfter of data (i.e., only transfer what has changed), and is thus used a lot for backups Transfers within the same machine, i.e., disks connected to the same computer, should not use compression (-z): it is much slower in this case! Linux has several tools to deal with time time measures how long it took for a command to run timeout stops a program if it is not fnished before a certain amount of time

37 Recap tzselect gives information about time zones and the current time anywhere in the world cal and ncal show calendars and the day of Easter (ncal only) date does several operations and calculations on dates and times sleep simply sleeps for a given period of time, working as a timer Comparing the contents of text fles is an important task comm compares two previously sorted fles and lists which lines are unique or shared diff is the main text fle comparison tool in the Unix world, and has three output styles: deftault, context, and unified It is used a lot to distribute program source code updates, which can be applied with the patch program

Links, basic file manipulation, environmental variables, executing programs out of $PATH

Links, basic file manipulation, environmental variables, executing programs out of $PATH Links, basic file manipulation, environmental variables, executing programs out of $PATH Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP The $PATH PATH (which

More information

More text file manipulation: sorting, cutting, pasting, joining, subsetting,

More text file manipulation: sorting, cutting, pasting, joining, subsetting, More text file manipulation: sorting, cutting, pasting, joining, subsetting, Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Inverse cat Last week we learned

More information

Removing files and directories, finding files and directories, controlling programs

Removing files and directories, finding files and directories, controlling programs Removing files and directories, finding files and directories, controlling programs Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Removing files Files can

More information

Finding files and directories (advanced), standard streams, piping

Finding files and directories (advanced), standard streams, piping Finding files and directories (advanced), standard streams, piping Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Finding files or directories When you have

More information

Regular Expressions. Regular expressions match input within a line Regular expressions are very different than shell meta-characters.

Regular Expressions. Regular expressions match input within a line Regular expressions are very different than shell meta-characters. ULI101 Week 09 Week Overview Regular expressions basics Literal matching.wildcard Delimiters Character classes * repetition symbol Grouping Anchoring Search Search and replace in vi Regular Expressions

More information

My Favorite bash Tips and Tricks

My Favorite bash Tips and Tricks 1 of 6 6/18/2006 7:44 PM My Favorite bash Tips and Tricks Prentice Bisbal Abstract Save a lot of typing with these handy bash features you won't find in an old-fashioned UNIX shell. bash, or the Bourne

More information

CST Lab #5. Student Name: Student Number: Lab section:

CST Lab #5. Student Name: Student Number: Lab section: CST8177 - Lab #5 Student Name: Student Number: Lab section: Working with Regular Expressions (aka regex or RE) In-Lab Demo - List all the non-user accounts in /etc/passwd that use /sbin as their home directory.

More information

FILTERS USING REGULAR EXPRESSIONS grep and sed

FILTERS USING REGULAR EXPRESSIONS grep and sed FILTERS USING REGULAR EXPRESSIONS grep and sed We often need to search a file for a pattern, either to see the lines containing (or not containing) it or to have it replaced with something else. This chapter

More information

UNIX files searching, and other interrogation techniques

UNIX files searching, and other interrogation techniques UNIX files searching, and other interrogation techniques Ways to examine the contents of files. How to find files when you don't know how their exact location. Ways of searching files for text patterns.

More information

Exploring the system, investigating hardware & system resources

Exploring the system, investigating hardware & system resources Exploring the system, investigating hardware & system resources Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Ctrl+c/Ctrl+v in the shell? Paste, in Gnome

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal Lecture 3 Tonight we dine in shell Hands-On Unix System Administration DeCal 2012-09-17 Review $1, $2,...; $@, $*, $#, $0, $? environment variables env, export $HOME, $PATH $PS1=n\[\e[0;31m\]\u\[\e[m\]@\[\e[1;34m\]\w

More information

CS Unix Tools & Scripting

CS Unix Tools & Scripting Cornell University, Spring 2014 1 February 24, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater A note on awk for (item in array) The order in which items are returned

More information

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois Unix/Linux Primer Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois August 25, 2017 This primer is designed to introduce basic UNIX/Linux concepts and commands. No

More information

Pattern Matching. An Introduction to File Globs and Regular Expressions

Pattern Matching. An Introduction to File Globs and Regular Expressions Pattern Matching An Introduction to File Globs and Regular Expressions Copyright 2006 2009 Stewart Weiss The danger that lies ahead Much to your disadvantage, there are two different forms of patterns

More information

Pattern Matching. An Introduction to File Globs and Regular Expressions. Adapted from Practical Unix and Programming Hunter College

Pattern Matching. An Introduction to File Globs and Regular Expressions. Adapted from Practical Unix and Programming Hunter College Pattern Matching An Introduction to File Globs and Regular Expressions Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss The danger that lies ahead Much to your

More information

ITST Searching, Extracting & Archiving Data

ITST Searching, Extracting & Archiving Data ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the

More information

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 Hi everyone once again welcome to this lecture we are actually the course is Linux programming and scripting we have been talking about the Perl, Perl

More information

CS Unix Tools & Scripting Lecture 7 Working with Stream

CS Unix Tools & Scripting Lecture 7 Working with Stream CS2043 - Unix Tools & Scripting Lecture 7 Working with Streams Spring 2015 1 February 4, 2015 1 based on slides by Hussam Abu-Libdeh, Bruno Abrahao and David Slater over the years Announcements Course

More information

Lecture 5. Essential skills for bioinformatics: Unix/Linux

Lecture 5. Essential skills for bioinformatics: Unix/Linux Lecture 5 Essential skills for bioinformatics: Unix/Linux UNIX DATA TOOLS Text processing with awk We have illustrated two ways awk can come in handy: Filtering data using rules that can combine regular

More information

Shell Programming Overview

Shell Programming Overview Overview Shell programming is a way of taking several command line instructions that you would use in a Unix command prompt and incorporating them into one program. There are many versions of Unix. Some

More information

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns Perl Regular Expressions Unlike most programming languages, Perl has builtin support for matching strings using regular expressions called patterns, which are similar to the regular expressions used in

More information

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Objective: Learn some basic aspects of the UNIX operating system and how to use it. What is UNIX? UNIX is the operating system used by most computers

More information

Essentials for Scientific Computing: Stream editing with sed and awk

Essentials for Scientific Computing: Stream editing with sed and awk Essentials for Scientific Computing: Stream editing with sed and awk Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Stream Editing sed and awk are stream processing commands. What this means is that they are

More information

Regular Expressions Explained

Regular Expressions Explained Found at: http://publish.ez.no/article/articleprint/11/ Regular Expressions Explained Author: Jan Borsodi Publishing date: 30.10.2000 18:02 This article will give you an introduction to the world of regular

More information

Wildcards and Regular Expressions

Wildcards and Regular Expressions CSCI 2132: Software Development Wildcards and Regular Expressions Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Searching Problem: Find all files whose names match a certain

More information

computer user has lost data at some point, perhaps because of a corrupted file or accidental

computer user has lost data at some point, perhaps because of a corrupted file or accidental CHAPTER 31 Backing Up Data Every computer user knows that backing up data is vital. This is usually because every computer user has lost data at some point, perhaps because of a corrupted file or accidental

More information

COMS 6100 Class Notes 3

COMS 6100 Class Notes 3 COMS 6100 Class Notes 3 Daniel Solus September 1, 2016 1 General Remarks The class was split into two main sections. We finished our introduction to Linux commands by reviewing Linux commands I and II

More information

CST8207: GNU/Linux Operating Systems I Lab Ten Boot Process and GRUB. Boot Process and GRUB

CST8207: GNU/Linux Operating Systems I Lab Ten Boot Process and GRUB. Boot Process and GRUB Student Name: Lab Section: Boot Process and GRUB 1 Due Date - Upload to Blackboard by 8:30am Monday April 16, 2012 Submit the completed lab to Blackboard following the Rules for submitting Online Labs

More information

Lecture 5. Additional useful commands. COP 3353 Introduction to UNIX

Lecture 5. Additional useful commands. COP 3353 Introduction to UNIX Lecture 5 Additional useful commands COP 3353 Introduction to UNIX diff diff compares two text files ( can also be used on directories) and prints the lines for which the files differ. The format is as

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

2) clear :- It clears the terminal screen. Syntax :- clear

2) clear :- It clears the terminal screen. Syntax :- clear 1) cal :- Displays a calendar Syntax:- cal [options] [ month ] [year] cal displays a simple calendar. If arguments are not specified, the current month is displayed. In addition to cal, the ncal command

More information

Unix Tools / Command Line

Unix Tools / Command Line Unix Tools / Command Line An Intro 1 Basic Commands / Utilities I expect you already know most of these: ls list directories common options: -l, -F, -a mkdir, rmdir make or remove a directory mv move/rename

More information

do shell script in AppleScript

do shell script in AppleScript Technical Note TN2065 do shell script in AppleScript This Technote answers frequently asked questions about AppleScript s do shell script command, which was introduced in AppleScript 1.8. This technical

More information

Paolo Santinelli Sistemi e Reti. Regular expressions. Regular expressions aim to facilitate the solution of text manipulation problems

Paolo Santinelli Sistemi e Reti. Regular expressions. Regular expressions aim to facilitate the solution of text manipulation problems aim to facilitate the solution of text manipulation problems are symbolic notations used to identify patterns in text; are supported by many command line tools; are supported by most programming languages;

More information

Chapter-3. Introduction to Unix: Fundamental Commands

Chapter-3. Introduction to Unix: Fundamental Commands Chapter-3 Introduction to Unix: Fundamental Commands What You Will Learn The fundamental commands of the Unix operating system. Everything told for Unix here is applicable to the Linux operating system

More information

9.2 Linux Essentials Exam Objectives

9.2 Linux Essentials Exam Objectives 9.2 Linux Essentials Exam Objectives This chapter will cover the topics for the following Linux Essentials exam objectives: Topic 3: The Power of the Command Line (weight: 10) 3.3: Turning Commands into

More information

IT 341: Introduction to System Administration. Notes for Project #8: Backing Up Files with rsync

IT 341: Introduction to System Administration. Notes for Project #8: Backing Up Files with rsync IT 341: Introduction to System Administration Notes for Project #8: Backing Up Files with rsync These notes explain some of the concepts you will encounter in Project #08: Backing Up Files with rsync Topics

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

5/8/2012. Exploring Utilities Chapter 5

5/8/2012. Exploring Utilities Chapter 5 Exploring Utilities Chapter 5 Examining the contents of files. Working with the cut and paste feature. Formatting output with the column utility. Searching for lines containing a target string with grep.

More information

CS 460 Linux Tutorial

CS 460 Linux Tutorial CS 460 Linux Tutorial http://ryanstutorials.net/linuxtutorial/cheatsheet.php # Change directory to your home directory. # Remember, ~ means your home directory cd ~ # Check to see your current working

More information

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash CS 25200: Systems Programming Lecture 10: Shell Scripting in Bash Dr. Jef Turkstra 2018 Dr. Jeffrey A. Turkstra 1 Lecture 10 Getting started with Bash Data types Reading and writing Control loops Decision

More information

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command. Unix Internal Assessment-2 solution 1 a.explain the mechanism of process creation. Ans: There are three distinct phases in the creation of a process and uses three important system calls viz., fork, exec,

More information

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment

More information

Linux shell programming for Raspberry Pi Users - 2

Linux shell programming for Raspberry Pi Users - 2 Linux shell programming for Raspberry Pi Users - 2 Sarwan Singh Assistant Director(S) NIELIT Chandigarh 1 SarwanSingh.com Education is the kindling of a flame, not the filling of a vessel. - Socrates SHELL

More information

CS Unix Tools & Scripting

CS Unix Tools & Scripting Cornell University, Spring 2014 1 February 21, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater Announcement HW 4 is out. Due Friday, February 28, 2014 at 11:59PM. Wrapping

More information

INTRODUCTION TO SHELL SCRIPTING ITPART 2

INTRODUCTION TO SHELL SCRIPTING ITPART 2 INTRODUCTION TO SHELL SCRIPTING ITPART 2 Dr. Jeffrey Frey University of Delaware, version 2 GOALS PART 2 Shell plumbing review Standard files Redirection Pipes GOALS PART 2 Command substitution backticks

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

UNIX II:grep, awk, sed. October 30, 2017

UNIX II:grep, awk, sed. October 30, 2017 UNIX II:grep, awk, sed October 30, 2017 File searching and manipulation In many cases, you might have a file in which you need to find specific entries (want to find each case of NaN in your datafile for

More information

A Tutorial for Excel 2002 for Windows

A Tutorial for Excel 2002 for Windows INFORMATION SYSTEMS SERVICES Writing Formulae with Microsoft Excel 2002 A Tutorial for Excel 2002 for Windows AUTHOR: Information Systems Services DATE: August 2004 EDITION: 2.0 TUT 47 UNIVERSITY OF LEEDS

More information

A Brief Introduction to the Linux Shell for Data Science

A Brief Introduction to the Linux Shell for Data Science A Brief Introduction to the Linux Shell for Data Science Aris Anagnostopoulos 1 Introduction Here we will see a brief introduction of the Linux command line or shell as it is called. Linux is a Unix-like

More information

Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland

Regular Expressions. Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland Regular Expressions Michael Wrzaczek Dept of Biosciences, Plant Biology Viikki Plant Science Centre (ViPS) University of Helsinki, Finland November 11 th, 2015 Regular expressions provide a flexible way

More information

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1 Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 POSIX character classes Some Regular Expression gotchas Regular Expression Resources Assignment 3 on Regular Expressions

More information

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012 Cisco IOS Shell Last Updated: December 14, 2012 The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-lineinterface (CLI) environment. Cisco IOS.sh enhances

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

Introduction to Scripting using bash

Introduction to Scripting using bash Introduction to Scripting using bash Scripting versus Programming (from COMP10120) You may be wondering what the difference is between a script and a program, or between the idea of scripting languages

More information

Getting to grips with Unix and the Linux family

Getting to grips with Unix and the Linux family Getting to grips with Unix and the Linux family David Chiappini, Giulio Pasqualetti, Tommaso Redaelli Torino, International Conference of Physics Students August 10, 2017 According to the booklet At this

More information

rsync link-dest Local, rotated, quick and useful backups!

rsync link-dest Local, rotated, quick and useful backups! rsync link-dest Local, rotated, quick and useful backups! Scope No complete scripts will be presented Just enough so that a competent scripter will be able to build what they need Unixes used: OpenBSD,

More information

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands Table Of Contents 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands Getting onto the Zoo Type ssh @node.zoo.cs.yale.edu, and enter your netid pass when prompted.

More information

Getting your department account

Getting your department account 02/11/2013 11:35 AM Getting your department account The instructions are at Creating a CS account 02/11/2013 11:36 AM Getting help Vijay Adusumalli will be in the CS majors lab in the basement of the Love

More information

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12. CIE- 25 Marks Government of Karnataka Department of Technical Education Bengaluru Course Title: Linux Lab Scheme (L:T:P) : 0:2:4 Total Contact Hours: 78 Type of Course: Tutorial, Practical s & Student

More information

IT 341: Introduction to System Administration. Notes for Project #9: Automating the Backup Process

IT 341: Introduction to System Administration. Notes for Project #9: Automating the Backup Process IT 341: Introduction to System Administration Notes for Project #9: Automating the Backup Process Topics Backup Strategies Backing Up with the rsync Daemon The crontab Utility Format of a crontab File

More information

Module 8 Pipes, Redirection and REGEX

Module 8 Pipes, Redirection and REGEX Module 8 Pipes, Redirection and REGEX Exam Objective 3.2 Searching and Extracting Data from Files Objective Summary Piping and redirection Partial POSIX Command Line and Redirection Command Line Pipes

More information

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT Unix as a Platform Exercises + Solutions Course Code: OS 01 UNXPLAT Working with Unix Most if not all of these will require some investigation in the man pages. That's the idea, to get them used to looking

More information

Linux File System and Basic Commands

Linux File System and Basic Commands Linux File System and Basic Commands 0.1 Files, directories, and pwd The GNU/Linux operating system is much different from your typical Microsoft Windows PC, and probably looks different from Apple OS

More information

Lecture 2. Regular Expression Parsing Awk

Lecture 2. Regular Expression Parsing Awk Lecture 2 Regular Expression Parsing Awk Shell Quoting Shell Globing: file* and file? ls file\* (the backslash key escapes wildcards) Shell Special Characters ~ Home directory ` backtick (command substitution)

More information

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. 2 Conventions Used in This Book p. 2 Introduction to UNIX p. 5 An Overview

More information

Fall Lecture 5. Operating Systems: Configuration & Use CIS345. The Linux Utilities. Mostafa Z. Ali.

Fall Lecture 5. Operating Systems: Configuration & Use CIS345. The Linux Utilities. Mostafa Z. Ali. Fall 2009 Lecture 5 Operating Systems: Configuration & Use CIS345 The Linux Utilities Mostafa Z. Ali mzali@just.edu.jo 1 1 The Linux Utilities Linux did not have a GUI. It ran on character based terminals

More information

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words More Linux Commands 1 wc The Linux command for acquiring size statistics on a file is wc. This command provides the line count, word count and number of bytes in a file. Open up a terminal, make sure you

More information

Contingency Planning and Backups: SSH/SCP, Deltas, and Rsync

Contingency Planning and Backups: SSH/SCP, Deltas, and Rsync License Contingency Planning and Backups: SSH/SCP, Deltas, and Rsync This work by Z. Cliffe Schreuders at Leeds Metropolitan University is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported

More information

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT Unix as a Platform Exercises Course Code: OS-01-UNXPLAT Working with Unix 1. Use the on-line manual page to determine the option for cat, which causes nonprintable characters to be displayed. Run the command

More information

Scripting Languages Course 1. Diana Trandabăț

Scripting Languages Course 1. Diana Trandabăț Scripting Languages Course 1 Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture Introduction to scripting languages What is a script? What is a scripting language

More information

A shell can be used in one of two ways:

A shell can be used in one of two ways: Shell Scripting 1 A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) 2 If we have a set of commands

More information

Practical 5. Linux Commands: Working with Files

Practical 5. Linux Commands: Working with Files Practical 5 Linux Commands: Working with Files 1. Ps The ps command on linux is one of the most basic commands for viewing the processes running on the system. It provides a snapshot of the current processes

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

${Unix_Tools} exercises and solution notes

${Unix_Tools} exercises and solution notes ${Unix_Tools exercises and solution notes Markus Kuhn Computer Science Tripos Part IB The shell Exercise : Write a shell command line that appends :/usr/xr6/man to the end of the environment variable $MANPATH.

More information

Systems Programming/ C and UNIX

Systems Programming/ C and UNIX Systems Programming/ C and UNIX December 7-10, 2017 1/17 December 7-10, 2017 1 / 17 Outline 1 2 Using find 2/17 December 7-10, 2017 2 / 17 String Pattern Matching Tools Regular Expressions Simple Examples

More information

Version June 2017

Version June 2017 Version 2.7.0 19 June 2017 Published by Just Great Software Co. Ltd. Copyright 2009 2017 Jan Goyvaerts. All rights reserved. RegexMagic and Just Great Software are trademarks of Jan Goyvaerts i Table of

More information

Dr. Sarah Abraham University of Texas at Austin Computer Science Department. Regular Expressions. Elements of Graphics CS324e Spring 2017

Dr. Sarah Abraham University of Texas at Austin Computer Science Department. Regular Expressions. Elements of Graphics CS324e Spring 2017 Dr. Sarah Abraham University of Texas at Austin Computer Science Department Regular Expressions Elements of Graphics CS324e Spring 2017 What are Regular Expressions? Describe a set of strings based on

More information

Shell Start-up and Configuration Files

Shell Start-up and Configuration Files ULI101 Week 10 Lesson Overview Shell Start-up and Configuration Files Shell History Alias Statement Shell Variables Introduction to Shell Scripting Positional Parameters echo and read Commands if and test

More information

Systems Programming/ C and UNIX

Systems Programming/ C and UNIX Systems Programming/ C and UNIX Alice E. Fischer September 6, 2017 Alice E. Fischer Systems Programming Lecture 2... 1/28 September 6, 2017 1 / 28 Outline 1 Booting into Linux 2 The Command Shell 3 Defining

More information

CSC UNIX System, Spring 2015

CSC UNIX System, Spring 2015 CSC 352 - UNIX System, Spring 2015 Study guide for the CSC352 midterm exam (20% of grade). Dr. Dale E. Parson, http://faculty.kutztown.edu/parson We will have a midterm on March 19 on material we have

More information

Motivation (Scenarios) Topic 4: Grep, Find & Sed. Displaying File Names. grep

Motivation (Scenarios) Topic 4: Grep, Find & Sed. Displaying File Names. grep Topic 4: Grep, Find & Sed grep: a tool for searching for strings within files find: a tool for examining a directory tree sed: a tool for "batch editing" Associated topic: regular expressions Motivation

More information

COMP2100/2500 Lecture 17: Shell Programming II

COMP2100/2500 Lecture 17: Shell Programming II [ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help] COMP2100/2500 Lecture 17: Shell Programming II Summary

More information

UNIX Essentials Featuring Solaris 10 Op System

UNIX Essentials Featuring Solaris 10 Op System A Active Window... 7:11 Application Development Tools... 7:7 Application Manager... 7:4 Architectures - Supported - UNIX... 1:13 Arithmetic Expansion... 9:10 B Background Processing... 3:14 Background

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

More information

Introduction to Unix Week 3

Introduction to Unix Week 3 Week 3 cat [file ] Display contents of files cat sample.file This is a sample file that i'll use to demo how the pr command is used. The pr command is useful in formatting various types of text files.

More information

UNIX Shell Programming

UNIX Shell Programming $!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...

More information

Linux shell scripting Getting started *

Linux shell scripting Getting started * Linux shell scripting Getting started * David Morgan *based on chapter by the same name in Classic Shell Scripting by Robbins and Beebe What s s a script? text file containing commands executed as a unit

More information

Basic Linux (Bash) Commands

Basic Linux (Bash) Commands Basic Linux (Bash) Commands Hint: Run commands in the emacs shell (emacs -nw, then M-x shell) instead of the terminal. It eases searching for and revising commands and navigating and copying-and-pasting

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

C Shell Tutorial. Section 1

C Shell Tutorial. Section 1 C Shell Tutorial Goals: Section 1 Learn how to write a simple shell script and how to run it. Learn how to use local and global variables. About CSH The Barkley Unix C shell was originally written with

More information

Regular Expressions. Regular Expression Syntax in Python. Achtung!

Regular Expressions. Regular Expression Syntax in Python. Achtung! 1 Regular Expressions Lab Objective: Cleaning and formatting data are fundamental problems in data science. Regular expressions are an important tool for working with text carefully and eciently, and are

More information

IT341 Introduction to System Administration. Project 4 - Backup Strategies with rsync and crontab

IT341 Introduction to System Administration. Project 4 - Backup Strategies with rsync and crontab IT341 Introduction to System Administration Project 4 - Backup Strategies with rsync and crontab Backup is one of the most important things a system administrator does. It is important to decide what data

More information

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

STATS Data Analysis using Python. Lecture 15: Advanced Command Line STATS 700-002 Data Analysis using Python Lecture 15: Advanced Command Line Why UNIX/Linux? As a data scientist, you will spend most of your time dealing with data Data sets never arrive ready to analyze

More information

About this course 1 Recommended chapters... 1 A note about solutions... 2

About this course 1 Recommended chapters... 1 A note about solutions... 2 Contents About this course 1 Recommended chapters.............................................. 1 A note about solutions............................................... 2 Exercises 2 Your first script (recommended).........................................

More information

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab Basic Terminal Intro to Linux ssh short for s ecure sh ell usage: ssh [host]@[computer].[otheripstuff] for lab computers: ssh [CSID]@[comp].cs.utexas.edu can get a list of active computers from the UTCS

More information

elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at

elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at Processes 1 elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at 2 elinks is a text-based (character mode) web browser we will use it to enable

More information

Linux Command Line Interface. December 27, 2017

Linux Command Line Interface. December 27, 2017 Linux Command Line Interface December 27, 2017 Foreword It is supposed to be a refresher (?!) If you are familiar with UNIX/Linux/MacOS X CLI, this is going to be boring... I will not talk about editors

More information