Watch some log file for changes dynamically.
tail -f some_log_file
Print a file in reverse
tac
Print a file with numbered line output (many formatting options)
nl
Reformats the text file to lines no longer than 60 chars and forces uniform spacing (one space between words and two spaces between sentences).
fmt -u -w 60 some_file.txt > new_some_file.txt
Wraps input lines to a specified length.
echo xoxoxoxox | fold -w 3
A simple pattern translator.
echo "Hello World." | tr "[a-z]" "[A-Z]" outputs HELLO WORLD.
Strip off the directory, and optionally, the file suffix parts of a file path.
basename srcs/C/main.c outputs main.c
Display the containing directory path, as much of the path as is provided.
dirname /homes/curly/.profile outputs /homes/curly
Execute a command periodically.
watch -n 5 ls -l /mnt/zippy1
Convert jpegs to half their resolution and 50 percent compression.
djpeg -scale 1/2 source.jpg | cjpeg -quality 50 > dest.jpg
execute a command on specified files
find . -iname *.txt -exec ls -l '{}' \;
find files modified after a certain time
find . -mtime -1
command line search and replace
sed s/old-string/new-string/g file.txt
take a screen shot
xwd | convert xwd:- png:screenshot.png
Trap a Signal in a Bash Script (CTRL-C = 2)
trap 'echo "stopping server..."; exit 0' 2
Autologin to ftp sites
put "machine 'some_machine_name' login 'your_username' password 'your_password' " into your .netrc file and chmod it to 600
format a fat32 partition
mkfs.vfat -F 32 /dev/hda1
reconfigure network interface with specified params
ifconfig eth0 192.168.1.15 netmask 255.255.255.0
Create a filesystem in a file and mount it with the loopback interface
dd if=/dev/zero of=fs.img bs=1k count=1024; mke2fs -m0 fs.img; mount -o loop fs.img /mnt/loop
configure startup services on debian
rcconf
Take a Screenshot (uses ImageMagick)
import -resize 800x600 `date +%H-%M-%S`.jpg
Image a hard drive (uses partimage.. you need to check the filesystem first with something like "e2fsck -fp /dev/hda1")
partimage -odb -f3 -z1 -V650 save /dev/hda1 /mnt/temp/hda1_image.gz
Turn off the stinking bell.
(console) setterm -bfreq (xterm) xset -b
Suppress some of the error messages printed to the console.
setterm -msglevel [0-8] 0 is no mesgs 8 is all mesgs
Query the wireless link level.
wlanctlng wlan0 lnxreq_commsquality
tar up hidden files (like your home directory)
tar -cjf home.tar.bz2 .??*
obtain your ip address in a bash script
/sbin/ifconfig | grep -i ethernet -A 1|grep "inet addr"|cut -d " " -f 12|cut -d ":" -f 2
Create mpeg from frames (requires ImageMagick and mpeg2encode from ftp://ftp.mpeg.org/pub/mpeg/mssg/
import -window win_id capture.miff (in a bash loop); convert -delay 20 *.miff capture.mpg
Setup ssh,scp etc.. with no password prompt
ssh-keygen -t rsa; scp ~/.ssh/id_rsa.pub user@remote_host:.ssh/authorized_keys;
encrypt/decrypt and view a text file
ccrypt -e somefile.txt; ccrypt -c somefile.txt.cpt
Find out what application is using a specific mount point.
fuser -m -u /mnt/point
mount a cloop filesystem
losetup /dev/cloop /path/to/cloop.img; mount /dev/cloop /mnt/point
mount a usb floppy drive
mount /dev/sda /mnt/usbfd
Setup a ssh tunnel to a remote machine
ssh www.host.com -L 8080:localhost:80 sleep 99999
Virtual CD Drive
cp /dev/cdrom mycd.iso; mount -o loop mycd.iso /mnt/cdrom/
Make a local viewable version of a website
wget -rEKk http://www.website.com
find which package a file belongs to
dpkg -S ls
Backup Your DVDs
mencoder dvd://1 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1024 -vf scale=400:-2 -oac copy -o /share/movie.avi
Securely VNC the current session of a remote machine
remotely: x11vnc -display :0 locally: ssh -C -L 5900:localhost:5900; vncviewer localhost
Validate XML document against a XSD
xmlstarlet val -e -s example.xsd example.xml
remote backup with ssh
tar -cjf - directory | ssh remotehost "cat > backup.tar.bz2"
restore remote backup with ssh
ssh remotehost "cat backup.tar.bz2" | tar -jxvf
watch network usage
iftop
Network Snooping on the Command Line
tcpdump port 1234 -X
Rotate your video 90 degrees clockwise
mencoder source.avi -o dest.avi -oac copy -ovc lavc -vf rotate=1
show which program has a certain port open
(as root) lsof -i:1234
using apt via a http proxy
export http_proxy=http://myproxy:myport; apt-get update
fix aterm and rxvt rendering problem with utf8 fonts
dpkg-reconfigure locales (select en_US.ISO-8859-1 and en_US as default)
make an image of a floppy drive
dd if=/dev/sda of=floppy.img bs=1k count=1440
make a bootable cdrom image
mkdir -p bootable_cd/boot; cd bootable_cd; mkisofs -r -b boot/boot_floppy.img -c boot/boot.catalog -o bootcd.iso .
Get your user, group and other identification info.
id
Check a disk drive for bad blocks
fsck -a -C -c /dev/hda1; fsck -a -C -cc /dev/hda1; badblocks /dev/hda1
Capture Desktop Video
ffmpeg -f x11grab -s xga -r 25 -i :0.0 -sameq /tmp/out.mpg
print a nice looking calendar
cal 2010 | lpr -l
|