Jim Kerr - Alaska Juggler
  Unix

 Why is it so hard to understand simplicity?
Juggling

Resume'

Diversions

Gravity

Music

About Jim

Contact Jim

Computer Trix

Site Map

Unix
"Unix is very simple, but it takes a genius to understand the simplicity."
(Dennis Ritchie)
OpenBSD Tricks:

Aliases to paste into your bashrc
mf ="mount -t msdos /dev/fd0Ba /floppy"  # This will mount a MSDOS formatted diskette
mcd="mount /dev/cd0a /cdrom" # Mount CDROM Drive
musb="mount /dev/sd0i /thumb
netstat -I sis0 -w 5
This gives the network I/O status of a netgear card interface (-I) (sis0) every 5 seconds (-w)

ps -aux
(Process Started listing)
Setup tricks
etc/sysctrl.conf file
make sure the ddb.panic = 0 # Set a machine's default to reboot after a kernel panic
net.inet.ip.forwarding =1 # set ip forwarding on for bridging and packet filtering
/etc/rc.conf.local - Turn on the Packet Filter program if you have set it up
pf = yes
stopping pf
pfctl -d
starting pf
pfctl -e
starting pf with configuration file
pfctl -f /etc/pf.conf
More PF commands
# pfctl -f /etc/pf.conf Load the pf.conf file
# pfctl -nf /etc/pf.conf Parse the file, but don't load it
# pfctl -Nf /etc/pf.conf Load only the NAT rules from the file
# pfctl -Rf /etc/pf.conf Load only the filter rules from the file
# pfctl -sn Show the current NAT rules
# pfctl -sr Show the current filter rules
# pfctl -ss Show the current state table
# pfctl -si Show filter stats and counters
# pfctl -sa Show EVERYTHING it can show
Mount a floppy disk
mkdir /floppy    #The first time you mount a floppy disk you need to create a mount point:
ls /dev/fd*          # to find a floppy device
mount -t msdos /dev/fd0Ba /floppy        # This will mount a MSDOS formatted diskette
cd /floppy        # Change into the floppy directory
cd /                  # Change to the root directory so the diskette can be unmounted
umount /floppy            # unmount the floppy diskette

tar -zxvf bash*.tgz /
will untar a comppressed tarball into the current directory
Mount a CD-ROM (at /cdrom mount point)
after creating the a mount point (i.e.mkdir /cdrom)
mount /dev/cd0a /cdrom
Disk Usage
df usage of major partitions
du -s size of current directory
ls -la full info. file listing incl. hidden files
ls -laF full info. file listing incl. hidden files & file types
#where @ is link, * executable, / is directory
ls -ld full info. directory listing
ls -laF | sort | grep "/" #list all directories
ls -laF | sort | grep "*" #list all executables
Data and File tricks
sed 's/^0/string/g' file-in.txt>file-out.txt
globally replaces zero at the beggining of the line with string and write the output to file-out.txt - don't forget the quotation marks.
find ./ -type f | xargs grep -l 'http://AlaskaEconomy.uaa.alaska.edu' \
| xargs sed -a '' -e 's/http://AlaskaEconomy.uaa.alaska.edu/Living Conditions/g'
4.41. How do I make substitutions in every file in a directory, or in a complete directory tree?
4.41.1. - ssed and Perl solution
The best solution for multiple files in a single directory is to use ssed or gsed v4.0 or higher:
sed -i.BAK 's|foo|bar|g' files # -i does in-place replacement
If you don't have ssed, there is a similar solution in Perl. (Yes, we know this is a FAQ file for sed, not perl, but perl is more common than ssed for many users.)
perl -pi.bak -e 's|foo|bar|g' files # or
perl -pi.bak -e 's|foo|bar|g' `find /pathname -name "filespec"`
For each file in the filelist, sed (or Perl) renames the source file to "filename.bak"; the modified file gets the original filename. Remove '.bak' if you don't need backup copies. (Note the use of "s|||" instead of "s///" here, and in the scripts below. The vertical bars in the 's' command let you replace '/some/path' with '/another/path', accommodating slashes in the LHS and RHS.)
To recurse directories in Unix or GNU/Linux:
# We use xargs to prevent passing too many filenames to sed, but
# this command will fail if filenames contain spaces or newlines.
find /my/path -name '*.ht' -print | xargs sed -i.BAK 's|foo|bar|g'
Perl global string/file replace
$ perl -pi -e 's/string1/string2/g' *
Getting rid of those pesky ^Ms that windows notepad leaves:
replace the ^M with tr


tr -d "\015" < dosformatted.txt > unixformatted.txt
Globally replace text in many files in place
find -name Root | xargs perl -pi -e 's/Old Text/New Text /g'
Just in case you need the ascii code here is an ASCII Table for you
$ find / \! -name '*.c' -print
Print out a list of all the files whose names do not end in ``.c''.

$ find / \! \( -newer ttt -user wnj \) -print
!Print out a list of all the files which are not both newer than``ttt'' and owned by ``wnj''.
$ find / \( -newer ttt -or -user wnj \) -print
!Print out a list of all the files that are either owned by ``wnj'' or newer than ``ttt''.
$ find / \! -fstype local -prune -or -name '*.core' -print
!Print out a list of all core files on local file systems.
dd if=floppy34.fs of=/dev/rfd0c bs=32k
!Write an OpenBSD floppy image to a floppy disk.
eject /dev/rcd0c
Eject the first CD device. This will work even if there is no CD in the drive.
Here is a handy backup routine to copy only files that have changed since the last backup:
#!/bin/csh
rsync -r -u -v /Stuff/* /Volumes/Backup/Stuff
rsync -r -u -v /Users/WhatsYourFace/* /Volumes/Backup/WhatsYourFace
RED HAT TRICKS
cat /proc/cpuinfo #for CPU information
cat /proc/meminfo # for memeory information
cat > filename.txt # then type or paste info to capture text and end with contol-d
tar -xvf tarfile.tar # unpack most archives
mkdir /cdrom # makes a directory to mount cdroms
mount /dev/cdrom /cdrom #mounts a cdrom in the /cdrom directory created in the last line

ps
–A notice the capital “-A” for all processes
stty rows 46 cols 100
Start Xwindows with:
xstart
find ./ -name filename
example:
cd ~ [go to home directory
find ./ -name lost.file*
ls –laF

Sort a directory via a pipe:
ls -l | sort -n +1
Explained:
ls = list directory -l = use long format
| = pipe output into the next command
sort -n +1 = sort using -n (numbers as opposed to letters) on the +1 (second field)
while in the sbin directory you can add users with the following:
./adduser –c “ftp guest” -d /home/iserguest -p secretpassword
Password change - Go to Single User Mode via hard boot (turn off computer or reset it)
Go to the boot prompt and type: linux single
Conversion tricks
EOL characters:
DOS: CR/LF
Macintosh: CR
Unix: LF


Juggling |
Resume' | Diversions | Gravity | Music | About Jim | Contact Jim | Site Map
Home