I am using the following command to find a directory name.
find / -type d -name "ora10"
My problem is, I am not sure what the exact directory name is, so I would like to find directories similar to "ora10g", "ora10client", etc.
How can I do this with find?
find supports wildcard matches, just add a *:
find / -type d -name "ora10*"
Related
I need to delete file which is 14 days older.
CMD USED:
find ${FILES_DIR}/*.zip -mindepth 1 -mtime +14 -delete
This works fine. But what if there are no zip files present in the folder? It's throwing an error. How to handle the case?
The first parameter is where to start the search.
A filename-pattern is given with -name '<pattern>
You should use
find ${FILES_DIR} -name '*.zip' -mtime +14 -delete
In your form the find gets a list of starting points, but has nothing to search.
-mindepth 1 dosn't seem to have an effect. May be you wanted to use -maxdepth 1 to restrict the search to the mentioned directory and nothing else. (Place it before -nameto avoid a warning
You may consider using -ls -delete - at least you can see what has been deleted.
I see plenty of answers on how to list all symlinks and how to remove all symlinks within a specific directory. However what about vice versa?
How would one go about listing/removing all directories within a directory that are not symlinks?
I know that rm -R removes all directories recursively but i want to know how to make it not delete symlinks in the process.
I also know that ls lists all directories files and symlinks however i would like to know how i would go about listing only directories that are not symbolic links.
Found a way finally.
First, run:
find . -depth -type d
to make sure the output looks sane, then:
sudo find . -depth -type d -exec rm -rf '{}' \;
Sure this does get a bit messy on the console to look through, but ... it works! If anyone can find a better and cleaner way to do this please post it.
I am new to perforce and unix. While doing a 'p4 sync' was getting an error "can't clobber writable files" for some of my files.
I then did a "chmod -R 555 ./*" , thinking that it would remove the write permissions for the files that were giving me the above mentioned error. I didn't know that we have different permissions for directories and files in perforce. So now I have set r-x permissions for all directories and files, and now when I try to do a 'p4 sync' I am getting the following kind of error for all the files:
open for write: /home/path_to_file/tmp.18455.196170: Permission denied
What should I do to revert back the original permissions that perforce provides?
An easy way to apply different permissions to files vs directories is to use find, like so:
find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 444
This would apply permissions 755to directories and 444to files.
However, please note I don't know which permissions you have to apply in your case, you may want to look at another installation to get an idea. In your case I suspect the error message comes from the directories missing write permissions.
Also note that using an octal mask with chmod is not necessarily what you want, as it means "assign these permissions"; when you want to "remove" or "add", it's usually better to use a symbolic mode; for example, to remove all three write bits on files only, you would specify a-w(remove w to all fields):
find . -type f -print0 | xargs -0 chmod a-w
Finally, note that you can use find to recursively list permissions of all files and directories, for manual verification:
find . -ls
The error indicates that files in the workspace are writable, but have not been checked out by 'Perforce' (opened for edit).
If you want writable files to be overwritten by files you sync from Perforce, set the 'noclobber' option to 'clobber' in the client spec.
More information about this option and the 'p4 client' command is available here:
http://www.perforce.com/perforce/r15.1/manuals/cmdref/p4_client.html#p4_client.usage
Hope this helps,
Jen.
Hi I am trying to do a find and copy to multiple preferences folders within user files just a plist but coming up on an error. I am hopping someone can help point it out for me or help me understand what I'm doing wrong.
find . -type d -name 'Preferences' -maxdepth 3 -exec cp -r {} /Users/ladmin/Desktop/source.plist *Library/Preferences \;
Running just this
find . -type d -name 'Preferences' -maxdepth 3
prints out what I am trying to copy into username/Library/Preferences
Then I want to copy the plist to the preferences folder of every user.
I hope this isn't too complicated for people to read.
Thanks Kris
Not entirely sure why that should cause an error, though it does have several issues.
find is recursive and cp -r is recursive, and they are both traversing the same tree. You can add the -prune test to find to stop it from descending found directories
Not sure if this effects anything here, but find generally likes options (i.e. -maxdepth) to come first.
*Library/Preferences if this expands to multiple paths all but one of them will get copied into the last one.
But, I think the main issue is that you are trying to copy a bunch of directories named Preferences into a single directory, so only one of them will actually get copied, and the rest will get overridden out.
find -maxdepth 3 -type d -name 'Preferences' -prune -exec echo cp -ivr {} /Users/ladmin/Desktop/source.plist username/Library/Preferences +
This fixes all of the first issues, but it's not clear from the question what should happen when a directory with that name already exists. The -iv will prompt you if you want to override when conflicts occur and add some verbosity. The + speeds up execution of find for commands that can take multiple file/dir names (like cp).
I know that to find all the .h files I need to use:
find . -name "*.h"
but how to find all the .h AND .cpp files?
find . -name \*.h -print -o -name \*.cpp -print
or
find . \( -name \*.h -o -name \*.cpp \) -print
find -name "*.h" -or -name "*.cpp"
(edited to protect the asterisks which were interpreted as formatting)
Paul Tomblin Has Already provided a terrific answer, but I thought I saw a pattern in what you were doing.
Chances are you'll be using find to generate a file list to process with grep one day, and for such task there exists a much more user friendly tool, Ack
Works on any system that supports perl, and searching through all C++ related files in a directory recursively for a given string is as simple as
ack "int\s+foo" --cpp
"--cpp" by default matches .cpp .cc .cxx .m .hpp .hh .h .hxx files
(It also skips repository dirs by default so wont match on files that happen to look like files in them.)
A short, clear way to do it with find is:
find . -regex '.*\.\(cpp\|h\)'
From the man page for -regex: "This is a match on the whole path, not a search." Hence the need to prefix with .* to match the beginning of the path ./dir1/dir2/... before the filename.
find . -regex ".*\.[cChH]\(pp\)?" -print
This tested fine for me in cygwin.
You can use find in this short form:
find \( -name '*.cpp' -o -name '*.h' \) -print
-print can be omitted. Using -o just between expressions is especially useful when you want to find multiple types of files and do one same job (let's say calculating md5sum).