All Questions
45 questions
8
votes
5
answers
2k
views
How to execute a command on all files whose names match a pattern and whose contents match a pattern?
Say I want execute cmd on all *.cpp and *.hpp files that contain the word FOO.
As far as just finding those files goes, I know I can do,
find /path/to/dir -name '*.[hc]pp' -exec grep -l 'FOO' {} +
...
0
votes
1
answer
153
views
Find all the folders that are concealed using 'chflags'
I have concealed some folders on my laptop using chflags:
chflags hidden hide-me
And I don't remember where exaclty these folders are located.
How is it possible to find all of them? (Probably by ...
14
votes
6
answers
2k
views
How to recursively list all files whose entire content is exactly "\n"
I have some failed experiment result files, and their contents are exactly a single \n (newline).
I would like to list them all (perhaps with something like find or grep), to know what are the files ...
1
vote
1
answer
43
views
How I can aggregate my matches from find command by grepped values?
I am looking for all occurences of <source_model>.*</source_model> at any files located at ./vendor/magento/*/etc/adminhtml/system.xml:
find ./vendor/magento/ -type f -path */etc/adminhtml/...
1
vote
2
answers
172
views
How to find the most recent file that contains a string
I have a directory containing several files. I need to know the full path of only the most recent file that contains a certain string.
This needs to work on macOS, and the directory path contains ...
1
vote
2
answers
2k
views
How to find files that only contain alphanumeric characters?
How to find files that only contain alphanumeric characters and [áéíóúñ.,¿?¡!()]?
I have some sparse plain text files and I need to separate them from scripts and any other thing, they're just ...
0
votes
1
answer
763
views
how to use find and grep with loop & variables?
I have bunch of files in a directory.
# ls -1
file1
file2
file3
file4
file5
file6
file7
file8
file9
file10
Task is to find files older than file5.
which I can do like
# find . ! -newer file5
./file1
....
-1
votes
2
answers
667
views
Finding files and matching patterns with printed filename in bash
I have the following code that lists matches far a pattern ptrn, with the filename being printed before the listing (which uses the context option -C NUM)
find "$fdir" "${isufx[*]}"...
1
vote
2
answers
332
views
Finding a string in a txt of house addresses with number ranges by passing in exact number and street names
Context
I'm a postal worker (mail sorter) and am trying to write a bash script which allows me to input an exact street address and first couple letters of a street name, and have it return the ...
6
votes
3
answers
2k
views
Find files that have the same name as the directory
I have the next problem:
Directory Example1 has three files: Example1, Things and Pictures.
Directory Example2 has three files: Example2, Example3 and Pictures.
I need a list showing only the ...
0
votes
2
answers
1k
views
search multiple files based on file contain string
let say i have one text file contains emails
abd3@dom
abd2@dom
sdklf2@lksd
sd@gm
i need small bash script for grep , find , to find contain the email in files and and print out the files they match ...
3
votes
5
answers
1k
views
How to do the equivalent of a "where" clause with `find` and `grep`
I have a folder tree of text files and I would like to find instances of a substring and the names of the files they came from.
If I do something like:
find . | xargs cat | grep 'abc'
then I would ...
0
votes
1
answer
72
views
capture the parameter and value from multiple files
we have the following 100-1000 files under /var/place folder
-rw-r--r-- 1 root root 261 Dec 24 22:52 total_machines-10.json
-rw-r--r-- 1 root root 261 Dec 24 22:52 total_machines-11.json
-rw-r--r-...
0
votes
1
answer
2k
views
Dealing with spaces in bash when piping the results from one command to another
I need to go recursively through several directories/files, in bash, replacing a certain string with another if it exists in a file. I had this solved in my script with the line:
grep -rl "...
1
vote
2
answers
2k
views
How can i terminate 'find' after the first match?
I am using find in a while loop.
it takes a list of ips in ip.txt, searches for the ip in a directory of files and then writes the name of the file that each IP was found in to a file called results....