files

Finding files in Linux/Mac Terminal

Finding files is a little different to MS DOS!

find <startlocation> <type> <filename> <exec>

The exec is a simple way of performing functions on the results. If you leave it off, the find doesn’t really do anything.

So, the simplest thing to do is find a file, so the exec becomes the output:

find / -name wkhtmltopdf* -exec ls -ls {} \;

That will find all files starting with wkhtmltopdf starting from / and the function to run on it is ls -ls {} \;

The {} will be replaced with the search result, so, in essence, ls -ls filename; will show you the details about the file which is what I want, as I am looking for all copies of the wkhtmltopdf toolkit on the server.

You can obviously change the exec to delete the files, or copy/move them, or interrogate further…

Keeping 2 drives sync’ed with rsync on Linux

I have an external USB HDD and I like to keep it synchronised with my desktop for backup reasons. I find the easiest way to do this, is to use rsync:

> sudo apt-get install rsync
> rsync -avu /source/ /dest/

For example:

> rysnc -avu /media/externaldisk/ /home/chris/diskbackup/

Will increment copy everything (ignoring older files) from /media/externaldisk to my /home/chris/diskbackup folder.

The options are:

  • a – Archive mode – Will retain the folder/file properties, such as owner, permissions, etc.
  • v – Verbose – Output the progress to the screen (so I know its still working)
  • u – Update – Only update files that have a more recent file modified date.