find

Rails - HABTM Relationship — How Can I Find A Record Based On An Attribute Of The Associated Model

一个人想着一个人 提交于 2019-12-17 22:37:12
问题 I have setup this HABTM relationship in the past and its worked before....Now it isnt and I'm at my wits end trying to figure out whats wrong. I've looking through the rails guides all day and cant seem to figure out what I'm doing wrong, so help would really be appreciated. I have 2 models connected through a join model and I'm trying to find records based an attribute of the associated model. Event.rb has_and_belongs_to_many :interests Interest.rb has_and_belongs_to_many :events and a join

Using `find -perm` to find when a permission is not set

左心房为你撑大大i 提交于 2019-12-17 22:33:39
问题 I want to find the non-readable files in my directory (eg the files with g-r). So I tried this: find . -perm -g-r It shows me all of the files?? So I tried this: find . -perm -g+r And it showed me only the readable files. It appears that -perm -g-r matches all files. I'm using CentOS 5.5. Am I doing something wrong? It doesn't look like -perm -g-r does anything useful. 回答1: Try: find . ! -perm -g+r 回答2: If you want to find files that are non-readable by you , you could use find . ! -readable

Linux why can't I pipe find result to rm?

≡放荡痞女 提交于 2019-12-17 21:44:23
问题 sorry if this is a noobie question but I can't find a good answer. To find then remove something I can use find . -name ".txt" -exec rm "{}" \; But why can't I just pipe the results to rm like find . -name ".txt" | rm like I would pipe it to grep find . -name ".txt" | grep a I've read from somewhere that rm doesn't take input from stdin and therefore I can't pipe it but what does that mean? When I type in rm a.txt it reads from standard input just like I can grep right? Or is there a

Capitalize first letter of each word in a selection using vim

混江龙づ霸主 提交于 2019-12-17 21:42:04
问题 In vim, I know we can use ~ to capitalize a single char (as mentioned in this question), but is there a way to capitalize the first letter of each word in a selection using vim? For example, if I would like to change from hello world from stackoverflow to Hello World From Stackoverflow How should I do it in vim? 回答1: You can use the following substitution: s/\<./\u&/g \< matches the start of a word . matches the first character of a word \u tells Vim to uppercase the following character in

Linux find file names with given string

柔情痞子 提交于 2019-12-17 21:27:27
问题 I'm on Ubuntu, and I'd like to find all files in the current directory and subdirectories whose name contains the string "John". I know that grep can match the content in the files, but I have no idea how to use it with file names. Any help would be appreciated. 回答1: Use the find command, find . -type f -name "*John*" 回答2: A correct answer has already been supplied, but for you to learn how to help yourself I thought I'd throw in something helpful in a different way; if you can sum up what

string.find() returns true when ==-1 is used but false when <0 is used

不打扰是莪最后的温柔 提交于 2019-12-17 21:05:13
问题 I am trying to find a character within a string but I am getting unexpected results. My understanding is that string::find(char c) returns -1 when it is not found. However, I am getting some unexpected results. Even though the string does not include an '8' , it is still returning true . std::string s = "123456799"; if(s.find('8')<0) cout << "Not Found" << endl; else cout << "Found" << endl; //Output: Found However, when using == instead the code works as expected. std::string s = "123456799"

Find conditions with hasMany model

泄露秘密 提交于 2019-12-17 19:25:21
问题 I have 4 model: Item------hasMany---->Detail Item------hasMany---->Favourite Item------hasMany---->Category How can I find all Item that has Favourite.member_id = '8' and Category.item_category_id = '1' Here is my Item model relation: public $hasMany = array( 'Detail' => array( 'className' => 'Detail', 'foreignKey' => 'item_id', 'dependent' => true, 'conditions' => '', 'order' => 'created DESC', ), 'Category' => array( 'className' => 'Category', 'foreignKey' => 'item_id', 'dependent' => true,

Rails virtual attribute search or sql combined column search

倖福魔咒の 提交于 2019-12-17 18:56:27
问题 I have a user model with attributes 'first' and 'last' So for example User.first.first #=> "Charlie" User.first.last #=> "Brown" This User model also has a virtual attribute 'full_name' #user.rb def full_name [first,last].join(' ') end def full_name=(name) #don't know what to do with people w/ middle names split = name.split(' ') self.first = split[0] self.last = split[1] end So for example: User.first.full_name = "Charlie Brown" #=> "Charlie Brown" User.first.full_name = "Homer Simpson" #=>

Use current filename (“{}”) multiple times in “find -exec”?

浪子不回头ぞ 提交于 2019-12-17 18:15:30
问题 Many sources say that every instance of {} will be replaced with the filename found through find, but when I try to run the following, I only get one text file and its name is ".txt" find /directory -name "*pattern*" -exec cut -f8 {} > {}.txt \; The goal was to create a text file with only the eighth column from each file found, and each text file will be named after its parent file. Something about that second set of {} is not replacing with the filename of each found file. 回答1: Try: find

Find files with illegal windows characters in the name on Linux

血红的双手。 提交于 2019-12-17 17:58:45
问题 I have a projects on my Linux box that contains file with characters that are considered illegal/reserved in Windows (http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx). The project has over 10,000 files across several folders and I'll to identify the path for these files. I can find . -name "*\?*" for each of the illegal/reserved characters, but is there an easier way to find all files that contain < > : " / \ | ? * Once I've identified, I would like to remove all such