//Latest Tips
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
This script will run check a for the Ubuntu 9.10 launch once every 5 mins and let you know when it's available:

while [ 1 ]; do if [ -z "`curl -I "http://cdimage.ubuntu.com/releases/9.10/release/"|grep "404"`" ];
then kdialog --msgbox "9.10 Released"; exit; fi; sleep 300;  done


View Comments »


Want to check the amount of used, free and total memory and swap from the command line? This script displays memory and swap information. Fully posix compliant and should work with all 2.[2-6].* kernels .

#fetch and process memory information
[ -f /proc/meminfo ] && {
Buffers=`grep -we 'Buffers' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
Cached=`grep -we 'Cached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
MemFree=`grep -ie 'MemFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
MemTotal=`grep -ie 'MemTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
SwapCached=`grep -ie 'SwapCached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
SwapFree=`grep -ie 'SwapFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
SwapTotal=`grep -ie 'SwapTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`
}
MEMUSED="$(( ( ( ( $MemTotal - $MemFree ) - $Cached ) - $Buffers ) / 1024 ))"
MEMTOTAL="$(( $MemTotal / 1024))"
MEMFREE="$(( $MEMTOTAL - $MEMUSED ))"
MEMPER="$(( ( $MEMUSED * 100 ) / $MEMTOTAL ))"
[ "$SwapTotal" -gt "1" ] && {
  SWAPUSED="$(( ( ( $SwapTotal - $SwapFree ) - $SwapCached ) / 1024 ))"
  SWAPTOTAL="$(( $SwapTotal / 1024))"
  SWAPFREE="$(( $SWAPTOTAL - $SWAPUSED ))"
  SWAPPER="$(( ( $SWAPUSED * 100 ) / $SWAPTOTAL ))" 
} || {
  SWAPUSED="0"
  SWAPTOTAL="0"
  SWAPPER="0" 
}

# display the information
/bin/echo
/bin/echo "Memory"
/bin/echo "Used: $MEMUSED"
/bin/echo "Free: $MEMFREE"
/bin/echo "Total: $MEMTOTAL"
/bin/echo
/bin/echo "Swap"
/bin/echo "Used: $SWAPUSED"
/bin/echo "Free: $SWAPFREE"
/bin/echo "Total: $SWAPTOTAL"
/bin/echo


View Comments »

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480,harddup -srate 48000 
-af lavcresample=48000 -lavcopts  
codec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:aspect=16/9:acodec=ac3:abitrate=192 
-ofps 30000/1001 -o output.mpg input.extension


Options you might want to change:

scale: 720:480 for NTSC, 720:576 for PAL
ofps: 30000/1001 for NTSC, 25 for PAL
aspect: 16/9 or 4/3 depending on your video


View Comments »

Generate a random 8 character password containing a-z, A-Z and 0-9:

egrep -ioam1 '[a-z0-9]{8}' /dev/urandom


View Comments »

To find the last modified files in a directory you can use ls -ltr. To find the last modified file on a file system it will not work, but the following command will work:

find /etc -type f -printf "%T@ %T+ %p" | sort -n


View Comments »

apt-get install sl
(or equivalent on your particular distro).

A "good" way of learning not to mistype ls.


View Comments »

Displays a random xkcd comic. Requires ImageMagick.

wget http://dynamic.xkcd.com/comic/random/ -O -| grep <img src="http://imgs.xkcd.com/comics | 
 sed s/<img src="// | sed s/"[a-z]*.*// | wget -i - -O -| display


View Comments »

Automatically import host keys for cluster of machines named 'all'

Using the 'dsh' command from the clusterit tools - http://sourceforge.net/projects/clusterit

RCMD_CMD_ARGS='-o VerifyHostKeyDNS=yes -o StrictHostKeyChecking=no' dsh -g all -e true


View Comments »

The following bash script, which depends on lynx web browser, uses Google's reverse geocode service to find a nearby address given a latitude and longitude pair:

#!/bin/bash
# findnearest
# Usage: findnearest latitude longitude
# Ex.  findnearest  17.976227 -66.111016

lat=$1
long=$2
result=$(lynx -dump "http://maps.google.com/maps/geo?output=csv&oe=utf-8&ll=$lat,$long")
echo $result | cut -f3- -d,


View Comments »


A '\' mark before a command will ignore aliases. For example, you have alias

alias ls='ls --color=auto'

and want use ls without that --color option

$ \ls


View Comments »

Get an excuse in a single command...

form the BOFH...

echo `telnet bofh.jeffballard.us 666 2>/dev/null` |grep --color -o "Your excuse is:.*$"


View Comments »

This short script reads a file line-by-line ( whith whitespace characters too ) and outputs to STDOUT.

#!/bin/bash
FILE='/path/to/filename'
for linecount in `seq $(cat $FILE | wc -l)`; do
line=`head -n$linecount $FILE | tail -1`
echo $line
done


View Comments »

If you spend a lot of time creating new shell scripts then it can be very useful to make them executable by default. To do this in Vim add the following lines to the end of your ~/.vimrc file - creating it if necessary:

"
" automatically give executable permissions if file begins with #! and contains
" '/bin/' in the path
"
au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod a+x <afile> | endif | endif


This code will automatically change the file to executable if the first line contains both "#!" and "/bin/".

Once you add #!/bin/sh (for example) to the start of a file and save it, the file will be immediately executable.


View Comments »

Do a sha256sum of an entire directory name directory and check for integrity.
Modifying the IFS variable is necessary for filename with space.

$ IFS='
'
$ for i in $(find directory -type f -print);do sha256sum "$i";done > directory.SHA256SUM
$ sha256sum -c directory.SHA256SUM


View Comments »

find . -name *whatyouwant* -exec perl -pi.bak -e 's/toto/foo/g' {} \;

Replace toto by foo in all file found by find.
It make a backup $file.bak


View Comments »

It is possible to hide a rar archive inside a png image file and then retrieve the files from this image.

cat picture.png archive.rar > hidden_archive_in_pic.png

This can also be done on Windows:

copy picture.png + archive.rar hidden_archive_in_pic.png

When you want to retrieve the hidden files, download the image, rename to .rar and extract.


View Comments »

Use this command to backup your del.icio.us bookmarks from the commandline with curl.

curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all

Or, using wget

wget --user=username --password=password https://api.del.icio.us/v1/posts/all -O bookmarks.xml


View Comments »

We can use vim to make changes to a file all in one command, for example

vim -c "5,10s/a/b/g | wq" filename

This will open the file 'filename' and replace all occurances of 'a' with 'b' on lines 5-10. The file will then be written and closed. To edit the file after the change, just remove the ' | wq' from the end of the command.


View Comments »

A remote Windows PC can easily be shutdown, assuming you have Samba installed on your Linux box, and you have a user account on the Windows PC that has the necessary rights.

Just enter the following command, where 'thehostname' is the hostname of the remote PC, and 'theusername' is a valid user account on the remote PC:

net rpc shutdown -S thehostname -U theusername

If the hostname is not known, or cannot be resolved, then use the following instead, replacing '111.111.111.111' with the IP address of the remote PC:

net rpc shutdown -I 111.111.111.111 -U theusername

Additionally, the parameters that can be used with Windows' own shutdown command such as '-f' to force or '-t' to set a timeout, can also be applied to the net rpc shutdown command as well. For example the following will wait 60 seconds, and then force all running programs to terminate before shutting down:

net rpc shutdown -S thehostname -U theusername -f -t 60


View Comments »

Use the command below to record a screencast and save it as an mpeg:

ffmpeg -f x11grab -s 800x600 -i :0.0 /tmp/screencast.mpg


View Comments »

Use the one liner below to relocate a file or directory, but keep it accessible on the old location through a symlink.

lmv() { [ -e "$1" -a -d "$2" ] && mv "$1" "$2"/ && ln -s "$2"/"$(basename "$1")" "$(dirname "$1")"; }


View Comments »

Use this command to find all the links in the current directory and below

find . -lname "*"


View Comments »

A few quick ways to empty a file of text in vi (all of these are done in command mode):

:1,$d
--
:1[enter]dG
--
ggdG


View Comments »

Last time, I had to install a package with a configure Script. There are a lot of parameters to adjust the installation. Unfortunately the configure doesn't end with success. A dubios error message appears and I don't find out what's wrong.
Also the modern oracle 'google' doesen't give a hint. But after hours I find a quick and easy solution:

sh -x ./configure ... configure_options ...

First there is a long rolling of letters, but afterwards, when the error appears, you can easy find out what the mistake is, because the debug modus tells you.


View Comments »



Home Latest Browse Top 25 Random Hall Of Fame Contact Submit