Motivation
- Many of us are new to using *nix systems
- This can be a daunting system when thrown in
- Using CLI is important for using our tools and firefighting
How to Use the Shell
- Scroll through old commands: C-n, C-p
- List your shell history: history
- Search for old command: C-r
- Move to the beginning of a line: C-a
- Move to the end of a line: C-e
Basics
Echo
- displays provided string or variable
List Files
- Note tree is likely not installed by default (brew install tree)
Change Directories
- ~ is your homedir
- `cd` == `cd ~`
- . is the current dir
- .. is one dir ‘up’
Create Directories
Create Files
Remove Files
Show files
Wildcards
- Can be used with most commands
Docs
Sudo
- Runs a command as the super user (root)
Environment
- Variables that customize how you interact with programs
env
- Displays all environment variables
PATH
- Contains paths to directories you want the system to look for executables
- Setup in .bashrc, .bash_profile, or .zshrc
Export
- Usually found in your shell profile
- Sets the value of a variable for use later
Reloading Your Environment
- bash: source ~/.bashrc
- zsh: run command: reload
Redirection
Pipe
- Redirects all output from one command to another
- Much like a function call
- Can be chained together
Redirection Operator
Streams
- stdin: stream of text going into a program
- stdout: standard output of a program
- stderr: typically used to display errors
- Redirect stderr to stdout: 2>&1
tee
- Reads from stdin and writes to stdout or a file
Searching
Grep
- Search a file or stream from pipe
- Useful flags: -i, -v, -r
Grep Replacements
Find
- This could be it’s own talk
- Allow very specific searching and execution
Locate
which
- outputs the path to an execuctable on your PATH
Processing Output
sort
uniq
cut
rev
sed
- Find and replace
- There is a lot to this tool
wc
Permissions
chown
- change owner and/or group of file
chmod
- u = user
- g = group
- o = other
- r = read
- w = write
- x = execute
Interacting with Processes
ps
- lists running processes
- aux, faux
kill
- kill -9 forces the kill if the process is hung
top
- Displays list of running process in an interactive way
- Shift+m sorts by memory usage
- Shift+p sorts by cpu usage
- q exits
htop
- more in depth version of top, not on all systems
&
- Runs a process in the background
Exit Status
Networking
ping
- Sends icmp packets at domain or ip
host
- Attempts to lookup a hostname for the ip provided
dig
- Looks up the ip associated with a domain name
- +short displays only the ip address
netstat
- -lpn is most used to display listening ports
- -lpn only shows the program name if you are root or sudoing
- Does not work on mac
ifconfig
- Lists information about networking on your computer
df
- Displays system wide disk usage
- -h displays ‘human readable’
du
- Displays an estimate of file space usage
free
- Shows current memory usage
- -m display in megabytes
- Does not work on Mac
w
- Shows which users are logged in currently
lastlog
- Shows a list of users and when they have logged in
Working with Files
tar
zip & unzip
rsync
- Used to sync two directory
- Can go over ssh
scp
- Uses ssh to copy a file to another computer
Customizing Your Shell
alias
- Create resusable shortcut
- Place in your profile file to always have them
zsh + oh_my_zsh
Questions?