find interview questions
Top find frequently asked interview questions
I often use the find
command to search through source code, delete files, whatever. Annoyingly, because Subversion stores duplicates of each file in its .svn/text-base/
directories my simple searches end up getting lots of duplicate results. For example, I want to recursively search for uint
in multiple messages.h
and messages.cpp
files:
# find -name 'messages.*' -exec grep -Iw uint {} +
./messages.cpp: Log::verbose << "Discarding out of date message: id " << uint(olderMessage.id)
./messages.cpp: Log::verbose << "Added to send queue: " << *message << ": id " << uint(preparedMessage->id)
./messages.cpp: Log::error << "Received message with invalid SHA-1 hash: id " << uint(incomingMessage.id)
./messages.cpp: Log::verbose << "Received " << *message << ": id " << uint(incomingMessage.id)
./messages.cpp: Log::verbose << "Sent message: id " << uint(preparedMessage->id)
./messages.cpp: Log::verbose << "Discarding unsent message: id " << uint(preparedMessage->id)
./messages.cpp: for (uint i = 0; i < 10 && !_stopThreads; ++i) {
./.svn/text-base/messages.cpp.svn-base: Log::verbose << "Discarding out of date message: id " << uint(olderMessage.id)
./.svn/text-base/messages.cpp.svn-base: Log::verbose << "Added to send queue: " << *message << ": id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base: Log::error << "Received message with invalid SHA-1 hash: id " << uint(incomingMessage.id)
./.svn/text-base/messages.cpp.svn-base: Log::verbose << "Received " << *message << ": id " << uint(incomingMessage.id)
./.svn/text-base/messages.cpp.svn-base: Log::verbose << "Sent message: id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base: Log::verbose << "Discarding unsent message: id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base: for (uint i = 0; i < 10 && !_stopThreads; ++i) {
./virus/messages.cpp:void VsMessageProcessor::_progress(const string &fileName, uint scanCount)
./virus/messages.cpp:ProgressMessage::ProgressMessage(const string &fileName, uint scanCount)
./virus/messages.h: void _progress(const std::string &fileName, uint scanCount);
./virus/messages.h: ProgressMessage(const std::string &fileName, uint scanCount);
./virus/messages.h: uint _scanCount;
./virus/.svn/text-base/messages.cpp.svn-base:void VsMessageProcessor::_progress(const string &fileName, uint scanCount)
./virus/.svn/text-base/messages.cpp.svn-base:ProgressMessage::ProgressMessage(const string &fileName, uint scanCount)
./virus/.svn/text-base/messages.h.svn-base: void _progress(const std::string &fileName, uint scanCount);
./virus/.svn/text-base/messages.h.svn-base: ProgressMessage(const std::string &fileName, uint scanCount);
./virus/.svn/text-base/messages.h.svn-base: uint _scanCount;
How can I tell find
to ignore the .svn
directories?
Update: If you upgrade your SVN client to version 1.7 this is no longer an issue.
A key feature of the changes introduced in Subversion 1.7 is the centralization of working copy metadata storage into a single location. Instead of a .svn
directory in every directory in the working copy, Subversion 1.7 working copies have just one .svn
directory—in the root of the working copy. This directory includes (among other things) an SQLite-backed database which contains all of the metadata Subversion needs for that working copy.
Source: (StackOverflow)
I have come across this delightful:
item = someSortOfSelection()
if item in myList:
doMySpecialFunction(item)
but sometimes it does not work with all my items, as if they weren't recognized in the list (when it's a list of string).
is it the most 'pythonic' way of finding an item in a list: if x in l:
?
Source: (StackOverflow)
I'm trying to find all of the symlinks within a directory tree for my website. I know that I can use find
to do this but I can't figure out how to recursively check the directories.
The command I'm using at the moment is
find /var/www/ -type l
How do I get this to check subdirectories?
Update:
I just discovered that the contents in /var/www are symlinks. I've changed the command to
find -L /var/www/ -type l
and it take a while to run, however I'm getting no matches.
Source: (StackOverflow)
Does Eclipse have a way to search a whole project for some text? Like Xcode's "find in project" feature.
Source: (StackOverflow)
I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this?
Source: (StackOverflow)
I have an app which is signed and several keystore files. I'd like to update the app, so I need to find out which one of keys was used.
How can I match which keystore was used to originally sign my app against various keystores I have on my machine?
Source: (StackOverflow)
Is it possible to use the find
command in some way that it will not recurse into the sub-directories? For example,
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
And the result of something like find DirsRoot --donotrecuourse -type f
will be only File1, File2
?
Source: (StackOverflow)
I'm using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt
and I want to get file.txt
Source: (StackOverflow)
I'm using the following command in my web application to find all files in the current directory that contain the string foo
(leaving out svn directories).
find . -not -ipath '.*svn*' -exec grep -H -E -o "foo" {} \; > grep_results.txt
How do I find out the files that doesn't contain the word foo
?
Source: (StackOverflow)
I am doing a find
and then getting a list of files. How do I pipe it to another utility like cat
(so that cat displays the contents of all those files) and basically need to grep
something from these files.
Source: (StackOverflow)
Hi I have the following dictionary in python:
d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'}
I need a way to find if a value such as "one" or "two" exists in this dictionary.
For example, if I wanted to know if the index "1" existed I would simply have to type:
"1" in d
And then python would tell me if that is true or false, however I need to do that same exact thing except to find if a value exists. Thanks for any help.
Source: (StackOverflow)
I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory?
Here is the find code we're using.
for file in $(find . -name '*.js'); do java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file; done
Source: (StackOverflow)
I need to hide all permission denied messages from:
find . > files_and_folders
I am experimenting when such message arises. I need to gather all folders and files, to which it does not arise.
Is it possible to direct the permission levels to the files_and_folders
file?
How can I hide the errors at the same time?
Source: (StackOverflow)
Suppose I have a file similar to the following:
123
123
234
234
123
345
I would like to find how many times '123' was duplicated, how many times '234' was duplicated, etc.
So ideally, the output would be like:
123 3
234 2
345 1
Source: (StackOverflow)