Last Edited: 01 May 2008 by superuser
Importered from old WiKi -- 30/04-08 18:04.
Contents
   
          Compression
          Applications
          Network
          Firewall
          System
          File System
         
         
         

ShellScripts Examples

For a more complete list of the commands used in the Bash shell see AzBash (An A-Z Index of the Linux BASH command line) or http://www.gnu.org/manual/
For a complete Bash Shell Syntax Reference go to http://www.gnu.org/software/bash/manual/bashref.html

- Control-C Interrupt a command
- Control-D Sends End of File from terminal
- Control-U Erases the entire command line
- Control-\ Is a stronger terminate than Control-C
- Control-Z Suspend process

Copy and Paste
Ctr+C will copy highlighted text in rxvt
Ctr+Insert will paste text at the prompt in rxvt

Remember, additional commands for an application can be retrieved by typing:
applicationName --help
at the commandline.

- Compression
- Applications
- Network
- Firewall
- Mounting and Unmounting
- Window Managers
- Additional Software

Compression

GZip Compress
gzip file

GZip Decompress
gzip -d file.gz

Tar Decompress (BZip2)
tar -jxf file.tar.bz2

Tar Decompress (GZip)
tar -zxf file.tar.gz

Tar Compress Directory with GZip (from inside directory)
tar -zcf archive.tgz *

Tar Compress Directory with BZip2 (from inside directory)
tar -jcf archive.tar.bz2 *

DotPup
unzip DotPup.pup

PETget / PupGet / AlienPackage
tar -zxf file.tar.gz

Applications

NMap (stealth syn scan)
nmap -sS -O -P0 -v 192.168.1.1

MPlayer (capture stream)
mplayer -noframedrop -dumpfile YourFile.rm -dumpstream rtsp://urlto/yourfile.rm

MPlayer (capture stream with HTTP Authentication)
mplayer -noframedrop -dumpfile YourFile.rm -dumpstream rtsp://urlto/yourfile.rm -user UserName -passwd YourPassword

MEncoder (make MPEG that will play on any system) (assumes 4:3 aspect ratio)
#adjust 'scale=' for size/aspect ratio and 'vbitrate' for video quality
mencoder VTS_01_1.VOB -vf scale=320:240:0:0:: -of lavf -lavfopts format=mpg -fps 30000/1001 -ofps 25 -ovc lavc -lavcopts vcodec=mpeg2video:keyint=25:vbitrate=512 -oac lavc -lavcopts acodec=mp3:abitrate=128 -o MyFile.mpg

RIP Audio CD
cdparanoia -B -- "1-"

Batch Encode Music Files to MP3
for fl in *.wav; do
lame -h -v -V 4 -b 64 --resample 22050 $fl
#rm $fl
done

Batch Convert FLASH to MPG
for file in *.flv
do

output=`ls $file -1|cut -f1 -d”.”`
ffmpeg -i $file -ab 56 -r 25 -ar 22050 -b 500 -s 352×240 $output.mpg

done

Find and Replace Text in Multiple Files
for fl in *.txt; do
mv $fl $fl.old
sed 's/findText/replaceText/g' $fl.old > $fl
rm $fl.old
done

Convert ps2 to pdf
ps2pdf -dOptimize=true yourFile.ps

Convert dos to unix text
dos2unix YourFile.txt

Convert unix to dos text
unix2dos YourFile.txt

Open MS BookMark/Shortcut File
linebefore=`fgrep -in [InternetShortcut] "$name" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`
url=`tail +$line "$name" | head -n 1`
url=`echo ${url#URL=} | sed 's/[ \t\n\r]*$//'`
exec defaultbrowser $url

RDesktop (requires XWindows)
rdesktop 192.168.1.1:3389 -u YourUsername -p - -g 1024x768

TightVNC (requires XWindows)
tightvnc -compresslevel 9 -quality 0 192.168.1.1

Network

Network Info
ifconfig [-a]

Ping
ping 192.168.1.1

Trace Route
traceroute 192.168.1.1

View Route Table
route [-n]

De-Active Network Interface
ifconfig eth0 down
rm /etc/dhcpc/dhcpcd-eth0.*

Active Network Interface
ifconfig eth0 up
rm /etc/dhcpc/dhcpcd-eth0.*
dhcpcd -d eth0

View Current Connections
netstat [-a]

DialUP/VPN (see: Dial Up Configuration or VPN Configuration)
pppd call MyConnection

killall pppd

WiFI Up (requires configuration)
modprobe ndiswrapper
echo "Configuring wireless network"
iwconfig wlan0 essid linksys mode Managed channel 2
iwconfig wlan0 key 777CCCFFFEEE6366FC7C312111
ifconfig wlan0 up
ifconfig
rm /etc/dhcpc/dhcpcd-wlan0.*
dhcpcd -t 10 -h puppypc -d wlan0

WiFI Down
ifconfig wlan0 down
rm /etc/dhcpc/dhcpcd-wlan0.*

Assign Static IP/Default Route
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 up
route add -net default gw 192.168.1.1

Read HTML or Text
wget http://www.puppylinux.com/news.htm∞ -O -

Save file from network or internet
wget http://www.puppylinux.com/news.htm∞ -O ~/news.htm

