Ubuntu – Using diff to compare a file and a directory


there is probably a simpler way to do this but I ran ls on the /media/user directory with no usb storage plugged in and saved the output to a file and I wanted to use diff to compare the file with a new usb plugged in and compare the file with the /media/user directory so that it detects the new directory in /media from the usb

I've used so far

ls > usbmedia.diff 
diff /home/user/desktop/scripts/usbmedia.diff /media/user/

the output I get is no /media/user/usbmedia.diff file so it is looking for a file of the same name but how do I get the diff command to not do that and compare the directory with the file

Best Answer

You're nearly right.

/tmp is better practice:


while:                                            # Go forever.
    ls /media/<USERNAME>/ > /tmp/media.diff
    sleep 10
    ls /media/<USERNAME>/ > /tmp/mediacompare.diff
    diff /tmp/media.diff /tmp/mediacompare.diff