Unix
https://harvard-iacs.github.io/2019-CS207/lectures/lecture1/
David Sondak
Harvard University Institute for Applied Computational Science
9/5/2019
Unix https://harvard-iacs.github.io/2019-CS207/lectures/lecture1/ - - PowerPoint PPT Presentation
Unix https://harvard-iacs.github.io/2019-CS207/lectures/lecture1/ David Sondak Harvard University Institute for Applied Computational Science 9/5/2019 Last Time Course introduction Unix and Linux 1 / 42 Today More on Unix / Linux
Unix
https://harvard-iacs.github.io/2019-CS207/lectures/lecture1/
David Sondak
Harvard University Institute for Applied Computational Science
9/5/2019
Last Time
1 / 42
Today
Again, some content adapted from Dr. Chris Simmons.
2 / 42
Basic Commands
http://cheatsheetworld.com/programming/unix-linux-cheat-sheet/
4 / 42
Absolutely Essential Commands
These commands should be at your fingertips at all times:
5 / 42
The ls command
6 / 42
Command Line Options
Note: Hidden files have names that start with .
7 / 42
ls Command Line Options
8 / 42
General ls Command Line
ls -al /usr/bin
documentation
9 / 42
man and More Information
1 General commands 2 System calls 3 C library functions 4 Special files (usually devices found in /dev 5 File formats and convections 6 Games 7 Miscellaneous 8 Sys admin commands and daemons
man 3 printf (shows manpage for C library function)
10 / 42
Running a Unix Program
1 Standard input 2 Standard output 3 Standard error
12 / 42
Unix Pipes
streams
to the next one
task
program1 program2 STDOUT STDIN
13 / 42
Building Commands
pipes
14 / 42
More Unix Commands: find
pattern
commands in Unix
15 / 42
find
files
16 / 42
The Famous grep
17 / 42
Regular Expressions
character
18 / 42
More on Regular Expressions
not in the character class
19 / 42
Regular Expressions Continued
20 / 42
Regular Expression Examples and Practice
You are given a text file called dogs.txt that contains names, ages, and breeds of dogs. Use grep and regular expressions to accomplish the following:
1 Find all dogs named either Sally or Joey.
2 Find all dogs named Joey.
entered in all lowercase!
3 Find all dogs that are 6 months old.
entered as 0.5.
21 / 42
File Attributes
Every file has a specific list of attributes:
For example, time attributes access with ls,
22 / 42
File Permissions
people that might access a file:
23 / 42
File Permissions Display Format
24 / 42
Changing File Permissions
25 / 42
Symbolic Representation
execute permission
26 / 42
Symbolic Representation Examples
27 / 42
Octal Representation
permissions for a file (3 digits)
(4+2+1)
28 / 42
Octal Representation Examples
29 / 42
Text Editors
use of available Unix text editors
31 / 42
A Brief Text Editor History
back in sed/awk: useful to know.
32 / 42
vi Overview
modes of operation:
current file
33 / 42
vim Quick Start Commands
34 / 42
Useful vim Commands
result
Here are some vim resources: https://vim.rtorr.com/, https://devhints.io/vim, https://vim-adventures.com/, vimtutor.
35 / 42
Shell Customization
shell when it starts up
administrators (e.g. /etc/profile)
additional customization
36 / 42
Shell Startup Files
Useful information can be found at the bash man page: https://linux.die.net/man/1/bash
don’t modify
Decent reference on the difference between .bash profile and .bashrc: Apple Stack Exchange, Scripting OS X
37 / 42
Lecture Exercise
Update your .bash profile Exercise goals:
https://www.tecmint.com/create-alias-in-linux/]
biz/tips/howto-linux-unix-bash-shell-setup-prompt.html)
Note to Windows users: Modify Bash Profile in Windows Note: The Dracula Theme is pretty fun.
38 / 42
I/O
Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR)
39 / 42
Shell Stream Redirection
40 / 42
Modes of Output Redirection
named foo while ls >> foo appends the output to foo
41 / 42
Wildcards
filenames in the current directory
42 / 42