NetBios Name Lookup
nmblookup -A 192.168.1.1

Send to Messenger Service
echo 'your message here' | smbclient -M NetBios_Name

Firewall

Clear ALL
iptables -F; iptables -t nat -F; iptables -t mangle -F

Starting Connection Sharing
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to 192.168.1.2 echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -P INPUT DROP

Stopping Connection Sharing
iptables -t nat -D POSTROUTING -o eth1 -j SNAT --to 192.168.1.2 echo 0 > /proc/sys/net/ipv4/ip_forward

iptables -D INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -D INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -P INPUT ACCEPT

System

Running Processes
#ps
top

Get Module Info
modinfo ModuleName

Get Module Dependancies
depmod ModuleName

List Loaded Modules
lsmod

Load Module
modprobe ModuleName

UnLoad Module
rmmod ModuleName

List PCI
lspci -v

List Disks and Partitions
#probepart
fdisk -l

Device Information
dmesg

File System

List Directory and Files
ls

Make Directory
mkdir /mnt/test

Delete Directory
rmdir /mnt/test

Make Empty File (directory path must exist)
touch /root/myfile

Delete File
rm /mnt/test

Make Squash File System
mksquashfs /root/mysystem /root/mysystem.sfs

Make ISO from CD or DVD
dd if=/dev/hdc of=MyFile.iso seek=0 bs=32k

Burn ISO to CD
cdrecord -data -eject -v speed=4 /dev/hdc puppylinux.iso

Format CDRW
cdrecord -v dev=/dev/hdc blank=fast

Burn ISO to DVD
growisofs -dvd-compat -Z /dev/hdc=MyFile.iso -speed=2

Verify CD Burn
exec readcd -c2scan -ts=32k dev=/dev/hdc MyFile.iso

Make MD5
md5sum YourFile.iso

Check MD5
md5sum -c YourMD5List.txt

Mounting and Unmounting

NTFS (read/write)
ntfsmount /dev/hda1 /mnt/hda1 -o force

NTFS Unmount (read/write)
fusermount -u /mnt/hda1

NTFS (readonly)
mount /dev/hda1 /mnt/hda1 -t ntfs -r

SquashFS (readonly)
mount /dev/hda1 /mnt/temp -t squashfs

Ext2/Ext3
mount /dev/hda1 /mnt/temp

ISO (readonly)
mount -r file.iso /mnt/cdrom -t iso9660 -o loop

Shared Drive
smbmount \\\\192.168.1.1\\c$ /mnt/tmp -o username=YourUsername password=

Shared Drive Unmount
smbumount /mnt/tmp

Image.gz
gzip -d image.gz
mount image /mnt/temp -o loop

initrd.gz
gzip -d initrd.gz
mount initrd /mnt/temp -o loop

usr_cram.fs
mount usr_cram.fs /mnt/temp -t squashfs -o loop

pup_save.3fs
mount pup_save.3fs /mnt/temp -o loop

pup_save.2fs
mount pup_save.2fs /mnt/temp -o loop

pup_xxx.sfs
mount pup_xxx.sfs /mnt/temp -t squashfs -o loop

Unmount /mnt/yourpath
umount /mnt/yourpath

Window Managers

*exit WM with ctrl+alt+backspace
*shutdown with ctrl+alt+del

Start Window Manager
xwin [jwm|icewm|xfce|enlightenment|fluxbox|startkde]
xwin jwm

Shutdown Computer
poweroff

Reboot Computer
reboot

Additional Software

PupGet (Puppy Linux Specific)
pupget

DotPup (Puppy Linux Specific)
dotpup

Mount Squash File System on the fly
mkdir mntpt
losetup /dev/loop2 devx_004.sfs
mount -t squashfs /dev/loop2 mntpt
cp -a --remove-destination mntpt/* /
umount mntpt

CVS Checkout
cvs -d:pserver:anonymous@server.com:/cvsroot/appname login
cvs -z3 -d:pserver:anonymous@server.com:/cvsroot/appname co -P main

CVS Update
cvs -z3 update -dPA

Compiling Applications
./configure --prefix=/usr --host=i486-pc-linux-gnu
make CFLAGS="-march=i486" CXXFLAGS="-march=i486"
make install
#or for alien package (or pet)
mkdir /myapp-1.0.0
make install DESTDIR=/myapp-1.0.0
cd /
tar -zcf myapp-1.0.0.tar.gz myapp-1.0.0
#for PET Package, then do:
tgz2pet myapp-1.0.0.tar.gz

Create and Working with PETget
tgz2pet YourPackage.tar.gz
pup2pet YourPup.pup
pet2tgz YourPet.pet
dir2pet YourDir

Compiling 2.6.18.1 Kernel
#!/bin/sh
cd /usr/src
wget http://www.puppyos.net/test/linux-2.6.18.1-source-patched_sfs_log_via.tar.bz2
rename linux-2.6.18.1 linux-2.6.18.1.old
tar -jxf linux-2.6.18.1-source-patched_sfs_log_via.tar.bz2
cd linux-2.6.18.1
make clean
make mrproper
rm -f .config
cp DOTconfig-K2.6.18.1-19OCT06 .config
#now is a good time for additional patches
make gconfig #Make config changes here
make
make modules
make modules_install



CategoryDocumentation