Tag Archives: find

Ubuntu Server: Recursively Remove .svn Folders Tips, Tricks and Tutorials 17 FEB 2014

ubuntu-10-logoSometimes SVN repositories just go bad and the best way forward as far as what you are concerned is to simply wipe them and start out fresh. Of course, while you can simply delete the SVN repo directly to remove it and then quickly recreate it with a few commands, you obviously need to tread a little more carefully around your existing SVN checkout – basically the collection of folders and files that you’re going to be using to repopulate your shiny new SVN repository with!

If you forgot to export your current checkout before deleting your SVN repo or perhaps the repository was too damaged to allow for exporting, you now sit with the situation where your checked out folders and subfolders all contain the obligatory hidden .svn directory which Subversion uses to store its required metadata in.

So in order to continue, we need a method of recursively removing these .svn hidden folders.

Luckily, by chaining the Linux find command with the suitable remove command, achieving this is pretty damn quick.

First, scope out just what files are going to be affected by the recursive delete function by first rather echoing out a list of affected folders/files:

find . -name .svn -exec echo {} \;

If you are happy with the list, continue with the actual delete:

find . -name .svn -exec rm -rf {} \;

Done. Of course, it’s best not to be messing around with SVN repositories in this fashion, but like most bad options in life, sometimes it is just completely unavoidable.

Ubuntu: How to Search for a Folder via the Terminal CodeUnit 11 JAN 2011

Often you know that there exists a specific directory on your system, but you just can’t seem to locate it anywhere. Enter the useful find statement, a generic workhorse that you will most certainly find on almost all *nix distributions!

To locate a specific directory by name, simply run:

sudo find / -name directoryname -type d

This will print out the list of matching directory paths that can be located on the system. Note that the sudo isn’t strictly necessary, but helps if you suspect the folder to be lurking in one of the system protected directories!


Ubuntu: Delete Files Older than a Certain Number of Days via the Terminal CodeUnit 10 AUG 2010

For example, let’s say you currently do non-incremental backups of your data on a daily business. If you don’t keep an eye on it, pretty soon your backup folder will run out of space and your system would come crashing down – so maybe it isn’t such a bad idea to run a cron in the background that deletes unnecessary files that are older than a specified number of days.

So how do we do this?

Well one solution is to make use of the powerful little find utility that comes with pretty much any variant of Linux. What this littly beauty does is offer you a whole lot of useful arguments, one of the most interesting being that of specifying a command to run on each file found!

Leveraging this functionality, we will first use the find command to locate our files older than a nuber of days and then use the rm command to delete them.

So how would the syntax for this look then?

find /path/to/files* -mtime +7 -exec rm {} ;

(Note the spaces between rm, {} and ;)

The first argument is the path to the files, it being either a path, directory or even a wildcard as indicated above. Full path is probably the safest though!

The second -mtime argument is used to specify the number of days old a file needs to be in order to qualify for the search. If you enter +7 like we have, then find will return all files older than 7 days.

Finally, the -exec attribute allows us to pass our command (like rm) to the find function and apply it against each of the located files. The {} ; at the end is simply a control sequence to terminate the command.