Linked Questions

19 votes
7 answers
19k views

How to find all git repositories within given folders (fast)

Naive approach is find dir1 dir2 dir3 -type d -name .git | xargs -I {} dirname {} , but it's too slow for me, because I have a lot deep folder structures inside git repositories (at least I think that ...
user1685095's user avatar
12 votes
5 answers
11k views

How do I use `find` to go to directory of that file

I want to find a file and then enter the directory containing it. I tried find /media/storage -name "Fedora" | xargs cd but of course, I the is not a directory error. How do I enter its parent ...
Hrvoje T's user avatar
  • 1,031
14 votes
5 answers
56k views

Shell script to check for the presence of one or more files with a specific extension?

I want to write a script to find a file with specific extension.this much i have done: #!/bin/bash file="/home/Savio/Dsktop/check/*.csv" file1="/home/Savio/check/*.txt" if [[ -f "$file" && -f ...
Savio Mathew's user avatar
8 votes
4 answers
5k views

limit find output AND avoid signal 13

I have a directory with ~1M files and need to search for particular patterns. I know how to do it for all the files: find /path/ -exec grep -H -m 1 'pattern' \{\} \; The full output is not desired (...
Andrey's user avatar
  • 820
2 votes
2 answers
8k views

How to delete remaining files of removed user?

I know deleting user with userdel username can cause information leakage and other security issues (as tutorial book says, administrator should delete user with -r option). But i tried it to see what ...
rzaaeeff's user avatar
  • 532
3 votes
4 answers
4k views

Zgrep stop after first match when arguments are passed from xargs

I'm using this command to find patterns in zip files (similar to the one) suggested here https://superuser.com/questions/144926/unix-grep-for-a-string-within-all-gzip-files-in-all-subdirectories ...
user13107's user avatar
  • 5,355
4 votes
2 answers
848 views

How to stop the find command after second match?

How to make find command, that will show only first two matches and then end, something similiar to How to stop the find command after first match? just version for two records.
harcotlupus's user avatar
2 votes
1 answer
885 views

Stopping find command after finding files in one directory

I have a command in a Korn script which is like as written below, find <path1> <path2> <path3> -name filename After this, it stores the output in a txt file. Using this txt file it ...
Dhiren Dash's user avatar
1 vote
4 answers
514 views

Bash script - check if any files changed recently

I am writing a script which needs to check if any of the files in a given directory have been modified recently. I thought I could simply use find, however it reports success even if it doesn't find a ...
symcbean's user avatar
  • 5,631
2 votes
1 answer
299 views

how to execute a shell built-in if find found certain files

In general, if we want to execute a command if find identifies files corresponding to certain specs, we can use -exec. But in my case I want to exit the shell/script if find found a match and -exec ...
jamadagni's user avatar
  • 1,331
1 vote
2 answers
279 views

find exiting on 1st found and return code

I would like to use find on a directory structure to exit if at least one file exists with a target condition, because this will lead to a failure of the rest of a shell script. Since this shell ...
dan's user avatar
  • 933
2 votes
1 answer
255 views

Improving performance of Script Using find and exec [closed]

I have a script that iterates through a given directory and automatically compresses those that do not contain at least one file used in less than 30 days. Now, I am wondering if I could improve ...
DataBach's user avatar
  • 153