find is a command line utility to search for files in a directory hierarchy
2
votes
2answers
29 views
Remove files and directories even if not empty, except some directories
I am trying to remove all contents of a directory with some exclusions. I'm currently using this:
find . -type f | grep -vZf ../../exclude.file | xargs rm -rf
The exclude.file contains:
*log*
...
3
votes
2answers
58 views
Finding all large files in the root filesystem
I have a linux server, which currently has below space usage:
/dev/sda3 20G 15G 4.2G 78% /
/dev/sda6 68G 42G 23G 65% /u01
/dev/sda2 30G 7.4G 21G ...
0
votes
0answers
29 views
Storage Formats for Flat File DB
Currently I use a flat file database with
find -type f -ls
to store information for about 400GB of files.
I'd like to store also the md5sum/sha[1|256]sum of the files.
Because the files are often ...
0
votes
2answers
32 views
Using exec in find over ssh from shell script
So, I am attempting to execute the following from within a shell script;
ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit"
When this runs, it ...
2
votes
2answers
26 views
can regex capture groups be used in GNU find command?
With the GNU find command (GNU findutils 4.4.2), a regular expression can be used to search for files. For example:
$ find pool -regextype posix-extended -regex ...
2
votes
1answer
30 views
find -exec doesn't do what find output suggests [duplicate]
If I do this find:
find ${TRIADS_DIR}/*.dc.results -path "*amblock/stats.*HEAD" -o -path "*amblock/stats.*BRIK"
then I get what I expect in STDOUT:
...
0
votes
0answers
47 views
Find if the file is compressed or not
I need to find whether the file is compressed or not in script.If it is compressed I need to uncompress and send as attachement. My find command results in two files sum12.pdf.Z and sum23.pdf.Z My ...
0
votes
2answers
36 views
Output multiple strings out of multiple files
Hi my current code is:
find /home/user/logfilesError/ -maxdepth 1 -type f -name "gBatch_*"\
-daystart -mtime -1 -exec grep -rl "ERROR" "{}" + | xargs -l basename
if [ $? -eq 0 ]; then
...
1
vote
1answer
43 views
Extract file name from find command
I am trying to extract the file name and attaching to mail. But when I send mail the attachment is coming with path name and file name.
Ex: dir=/home/as123/bill and filename=abc.pdf.Z and I am ...
2
votes
1answer
31 views
Why can't I chmod these files that I could earlier?
I was trying to add execute permissions to sh files in a folder. For that I mistakenly used:
find . -print0 -iname '*.sh' | xargs -0 chmod -v 744
and the output was :
mode of `.' changed from 0755 ...
5
votes
1answer
42 views
Can “find” command preserve access-time
I'm running the following command which is supposed to find specific directories according to their Access-Time metadata detail however for some reason the find command changes the access time of ...
0
votes
1answer
28 views
Why do these 2 find commands give differnt results?
I wanted to see all files modified within the last 10 days and who owned them, so i entered the following to give me an idea how many results would be returned;
find . -maxdepth 1 -mtime -10
I then ...
6
votes
2answers
153 views
fastest way to grep jar file for a particular name in it?
I am trying to find all the jars which has spring in its name. I am working with windows and using cygwin to run the linux commands. Does my below command looks right?
find . -name "*.jar" -exec jar ...
3
votes
2answers
91 views
Find files in directory with paired names
I'm running tests of a variable-size-and-contents test set. Data files are added and removed frequently. I'm looking for an automated way of gathering a file list.
All files are in subdirectories of ...
4
votes
3answers
110 views
zsh's “echo SomeText >> **/filename” in other shells
I need to fill all files with a specific filename (recursively) with a text.
In zsh this can be done with
echo SomeText > **/TheFileName
I search generic solutions for sh-compatible and/or tcsh ...
5
votes
6answers
206 views
Use find to find certain directory and delete all files in it except one directory
I'm having the following problem. I have a directory structure and want to delete everything that is within a directory named Caches. Everything should be delete except all directories named ...
6
votes
2answers
111 views
“find: .: No such file or directory” while using find on the current directory
Find command seems not to work at all. For example, I'm in a directory where there absolutely is file named index.php and I execute this:
[root@server htdocs]# find . -name "index.php"
find: .: No ...
2
votes
4answers
34 views
Generate multiple symbolic links with maitaining directory structure
I want to generate symbolic links from multiple folders with maintaining the directory structure. I read a few answers and the best thing i can come up with now is:
find ...
1
vote
0answers
24 views
-exec isn't being passed all the files found by find [duplicate]
There are two files called install.log and install.sh
The find command will find both of these and pass them to -exec ls
With the addition of an or (-o), it only passes one argument to -exec ls
...
0
votes
1answer
36 views
How to output the lines of a file after find and a grep?
Hello I want to output ERROR messages from logfiles from the current date.
First I search for the logs of today with specific prefix:
find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" ...
0
votes
2answers
33 views
How can I search filenames which are starting with xy_* and are created/edited today?
Hello I´m currently trying to search for logfiles which are starting with xy_Number and are created/edited today(not last 24 hrs).
I tried:
find /home/USER/logfilesError/ -maxdepth 1 -type f ...
7
votes
2answers
60 views
break out of find if an -exec fails
Is there a way to write an find so that it breaks if one of the -exec operations fails on a file?
E.g. (javac is conveniently used as a program that can return an exit code of 1 on some files and for ...
2
votes
4answers
126 views
Copy files and directory tree for filesize in specified range
Hi I would like to make a small script copying files from different directories example /pp/01 /pp/02/ etc... to another destination with the same directory design. But only those files within the ...
1
vote
2answers
44 views
How to locate a file in a directory
How can I locate a file using locate in CentOS under a specific directory from terminal?
Locate search the whole database!
7
votes
5answers
117 views
How to search for files with immutable attribute set?
For config auditing reasons, I want to be able to search my ext3 filesystem for files which have the immutable attribute set (via chattr +i). I can't find any options for find or similar that do ...
0
votes
1answer
26 views
better use of find - rvm.sh
I am trying to find rvm.sh as I am receiving the infamous rvm is not a function error.
The file in most linuxes is supposed to be at
/etc/profile.d/rvm.sh
However on opensuse it is not there so I ...
4
votes
1answer
63 views
Blank lines when executing “grep | xargs” in a “find -exec”
I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all).
I've managed to get the list of blocking .htaccess but when I try to extract ...
3
votes
3answers
160 views
'is a directory' error when trying to pass directory name into function
Note: I am a newbie to bash scripting
In my bash script, I use find to get the folder names by wildcard:
for i in $(find ${directory} -mindepth 1 -type d -name ${wildcard});
do
stuff=doStuff ${i}
...
5
votes
3answers
244 views
Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?
Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
2
votes
0answers
40 views
diff -r only for certain file types
Is there a way I can perform a recursive diff of two directories but only compare (in their respective places) files that match a specific filename or filetype predicate?
E.g. I would like to do ...
1
vote
2answers
24 views
Deleting user directories with . in name
I have directories with usernames as "firstname.lastname" and firstname.middle.lastname in one directory. Is there a way to delete directories with "." in name under current directory. I need to run ...
1
vote
1answer
24 views
Using a zsh function in find?
I'm on OS X and have defined a function called finderpackage that tries to determine if a folder is in fact a "package" (also, somewhat erroneously, known as a "bundle") according to the Finder.
My ...
1
vote
0answers
39 views
Why below script is not able to find and delete files [closed]
Why below find command does not find and delete files ?
I am launching it like this ./script.sh 1 MYFOLDER
days_period=$1
myuser=$(whoami)
folder_prefix=$2
LOGS_DIR=~/$folder_prefix/logs
if [ $# ...
2
votes
2answers
104 views
find the single largest file
We host a share of size 4 TB. How efficient is it to find a file with highest size.
Usually we use:
du -ak | sort -k1 -bn | tail -1
and it is not easy to scan through a share of such huge size and ...
2
votes
1answer
63 views
How to find text in files and only keep the respective matching lines using the terminal on OS X?
I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool for search files for specific text strings.
I have a folder with many huge text files and ...
0
votes
2answers
37 views
find action not working for specific search [duplicate]
I'm trying to use the find command to list the size of a certain set of files but am getting no output. The command I use is:
find POD -type f -name *.mp3 -or -name *.ogg -ls
Which produces no ...
1
vote
3answers
196 views
Bash script for automatic tar backup of chosen files and directories
Within a given directory in linux environment, I need to pick all files modified after a certain date (let's say 7 days) as well as all directories (only in root directory, hence non recursively) ...
3
votes
3answers
65 views
find 2 files with similar names and move them to a new location
I have a system with a watch folder where people/companies can upload new files via FTP or SMB. In this watch folder They should ALWAYS upload 2 files: 1 media file with a prefix name of ABC*.mxf and ...
1
vote
2answers
70 views
find command throws errors when inside function
I can run the following command in bash without any errors:
$ find /d/Code/Web/Development/Source/ \( -name '*.cs' -o -name '*.cshtml' \) -exec grep -IH UserProfileModel {} \;
I wrote a function in ...
1
vote
3answers
483 views
find: missing argument to -exec
I'm trying to run the following command:
find a/folder b/folder -name *.c -o -name *.h -exec grep -I foobar '{}' +
This is returning an error:
find: missing argument to -exec
I can't see what's ...
1
vote
2answers
102 views
How to search and replace strings matching a replacement list for multiple files
I have a file, say map.txt, containing a list of search strings and corresponding replacements:
search -> replacement
bigBone -> bb
fishMarket -> fm
dogCollar -> dc
...
I need to ...
1
vote
5answers
42 views
find subdirectories with lowest number
I am trying to list all subdirectories with the lowest number.
For example, for the following list:
/100/2001
/100/2003
/101/2001
/101/2004
/102/2000
/102/2003
/102/2005
I am ...
0
votes
1answer
47 views
Trying to pass user generated variable to an external command
I have a bash script that is asking a user for input, then passes that variable to a find command. I've tried quoting/escaping the variable every way I know, but it keeps failing.
read -p "Please ...
1
vote
2answers
132 views
Output of command when piped to another command
I am running a command which does a quick checksum of some file like so
find / -type f -ctime +30 -mtime +30 -atime +30 -exec md5sum {} \; | xargs -P 4
and I am trying to run it in parallel with
...
4
votes
4answers
163 views
Delete all files in a directory whose name do not match a line in a file list
I have a directory with 1000+ files. In a text file, I have about 50 filenames, one per line. I'd like to delete all the files in the directory whose filenames don't correspond with an entry on the ...
2
votes
2answers
80 views
Find command for lookup up a directory tree
Is there any equivalent command, or options for, GNU find that will search up the directory tree? I'd like to look backwards through the tree for files with a given name. For example, say I'm in ...
0
votes
1answer
57 views
touch & gzip all HTML, CSS, JS files in a directory recursively
I'm trying to optimize Nginx server. I've enabled Gzip_Static_Module to serve pre-compressed gzip static files like CSS, JS, HTML.
Nginx Wiki says that the timestamps of the compressed and ...
2
votes
1answer
37 views
Why does to order of the parameters affect the files found by `find`?
I found this weird behavior in find. Depending on the order of the parameters to find it finds different files.
For example, I have a directory tree with the following content.
.
├── configure.ac
...
1
vote
2answers
471 views
How do I get absolute path from using find unix command
How to get absolute path by using find command.
actually I am running the following script:-
find . -size +20M | while read a
do
i=$(echo $a | sed 's:/: :g')
echo $a;
j=($i)
...
4
votes
3answers
66 views
How to find files containing two strings in different lines
A real example is: I have a Python file util.py, and I changed one of the function name from foo to bar. There might be other files using foo as function name and they are irrelevant.
I want to ...







