see http://www.zinkwazi.com/unix for more...
UNIX Class - Santa Barbara Business College class notes
Instructor: Greg Lawler (notes typed up by ryan foster)
(note: this info was current in July 2001)
quick intro/summary of vi(m)
vi text editor and uber tool!
vi foo opens foo
vi opens a blank document
command mode (pres esc to get back to command mode)
:q quits vi
:w writes file
:wq writes file and quits
! place ! at end of :w or :q to force action
hjkl navigation. h=left j=down k=up l=right
dd delete current line and also puts it into buffer
4dd deletes 4 lines from current line
G go to bottom of file
4G go to line 4
gg go to top of file
cw change word
3cw changes 3 words
dw delete word
3dw delete 3 words
r replace character under cursor
R enables insert mode and replaces any text typed
Y copies current line to buffer
4Y copies 4 lines to buffer
y copy word to buffer
4y copies 4 words to buffer
P pastes buffer contents
$ go to end of current line
0 (zero) go to beginning of current line
:%s/$/!/g inserts "!" at end of every line in file
:%s; ; is ;g substitutes " is " where spaces exist
:%s/^/The code for /g inserts "The code for " at the beginning of every line
insert mode (press i to get into insert mode from command mode, press esc to exit insert mode)
type text
Common Linux commands:
Remember: Filenames and commands are case-sensitive.
ls show contents of a directory
switches: -a show all files, even hidden files and directories
-l show long listing with permissions
-h show file sized in megs or kb not blocks
e.g. ls -alh /etc/init.d
cd change directory
cd destination
e.g. cd /var/log
pwd print working directory
e.g. pwd
touch creates empty file, if exists updates timestamp
touch filename
e.g. touch /var/lib/dhcp/dhcpd.leases
cp copy files
cp source destination
switches: -R recures sub-directories
e.g. cp -R /etc/ .
mv rename or move files
mv source destination
e.g. mv /etc /foo
e.g. mv foo bar
rm remove file
rm filename
switches: -f force remove
-rf force recursive remove
e.g. rm foo
e.g. rm -rf /etc
mkdir makes new directory
mkdir directory
e.g. mkdir foo
ping pings specified destination
ping destination
switches: -f flood ping
traceroute traces the route to a destination
traceroute destination
e.g. traceroute www.yahoo.com
df show partition information
df
switches: -h "human readable" filesizes
mount mounts a device to directory
mount directory
e.g. mount /mnt/cdrom mounts the cdrom to /mnt/cdrom
dd makes binary image
e.g. dd if=/dev/cdrom of=foo
pump dhcp client
switches: -r release ip
-R renew ip
pump -R
ps lists processes
switches: aux lists all processes
e.g. ps aux
killall kills process by executable/daemon name
killall executable
e.g. killall netscape
kill kill process by PID
kill PID
switches: -1 restarts process
-9 kills process without restart
e.g. kill 1234
crontab runs a command at any given time
crontab switch time path
switches: -e edit user's crontab
e.g. crontab -e
ncftp ftp.redhat.com anonymous ftp connection to ftp.redhat.com
ncftp -u bob ftp.redhat.com user ftp connection to ftp.redhat.com with username bob
ncftp commands:
ls show contents of a directory
put puts a file on server
mput puts multiple files
get gets a file
mget gets multiple files
pwd print working directory
l local command
e.g. lcd /etc changes local directory to /etc
rpm redhat package manager
foo.rpm: package file containing binaries, config file, setup script, and install directions
rpm -aq lists all installed packages
e.g. rpm -aq | grep apache
rpm -e package erases installed package
e.g. rpm -e apache-1.3.19-5
rpm -Uvh foo.rpm installs package foo.rpm
rpm -qpl foo.rpm lists the files in uninstalled package foo.rpm
install dhcp
get rpm
rpm -Uvh dhcpd...rpm
config file is /etc/dhcpd.conf
local subnet must be defined
leases file must be created
touch /var/lib/dhcp/dhcpd.leases
start dhcp
/etc/init.d/dhcpd start
apache
config file is /etc/httpd/conf/httpd.conf
samba
config file is /etc/samba/smb.conf
named
config file is /etc/named.conf
list all domains and ip nets that you answer for
named directory is /etc/named.d
conf files for each domain
db.brooks
db.192.168.3
updatedb
puts listing of all files and directories on hard disk into a database
locate
gives location of a file from the database from updatedb
e.g. locate smb.conf
zinkwazi.com/tools/putty.exe
windows ssh and telnet client
snmpwalk 192.168.3.247 public system
snmpget ip OID public
snmpset
sets variables
mrtg
graphing tool
rename a bunch of files with prefix old. to new. (opposite of basename)
for f in old.*; do mv $f new${f#old}; done