How do I remove all traces of SVN from my directory? - linux

I want it to be cleared of SVN, recursively, but of course keep my files.

You mean killing all the .svn directories? This should do it:
find -name '.svn' -type d -exec rm -rf {} ';'
EDIT: Updated from comments. Doh!

use find and look for the .svn directories
find . -name "FILE-TO-FIND"-exec rm -rf {} \;

You can fetch a new copy from the svn repository using the svn export command instead of svn checkout. The resulting tree will have no SVN bits in it.

Related

removing some files out of several folders

I have a question about removing some files out of several folders.
To be more specific: There are 5 Folders which are only the same by a few characters. For example: o1_FolderF_xy and zz_FolderF_34. And in each folder with the characters "FolderF" I want to delete all the files which starts with "filename".
The last time I did it by hand.
Will this work? Or do i need a script with a loop?
rm -rf /path/toFolder/*FolderF*/filename*
I'm sorry, I think for most it's a stupid question. But I'm new to all the stuff and I just do not want to go wrong with the delete
Your suggested command will work just fine.
You could use find instead:
find /path -name 'filename*' -exec rm {} \;
Basically it search's files with filename pattern on /path directory and for each file it executes rm.
Or, if you want to just check into those specific directories:
find /path -wholename '*folder*/filename*' -exec rm {} \;

Linux command to delete all files except .git folder?

