Tuesday, November 8, 2011

mv: cannot move `./directory1' to `../directory2': Directory not empty

I wanted to move all files from one directory structure to another, for me I had an updated version of a lot of website files and I wanted to update them all in one go so I tried:

mv ./directory1/* ./directory2/

Because I have lots of files within sub-directories on both folders the mv command wouldn't play nice and kept throwing this "Directory not empty" error, even doing an "mv -f" to force overrides didn't work..

After search around people have come up with elaborate bash scripts to do the task, and I like to throw a bash script together every now and again but in this situation it's really not necessary, we just need to use rsync:

rsync -avh ./directory2/ ./directory1/

That rsync command will override all the files in directory1 with the files in directory2 and recurse through all sub-directories, it will override them regardless if they're older/newer/different sized etc so do a backup of your original directory before running the command

Rsync is a great tool and you can do so much more than just synchronising local folders, for more advanced options (like only overwriting newer files etc) check out the man page for rsync here: http://linux.die.net/man/1/rsync

Hope this helps somebody out.

Monday, April 25, 2011

Converting flash video to mpg using ffmpeg in linux ubuntu

Converting flash video to mpg using ffmpeg in linux ubuntu.. I posted a script recently to extract flash videos from your web browsers cache in linux, sometimes flvs can be missing parts that stop you from skipping forward etc but ffmpeg converts most video formats easily so we just need to apt-get it:
sudo apt-get install ffmpeg
I'm not going to into too much depth with ffmpeg here other than to convert an flv to an mpg, I recommend checking out the ffmpeg documentation for anything specific, you can also google it from here:

Another option is, if your looking for the GUI way to convert videos in Linux, to use WinFF which you easily install by adding a repository in ubuntu: http://code.google.com/p/winff/wiki/UbuntuInstallation

What I wanted to be able to do was convert all of the flv's I had in a directory to mpg's, to do this using ffmpeg simply:
ffmpeg -i input.flv output.mpg
ffmpeg's clever enough to figure the rest out for itself, there are many options you can us, I decided just to set the frame size to 800x600 for simplicity (-s 800x600) so my final ffmpeg command was:
ffmpeg -i input.flv -s 800x600 output.mpg
In another post I posted a script to extract flash videos from the web browser cache and put them into a separate directory for storage (click here to read this post) so this script is an extension of that script to convert all flv's into mpeg and put them into a video directory:
#!/bin/bash
INPUTDIR=~/Videos/flvs
OUTPUTDIR=~/Videos

for f in $INPUTDIR/*.flv
do
    a=$(basename $f | cut -f1 -d '.')
    ffmpeg -i "$f" -s 800x600 "$OUTPUTDIR/$a.mpg"
done
This may take some time to complete depending on how many flash flv files you have the input directory.. I generally use my cache flash extractor bash script then sift through the flvs directory deleting what I don't want, then convert the videos I want to keep.

If you find it useful let me know..

Thursday, April 21, 2011

Creating an ISO of a DVD in Linux Ubuntu and mounting it as a drive

I'm going to create an ISO of a DVD and mount the .iso file so it appears as a DVD drive, I'll be doing this in Linux Ubuntu 10.

There's many reasons why you might want to do this, I've got some DVD's that I don't want to lose and by this time we've all reaslised that CD's and DVD's are almost as unreliable as floppy disks were.. that ever dreaded sound of the drive choking on your favourite movie.. lost forever, or having to wait for it to arrive from Amazon

We're going to create the ISO with Brasero which comes with Ubuntu, if it's not installed (Applications -> Sound & Video -> Brasero Disc Burner) then just apt-get it:
sudo apt-get install brasero
With brasero it's easy to either copy a CD/DVD or create an ISO of it however it didn't work for me out of the box due to a missing library:
Please install the following manually and try again:
libdvdcss.so.2 (library).
To fix this we need to add the medibuntu repository:
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
The medibuntu is a very useful repository that contains packages excluded from the main ubuntu repository's for legal reasons.

Then we're able to install the missing library we need:
sudo apt-get install libdvdcss2
Open up brasero and select "Disk Copy" under "Create a new Project" on the left, the "Copy CD/DVD" dialog will appear, select "Image File" from the "Select a disc to write to" drop down menu, click the "Properties" button to change the output file location and click "Create Image".

Depending on the size of the CD/DVD it may take some time to create the image.

Once it's complete you can mount the ISO of the DVD, remove the DVD from the drive and watch it direct from the hard drive.. it also improves speed when converting a DVD to a compressed video format which I'll cover in the next post, for now let's mount the iso as a drive.

To do this we mount the ISO as a loop device, but first we must create a directory to mount it to:
sudo mkdir -p /mnt/iso
 Then mount it:
sudo mount -o loop mydvd.iso /mnt/iso
The "Open DVD from folder" option in SMPlayer works perfectly and of course you can now burn this ISO to a blank DVD using Brasero.

Tuesday, April 19, 2011

Connecting a nokia n70 to Ubuntu 10 via usb

I've got some photos stored on a nokia n70 that I need to download to my laptop running Ubuntu 10, I have the usb cable ready so what happens when I connect it?

The Network Manager picks it up straight away as a mobile broadband device so it's looking good, but I don't need to use the phone to connect to the internet.. my Huawei usb dongle works straight out of the box with Ubuntu

To upload/download files to/from the Nokia n70 we need to use obexftp, it comes with a gui version called obextool so let's install them both:

sudo apt-get install obextool obexftp

I ran obextool straight away but it didn't work out of the box with the nokia for some reason.. so let's use obexftp to see if it can pick up the phone:

sudo obexftp -u
Found 2 USB OBEX interfaces


0 (Manufacturer: Nokia Product: Nokia N70 Serial: (null) Interface description: SYNCML-SYNC)
1 (Manufacturer: Nokia Product: Nokia N70 Serial: (null) Interface description: PC Suite Services)


Use '-u interface_number' to connect

It's found the phone, let's see if it can connect and list the drives on the phone (internal and memory card):

sudo obexftp -u 1 -l
Connecting..\done
Tried to connect for 16ms
Receiving "(null)"...|<?xml version="1.0"?>
<folder-listing version="1.0">
   <folder name="C:" user-perm="RW" mem-type="DEV" label="Phone memory"/>
   <folder name="E:" user-perm="RW" mem-type="MMC" label="Memory card"/>
</folder-listing>
Disconnecting../done

Success!

The obextool gui had trouble connecting before, so let's tell it how to connect:

sudo obextool --obexcmd "obexftp -u 1"

I can now download the images from my nokia n70 to my Ubuntu desktop:




I hope somebody finds this useful.. please make a comment if you have any questions

Friday, April 1, 2011

Saving watched online videos in linux, firefox cache flash extractor bash script

I recently upgraded to Ubuntu 10.10 and needed to rewrite a couple of useful scripts I use.

Here's a simplified version of a bash script that reads your firefox cache, finds flash files over a certain size, saves them in directory and opens the directory with nautilus to browse the extracted videos/flash files:

#!/bin/bash
# flvcache script

CACHE=~/.mozilla/firefox/xxxxxxxx.default/Cache
OUTPUTDIR=~/Videos/flvs
MINFILESIZE=2M

for f in `find $CACHE -size +$MINFILESIZE`
do
    a=$(file $f | cut -f2 -d ' ')
    o=$(basename $f)
    if [ "$a" = "Macromedia" ]
        then
            cp "$f" "$OUTPUTDIR/$o"
    fi
done

nautilus  "$OUTPUTDIR"&

Remember to chmod 755 the file so you can execute it from the command line.

Change the variable CACHE to your firefox cache location, it'll be somewhere like: ~/.mozilla/firefox/xxxxxxxx.default/Cache

Create a directory to save them into, I chose:
mkdir ~/Videos/flvs

I hope somebody finds this useful.

The script is presented in a simplified format to show bash scripting, you can see how to: use a for loop using bash, load output from external programs into a variable using bash and use an if statement using bash.