Download presentation
Presentation is loading. Please wait.
1
Introduction to UNIX
2
*nix Linux, Solaris, BSD, macOS…
We will be using Ubuntu and centOS primarily
3
UNIX OS 3 parts: Kernel Shell Programs
4
Kernel Interacts with hardware directly Manages memory
Handles filestore and communications
5
The Shell Interface between user and kernel Command line interpreter
Commands are programs The Shell is also a program
6
Programs Everything is a process or a file Process – executing program
Each process has a unique process identifier (PID) File – collection of data created by users
7
Filesystem
8
Basic Commands - Syntax
Example: ls -a /home The Shell expects tokens to be separated by spaces Typically first token is your command Subsequent tokens are arguments Arguments that start with - or -- are options Non-option arguments passed to command
9
Basic Commands ls (list) touch myfile.txt Options: -a, -l, -h…
Argument: /home/username/ touch myfile.txt Creates a blank file named myfile.txt
10
Basic Commands cd (change directory) pwd
If no destination is provided it defaults to home directory . is your current directory .. will take you to the parent directory pwd Print working directory (where you are in the filesystem)
11
Basic Commands mkdir (make directory) rmdir (remove directory)
Must provide new directory name rmdir (remove directory) rm (remove) Delete a file Common to see rm –rf /path/to/file Be careful, -r is recursive and -f is force
12
Basic Commands cp (copy) mv (move) cp source destination
ex: cp myFile /home/anotheruser/ mv (move) mv source destination Use this to rename files
13
Basic Commands cat vim (or emacs) View contents of file Edit file
There are built in tutorials for both of these vimtutor Start emacs, type “Ctrl –h” followed by “t”
14
Basic Commands For more information on any command type “man <command>” Shows command usage Shows all options with explanations
15
Basic Commands Ctrl C – kill process Ctrl D – end of file
Ctrl Z – suspend process Enter “bg” to resume process in background Enter “fg” to bring it to foreground again
16
Other Useful Commands find /home -name <filename> df -h
Find a file in your home directory by name df -h Display how much disk space has been used
17
Filters head tail grep Show first n lines (10 by default)
Show last n lines (10 by default) grep Search for a given pattern
18
Wildcards * ? [ ] Zero or more characters
ls *.png (list all pngs in current directory) ? Single character ls ?a* (list all files whose 2nd letter is “a”) [ ] Range of characters ls [a-dj]*.png (list all pngs that start with a,b,c,d, or j)
19
Redirecting Output cat list1.txt list2.txt > bothLists.txt
redirects output of cat to a text file called bothLists.txt cat list1.txt list2.txt >> bothLists.txt appends output of cat to bothLists.txt command1 | command2 called a pipe redirects output of command1 to input of command2 sort < names.txt redirects input to come from file sorts content of names.txt
20
Combining Commands cal 2017 ; ls -a
runs two commands in sequence sudo apt-get update && sudo apt-get upgrade downloads the list of available updates installs them if the previous command was successful ./myscript || echo “Script Failed!” runs myscript prints “Script Failed!” if script failed Added combination of commands on one line, since it was in Welcome Week exercises. Feel free to skip if nesessary. Max
21
SSH Secure Socket Shell ssh username@ip Remote access
Login to another box on your network
22
Path Path – location of file/directory
Absolute path – location of file/directory from root directory /usr/local/bin ~/Desktop (~ will refer to your home directory) Relative path – location of file/directory relative to another directory ../home/anotheruser
23
Path cont. $PATH /usr/bin/python (invoke python interpreter)
Shell will search for a disk utility, if command is not built-in /usr/bin/python (invoke python interpreter) ./a.out (run program compiled in current directory)
24
Access Control Every file is owned by a user and a group
Permissions allow users/groups to read/write/execute files Root can read/write/execute anything Other users can get root privileges with “sudo” “su” allows a user to change the login session owner
25
User Info - /etc/passwd
Each line contains login info for a single user Format: Username Password Placeholder User ID Group ID Comment field Home directory User shell
26
User Info - /etc/shadow
Each line contains hashed password for single user Format: Username Salt and hashed password Last password change Days of warning prior to password expiration Last 3 fields denote days before account is made inactive
27
Permissions File type, mod bits Number of hard links Owner Group Size
Modification time filename
28
Permissions r – read (4) w – write (2) x – execute (1)
To change: chmod <modes> <files> chmod 754 myScript.sh 7 – rwx for user (file’s owner) 5 – rx for group (member’s of file’s group) 4 - r for other (everyone else)
29
Bash Extension of Bourne Shell When the Shell gets a command it
There are others, like Korn Shell When the Shell gets a command it Expands aliases Checks if command is a shell built in If not, assumes command is a program
30
Bash Scripting – Hello World
31
Bash Scripting #!/bin/bash Need to “chmod 755 hello.sh”
Invoke appropriate interpreter Need to “chmod 755 hello.sh” Executable for user, group and other can read/write To run “./hello.sh”
32
References OneNote
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.