Unix Course
Unix Course
1 - Introduction to UNIX.
Developed by AT&T employees at Bell Labs (1969-1971)
Employees worked by themselves on smaller project named UNICS ( Uniplexed
Information and Computing Service)
Renamed UNIX after become multiuser.
echo $0 : Display current working shell. Not the starting one, current one.
man : keyword access manual for commands. Ex: man echo
man -k or apropos : look for keyword commands and description.
2 - Filesystem Basiscs
- pwd: show present working directory. Display current working directory.
- ls: list directory structure.
- ls -lah: ls with optional listings.
- cd : navigate to folder
- cd .. : return to parent directory.
- cd ../.. : move back directories. Back one them back the second.
- cd - : switch back to last directory.
/ : Root
/bin : Binaries, programs
/sbin : System binaries, system programs
/dev : Devices: hard drivers, keyboard, mouse, etc.
/etc : System configurations
/home : User home directories
/lib : Libraries of code
/tmp : Temporary files
/var : Various, mostly foes the system uses
/usr
/usr/bin
/usr/etc
/usr/lib
/usr/local : User Programs, tools and libraries (not files)
- WILDCARD CHARACTERS:
* zero or more characters (glob)
? any other character
[ ] : any character in the brackets.
- find ~ -name *.??? or find / -name ????.** or find / -name index[123].hmtl
look for name index combined with any of characters inside brackets.
rwx-rw—r—
* Frequently files has execution off because they are not script. They are
text files.
* By default directories has execute turned on because they can be read and
search.
Usage:
chmod ugo=rwx “filename”
chmod u=rwx, g=rw-, o=r “filename”
chmod ug+w “filename”
chmod o-w “filename”
chmod ugo+w “filename” is equal to chmod a+w
chmod go-rw filename
Octonal notation
rwx-rw—r—
sort < cars.txt : using the cars.txt as input for sort command.
sort -u cars.txt > sorted_unique_cars.txt : inputs cars list into sort method
and save the return into sorted_unique text file.
Parenthesis is not required because we always evaluate the input first.
< > operators need to be used with file for input or output. it cant be used
for readings.
| (pipe operator) always use output of command and not a file.
cat cars.txt | sort | uniq > sorted_uniq_ cars.txt
Regular Expression
“regex” for short
grep apple fruit.txt return lines where word apple exists, not the word but
the lines.
grep -i: case insensitive.
grep -c : grep coint
grep -R ./ : recursive search on directory
grep -w : exactly match
grep -v : list what does not match. Inverse of regular search.
grep -n : give match and line numbers
grep -Rl: “l” suppress everything and just show the filename.
grep -RL: “-L” returns filename that does not match.
Example: ps aux | grep Terminal
history | grep nano | less
# GREP_COLOR codes
# Attributes: Text color: Background:
# 0 reset all 30 black 40 black
# 1 bright 31 red 41 red
# 2 dim 32 green 42 green
# 4 underscore 33 yellow 43 yellow
# 5 blink 34 blue 44 blue
# 7 reverse 35 purple 45 purple
# 8 hidden 36 cyan 46 cyan
# 37 white 47 white
# Separate with ";"
#
export GREP_COLOR="34;47"
grep —color ‘ea[cp]’ fruits.txt: grep to word with ea with third letter c or
p.
SSH Commands:
ssh-keygen -R server-name
ssh-keygen -R server.ip.addre.ss
ssh-keygen -R 202.54.1.5
ssh-keygen -R server1.example.com