//Latest Tips
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
A "good" way of learning not to mistype ls.
Replace toto by foo in all file found by find.
It make a backup $file.bak
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
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
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
Generate a random 8 character password containing a-z, A-Z and 0-9:
egrep -ioam1 '[a-z0-9]{8}' /dev/urandomTo 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
apt-get install sl(or equivalent on your particular distro).
A "good" way of learning not to mistype ls.
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
Automatically import host keys for cluster of machines named 'all'
Using the 'dsh' command from the clusterit tools - http://sourceforge.net/projects/clusterit
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
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,
A '\' mark before a command will ignore aliases. For example, you have alias
and want use ls without that --color option
$ \ls
alias ls='ls --color=auto'
and want use ls without that --color option
$ \ls
Get an excuse in a single command...
form the BOFH...
form the BOFH...
echo `telnet bofh.jeffballard.us 666 2>/dev/null` |grep --color -o "Your excuse is:.*$"
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
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:
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.
" " 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.
Do a sha256sum of an entire directory name directory and check for integrity.
Modifying the IFS variable is necessary for filename with space.
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
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
It is possible to hide a rar archive inside a png image file and then retrieve the files from this image.
This can also be done on Windows:
When you want to retrieve the hidden files, download the image, rename to .rar and extract.
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.
Use this command to backup your del.icio.us bookmarks from the commandline with curl.
Or, using wget
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
We can use vim to make changes to a file all in one command, for example
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.
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.
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:
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:
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:
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
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
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")"; }
Use this command to find all the links in the current directory and below
find . -lname "*"
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
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:
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.
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.