I want to delete all of the current directory's content except for the .git/ folder before I copy the new files into the branch.
What's the linux command for that?
Resetting the index is cheap, so
git rm -rf .
git clean -fxd
Then you can reset the index (with git reset) or go straight on to checking out a new branch.
With find and prune option.
find . -path ./.git -prune -o -exec rm -rf {} \; 2> /dev/null
Edit: For two directories .git and dist
find . -path ./.git -prune -o \( \! -path ./dist \) -exec rm -rf {} \; 2> /dev/null
As Crayon mentioned in the comments, the easy solution would be to just move .git out of the directory, delete everything, and then move it back in. But if you want to do it the fancy way, find has got your back:
find -not -path "./.git/*" -not -name ".git" | grep git
find -not -path "./.git/*" -not -name ".git" -delete
The first line I put in there because with find, I always want to double-check to make sure it's finding what I think it is, before running the -delete.
Edit: Added -not -name ".git", which keeps it from trying to delete the .git directory, and suppresses the errors. Depending on the order find tries to delete things, it may fail on non-empty directories.
One way is to use rm -rf *, which will delete all files from the folder except the dotfiles and dotfolders like .git. You can then delete the dotfiles and dotfolders one by one, so that you don't miss out on important dotfiles like .gitignore, .gitattributes later.
Another approach would be to move your .git folder out of the directory and then going back and deleting all the contents of the folder and moving the .git folder back.
mv .git/ ../
cd ..
rm -rf folder/*
mv .git/ folder/
cd folder
for i in `ls | grep -v ".git"` ; do rm -rf $i; done; rm .gitignore;
the additional rm at the end will remove the special .gitignore. Take that off if you do need the file.
as CB Bailey mention:
I want to remove the history of tracker files too.
git rm -rf .
git clean -fxd
git update-ref -d refs/heads/master #or main or ...
should find all the files and directories that with the name .git
find . -name .git
should find all the file and directories not named .git
find . -not -name .git
delete all the files that you find
find . -not -name .git -exec rm -vf {} \;
be sure that the find is doing what you want
if you want to delete directories change the rm command to rm -rvf
I include the v option to see the files that are deleted.
if you want to make sure about the files before you delete them
pipe the find command to a file and review the results

How to remove a file with specific filename in Linux from all the folders inside current directory?

My project has a number of directories and also has a large number of sub-projects. When I move from one PC to another all the Makefiles are creating problems in building the project.
If I remove the Makefiles then there is no error in building. How can I remove all the Makefile* files from the parent directory in Linux? Is there any command to perform this? There are hundreds of Makefiles. So removing them one by one is hard. Please suggest a method to do this.
You can use -delete option.
find . -name "filename" -type f -delete
http://en.wikipedia.org/wiki/Find#Delete_files_and_directories
find . -name "name-here" -exec rm -rf {} \;
find . name "filename" -type f|xargs rm -rf

find and remove files with space using find command on Linux

I'm trying to remove all thumbs.db files in a Windows partition using find command in Ubuntu:
find . -iname "*.db"|while read junk;do rm -rfv $junk;done
But it's not working for me and nothing happens! I think I found the problem, the white spaces in directory names!
I did this trick to remove my junk files before on previous version of Ubuntu but now on latest version of Ubuntu I can't.
Is there any bug in my command?
I'd do it this way:
find . -iname 'thumbs.db' -exec rm -rfv {} +
This way, it still works even if your directories contain whitespace in their names.
just to throw this out there
find . -name "*.pyc" -delete
I'm not sure why you're using while.
find . -iname 'thumbs.db' -exec rm -rfv {} \;
...should suffice (and only delete the files you want to, not any BDB files that may be laying around).
The code looks good and works on arch and debian. Maybe there are no files matching "*.db"?
As a sidenote: I might not be a good idea to delete all files with the suffix ".db", because you can accidently delete other files than "Thumbs.db"
First check if the first part of your command, that is:
find . -iname "*.db"
is returning anything.
If it does then you can use xargs as follows to accomplish your task:
find . -iname "*.db" | xargs rm -rfv
UPDATE: From comments, this is unsafe, specially if there are spaces in directory/file names. You will need to use -print0 / xargs -0 to make it safe.

How to remove all .svn directories from my application directories

One of the missions of an export tool I have in my application, is to clean all .svn directories from my application directory tree. I am looking for a recursive command in the Linux shell that will traverse the entire tree and delete the .svn files.
I am not using export, as this script will be used for some other file/directory names which are not related to SVN. I tried something like:
find . -name .svn | rm -fr
It didn't work...
Try this:
find . -name .svn -exec rm -rf '{}' \;
Before running a command like that, I often like to run this first:
find . -name .svn -exec ls '{}' \;
What you wrote sends a list of newline separated file names (and paths) to rm, but rm doesn't know what to do with that input. It's only expecting command line parameters.
xargs takes input, usually separated by newlines, and places them on the command line, so adding xargs makes what you had work:
find . -name .svn | xargs rm -fr
xargs is intelligent enough that it will only pass as many arguments to rm as it can accept. Thus, if you had a million files, it might run rm 1,000,000/65,000 times (if your shell could accept 65,002 arguments on the command line {65k files + 1 for rm + 1 for -fr}).
As persons have adeptly pointed out, the following also work:
find . -name .svn -exec rm -rf {} \;
find . -depth -name .svn -exec rm -fr {} \;
find . -type d -name .svn -print0|xargs -0 rm -rf
The first two -exec forms both call rm for each folder being deleted, so if you had 1,000,000 folders, rm would be invoked 1,000,000 times. This is certainly less than ideal. Newer implementations of rm allow you to conclude the command with a + indicating that rm will accept as many arguments as possible:
find . -name .svn -exec rm -rf {} +
The last find/xargs version uses print0, which makes find generate output that uses \0 as a terminator rather than a newline. Since POSIX systems allow any character but \0 in the filename, this is truly the safest way to make sure that the arguments are correctly passed to rm or the application being executed.
In addition, there's a -execdir that will execute rm from the directory in which the file was found, rather than at the base directory and a -depth that will start depth first.
No need for pipes, xargs, exec, or anything:
find . -name .svn -delete
Edit: Just kidding, evidently -delete calls unlinkat() under the hood, so it behaves like unlink or rmdir and will refuse to operate on directories containing files.
There are already many answers provided for deleting the .svn-directory. But I want to add, that you can avoid these directories from the beginning, if you do an export instead of a checkout:
svn export <url>
If you don't like to see a lot of
find: `./.svn': No such file or directory
warnings, then use the -depth switch:
find . -depth -name .svn -exec rm -fr {} \;
In Windows, you can use the following registry script to add "Delete SVN Folders" to your right click context menu. Run it on any directory containing those pesky files.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
#="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
You almost had it. If you want to pass the output of a command as parameters to another one, you'll need to use xargs. Adding -print0 makes sure the script can handle paths with whitespace:
find . -type d -name .svn -print0|xargs -0 rm -rf
find . -name .svn |xargs rm -rf
As an important issue, when you want to utilize shell to delete .svn folders You need -depth argument to prevent find command entering the directory that was just deleted and showing error messages like e.g.
"find: ./.svn: No such file or directory"
As a result, You can use find command like below:
cd [dir_to_delete_svn_folders]
find . -depth -name .svn -exec rm -fr {} \;
Try this:
find . -name .svn -exec rm -v {} \;
Read more about the find command at developerWorks.
Alternatively, if you want to export a copy without modifying the working copy, you can use rsync:
rsync -a --exclude .svn path/to/working/copy path/to/export

Resources