find

Delete files except those whose name matches a string

删除回忆录丶 提交于 2021-01-28 07:24:44
问题 I'm trying to delete all files (include subdir) in a directory but only files which not match specific file name: "equipe" "match" "express" I'm trying to do it with this command find . -type f '!' -exec grep -q "equipe" {} \; -exec echo rm {} \; That doesn't work. It echos files with "equipe" inside How can I do it with multiple strings? ("equipe" "match" "express") 回答1: You may use this find : find . -type f -not \( -name '*equipe*' -o -name '*match*' -o -name '*express*' \) -delete 来源:

What does it mean to pipe from the Net Start command to the Find command?

☆樱花仙子☆ 提交于 2021-01-28 05:30:40
问题 An example of this is: NET START | FIND "MSSQLSERVER" > nul 回答1: I don't think this command line does make a lot of sense, but any way: NET START lists all running services, the output of this command is sent to the FIND tool, which searches for the string "MSSQLSERVER" in the input it has been given. If any line of the input matches the search condition find prints these lines an the screen, unless in a case like this, where the input is send to the null device. This is the part : > nul. 来源:

Check for (whole only) words in string

不问归期 提交于 2021-01-28 01:55:48
问题 Training on Checkio. The task is called Popular words. The task is to search for words from a list (of strings) in a given string. For example: textt="When I was One I had just begun When I was Two I was nearly new" wwords=['i', 'was', 'three', 'near'] My code goes like: def popular_words(text: str, words: list) -> dict: # your code here occurence={} text=text.lower() for i in words: occurence[i]=(text.count(i)) # incorrectly takes "nearly" as "near" print(occurence) return(occurence) popular

BASH: Filter list of files by return value of another command

无人久伴 提交于 2021-01-27 20:04:31
问题 I have series of directories with (mostly) video files in them, say test1 1.mpg 2.avi 3.mpeg junk.sh test2 123.avi 432.avi 432.srt test3 asdf.mpg qwerty.mpeg I create a variable ( video_dir ) with the directory names (based on other parameters) and use that with find to generate the basic list. I then filter based on another variable ( video_type ) for file types (because there is sometimes non-video files in the dirs) piping it through egrep . Then I shuffle the list around and save it out

How do I grep recursively in files with a certain extension? [duplicate]

☆樱花仙子☆ 提交于 2021-01-27 14:06:23
问题 This question already has answers here : grep recursively for a specific file type on Linux (4 answers) Closed 2 years ago . To find all file paths with .out extension in subdirectories, I use find . -name '*.out' To grep a pattern in all files ending in .out , I use grep pattern *.out How do I combine these two commands, so that it finds all files and then greps in those files? I am looking for an elegant alternative to grep -r 'pattern' . | grep '.out' 回答1: find allows you to run a program

bash find using regex is not case sensitive

廉价感情. 提交于 2021-01-27 13:26:13
问题 I need to find files starting with three lowercase letters but for some reason I'm getting an undesired case-insensitive behavior. I'm using find with the -regex option but it finds even the files starting with capital. $ find . -regextype posix-egrep -regex '.*/[a-z]{3}\w+\.abc' ./TTTxxx.abc ./tttyyy.abc prints the same as: $ find . -regextype posix-egrep -regex '.*/[A-Z]{3}\w+\.abc' ./TTTxxx.abc ./tttyyy.abc If instead of using a range of characters I use a single character, works as

How do I find a complete word (not part of it) in a string in C++

社会主义新天地 提交于 2021-01-27 05:33:08
问题 In a C++ code, I'm trying to search for a word in a sentence but it keeps doing partial search. I want it to search only for the complete word not parts of it too, any help? size_t kk; string word="spo"; string sentence="seven spoons"; kk=sentence.find(word); if (kk !=string::npos) cout << "something" << endl; 回答1: I think the best way is to split your string using whitespace and punctuation characters as delimiters, then use std::find on the result. #include <boost/algorithm/string.hpp>

Exclude list of files from find

放肆的年华 提交于 2021-01-20 14:43:11
问题 If I have a list of filenames in a text file that I want to exclude when I run find , how can I do that? For example, I want to do something like: find /dir -name "*.gz" -exclude_from skip_files and get all the .gz files in /dir except for the files listed in skip_files. But find has no -exclude_from flag. How can I skip all the files in skip_files ? 回答1: I don't think find has an option like this, you could build a command using printf and your exclude list: find /dir -name "*.gz" $(printf "

Using find to locate files modified within yesterday

北慕城南 提交于 2021-01-20 12:09:16
问题 I would like to get a shell command to find the files with a modification date for yesterday — 24 hours only. That means I would like to find the files which were modified yesterday only. 回答1: Use find with mtime and daystart , it will find files modified 1*24 hours ago, starting calculations from midnight (daystart): find dir -daystart -mtime 1 回答2: This answer assumes you have GNU date and find. It also assumes that if you run the script at any time on 2016-07-14, you want the files

Using find to locate files modified within yesterday

二次信任 提交于 2021-01-20 12:07:22
问题 I would like to get a shell command to find the files with a modification date for yesterday — 24 hours only. That means I would like to find the files which were modified yesterday only. 回答1: Use find with mtime and daystart , it will find files modified 1*24 hours ago, starting calculations from midnight (daystart): find dir -daystart -mtime 1 回答2: This answer assumes you have GNU date and find. It also assumes that if you run the script at any time on 2016-07-14, you want the files