Delete files older than x days
Posted by Kelvin on 22 Mar 2011 | Tagged as: Ubuntu
Delete files older than 7 days:
cd /path/to/dir find -mtime +7 -exec rm {} \;
Change +7 to +14 for deleting files older than 14 days.
Reset wireless in Ubuntu 10.04 Lucid
Posted by Kelvin on 04 Mar 2011 | Tagged as: Ubuntu
Ever had your Intel wireless card play up on you in Ubuntu? You can't seem to reset it like the ethernet cards (i.e. with ifup and ifdown). Do this instead:
sudo rmmod iwlagn && sudo modprobe iwlagn
Replace iwlagn with your wireless card module name if you don't have an intel wireless card.
gnome and gedit shortcut awesomeness
Posted by Kelvin on 28 Feb 2011 | Tagged as: Ubuntu
Anyone on Ubuntu will probably have used gedit at one time or the other.
Well, gedit just got cooler.
Turns out you can map/remap shortcuts on all gnome-based applications including gedit by changing a simple setting.
1. Hit Alt-F2, enter gconf-editor
2. Go to desktop > gnome > interface
3. check can_change_accels
Now in gconf-editor, click the Edit menu, you should see a menu entry called "List Recent Keys". Move your mouse over the entry, then press any keyboard combination, say Ctrl-L. You should now see Ctrl-L on the right of "List Recent Keys".
Ha! You've now mapped Ctrl-L to the "List Recent Keys" menu item.
And you can do this for all apps which are gnome-compliant, including gedit of course…
Download google video and youtube from command-line
Posted by Kelvin on 22 Feb 2011 | Tagged as: Ubuntu
clive is an awesome tool for downloading google video and youtube flash videos from the command-line.
sudo apt-get install clive # download google video in flv clive http://video.google.com/videoplay?docid=-1388254997387483895 # download youtube in mp4 clive --format=mp4 http://www.youtube.com/watch?v=JPyuH4qXLZ0 # download list of URLs in file cat urls.txt | clive
Flatten folder/directory tree
Posted by Kelvin on 16 Jan 2011 | Tagged as: Ubuntu
For example, to move all mp3 files in sub directories into the current dir:
find . -name *.mp3 -exec mv {} . \;
Recursively copy only files with certain extension with rsync
Posted by Kelvin on 16 Jan 2011 | Tagged as: Ubuntu
Sometimes you want to get to all MP3 or PDF files which are nested in a deep directory tree. Here's what you do..
rsync -rvtW --delay-updates --modify-window=1 --progress --include='*.pdf' --include='*.xml' --exclude='*.*' source dest
Useful ffmpeg commands
Posted by Kelvin on 06 Dec 2010 | Tagged as: Ubuntu
Shameless ripped from http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs
Getting infos from a video file
ffmpeg -i video.avi
Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg
This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.
Turn a video to X images
ffmpeg -i video.mpg image%d.jpg
This command will generate the files named image1.jpg, image2.jpg, …
The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.
Encode a video sequence for the iPpod/iPhone
ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320×180 -title X final_video.mp4
Explanations :
Source : source_video.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4
Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320×240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4
Explanations :
Source : source_video.avi
Audio codec : aac
Audio bitrate : 32kb/s
Video codec : xvid
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4
Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Explanations :
Source video : source_video.avi
Audio bitrate : 192kb/s
output format : mp3
Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320×240 -f flv video_finale.flv
Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
Or:
ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg
Explanations :
target pal-dvd : Output format
ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320×240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720×576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg
Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2
Download youtube videos as mp3
Posted by Kelvin on 04 Dec 2010 | Tagged as: Ubuntu
For Ubuntu..
sudo apt-get install ffmpeg cd ~/bin wget https://github.com/rg3/youtube-dl/raw/2010.11.19/youtube-dl chmod +x youtube-dl wget http://www.supermind.org/scripts/youtube2mp3 chmod +x youtube2mp3
The contents of youtube2mp3 is simple:
#!/bin/bash #!/bin/bash x=/tmp/.youtube-dl-$RANDOM-$RANDOM.flv youtube-dl --output=$x --format=18 "$1" ffmpeg -i $x -vn -ar 44100 -ac 2 -ab 256k -f mp3 "$2"
Now get the youtube URL you want to convert to MP3, and run it like so:
youtube2mp3 <youtube_url>
For example:
youtube2mp3 http://www.youtube.com/watch?v=cFhaBEtmHeU
Move up multiple directories in bash
Posted by Kelvin on 04 Dec 2010 | Tagged as: Ubuntu
Ever thought typing cd.. 5 times was silly? Try this up() function!
Add this to .bash_profile or .bashrc
up () { if [ -z $1 ]; then cd .. elif [ $1 -gt 0 ]; then let count=0 while [ $count -lt $1 ]; do cd .. let count=count+1 done else echo "Argument must be a positive integer." fi pwd }
The script in action:
kelvin:~/java/search/apache-solr-1.4.0/src/java/org/apache/solr/search$ up 5 kelvin:~/java/search/apache-solr-1.4.0/src$
Recursively delete .svn folders
Posted by Kelvin on 04 Dec 2010 | Tagged as: Ubuntu
#!/bin/bash find ./ -name ".svn" | xargs rm -Rf