Lecture 04
Lecture 04
1
Administrivia
▪Course webpage live!
▪HW1 actually posted
- after this lecture you now have everything you need
- klaatu accounts created
- set up SSH
- ssh [email protected]
- password: tempPassword
- passwd #will let you change your password
- issues fill out this form: https://forms.gle/sFojyRU4eC8kJT4T9
- Grading scripts are still being adjusted
4
Transferring files between local and remote
▪tar – tape archive – compresses directory of files for easy transfer (like zip or archive)
- tar -c <directory to compress>
- tar –c –v –f myTarFile.tar /home/champk/
- -c – creates new .tar archive file
- -v - Verbosely show the tar process
- -f - to decide name of tar file
- tar –x <file to extract>
- tar –x –v myTarFile.tar
▪wget – non-interactive download of files from the web supporting http, https and FTP
- Non interactive means it can work in the background (helpful if the files take a while)
- wget http://website.come/files/file.zip
▪scp – secure copy – uses ssh protocol to transfer files between different hosts
- scp [email protected]:file.txt /local/directory copies file.txt from remote host to local directory
- scp file.txt [email protected]:/remote/directory/ copies file.txt from local host to remote directory
▪You can always use a file transfer GUI like FileZilla uses FTP or SFTP, available for all platforms
8
Exit Codes
The command “exit” exits a shell and ends a shell-script program
ctrl+c aborts a process
When a process exits you can use a number to indicate either a success or failure
0 = success
1 or any non-zero positive number = error
9
grep
▪Search for a given string within a given file
- grep [options] pattern [files]
- EX: grep “computer” /usr/share/dict/words
▪Helpful Options
- -c : prints count of lines with given pattern
- -h : display matched lines (without filenames)
- -i : ignore case when matching
- -l : display list of filenames with matches
Examples
- cmd > file sends stdout to file
- cmd 2> file sends stderr to file
- cmd 1> output.txt 2> error.txt redirects both stdout and stderr to files
- cmd < file accepts input from file
- Instead of directly putting arg in command, pass args in from given file
- cat file1.txt file2.txt file3.txt or cat < fileList.txt
15
I/O Piping
We can feed the stdout of one process to the stdin of
another using a pipe (“|”)
- Data flows from process to the other through multiple
transformations seamlessly
- Similar to redirection, but specifically passes streams into other
programs instead of their defaults
Example:
- Instead of:
- du –h –d 1 . > sizes.txt
- grep ‘M’ sizes.txt
- We can use piping
- du – h –d 1 . | grep ‘M’