Iteratively remove file type - linux

I'm trying to delete the files that visual sourcesafe inserts into various folders. It's this file:
vssver2.scc
Since I have many nested folders, I'd like to do this recursively from the parent folder. What would the linux code be to delete all files with .scc extension? (I'm on a mac).
Thanks.

Look for them and remove:
find . -name "*.scc" -exec rm {} +
To make sure you are going to delete the correct files, you can replace the rm with ls so that it will show these files.
Also, you can replace find . with find /your/path to indicate the exact path from which you want to remove. With find . it will start from the current path.

find . -name ".scc" -print0 | xargs -0 rm -rf

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 {} \;

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

how to delete all files with a path pattern

I have a backup location, which uses hardlinks to store existing or changed files. The location of these backups mimick the linux file system with a date part in it.
For example I have files
/backup/servername/2012-06-26T00.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T06.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T06.43.01/www.website.com/file2.html
/backup/servername/2012-06-26T12.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T12.43.01/www.website.com/file2.html
How can I find all files which have www.website.com in them, so I can delete them
I have this command combination to delete files I can find with find, but I can't figure out how to find these files.
find . -name 'filename.*' -print0 | xargs -0 rm
You're being a little loose with your terminology, so it's a kind of tough to understand what exactly you want. However, if I understood you correctly, you want to delete all the files within a directory called www.website.com:
find . -wholename '*/www.website.com/*.html' -delete
if i understood you right you can use smth like this: find /backup/servername/2012-06-26T12.43.01/www.website.com/ -iname '*file*' -print0 | xargs -0 rm

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.

Bash script to recursively step through folders and delete files

Can anyone give me a bash script or one line command i can run on linux to recursively go through each folder from the current folder and delete all files or directories starting with '._'?
Change directory to the root directory you want (or change . to the directory) and execute:
find . -name "._*" -print0 | xargs -0 rm -rf
xargs allows you to pass several parameters to a single command, so it will be faster than using the find -exec syntax. Also, you can run this once without the | to view the files it will delete, make sure it is safe.
find . -name '._*' -exec rm -Rf {} \;
I've had a similar problem a while ago (I assume you are trying to clean up a drive that was connected to a Mac which saves a lot of these files), so I wrote a simple python script which deletes these and other useless files; maybe it will be useful to you:
http://github.com/houbysoft/short/blob/master/tidy
find /path -name "._*" -exec rm -fr "{}" +;
Instead of deleting the AppleDouble files, you could merge them with the corresponding files. You can use dot_clean.
dot_clean -- Merge ._* files with corresponding native files.
For each dir, dot_clean recursively merges all ._* files with their corresponding native files according to the rules specified with the given arguments. By default, if there is an attribute on the native file that is also present in the ._ file, the most recent attribute will be used.
If no operands are given, a usage message is output. If more than one directory is given, directories are merged in the order in which they are specified.
Because dot_clean works recursively by default, use:
dot_clean <directory>
If you want to turn off the recursively merge, use -f for flat merge.
dot_clean -f <directory>
find . -name '.*' -delete
A bit shorter and perform better in case of extremely long list of files.

Resources