find is a command line utility to search for files in a directory hierarchy
6
votes
2answers
797 views
How to detect whether “find” found any matches?
Is there an idiomatic means to detect whether "find" found any matches? I'm currently using
COUNT=`find ... | wc -l`
if [ "$COUNT" -gt 0 ]; then
but this seems a little indirect to me. Also, I'd ...
6
votes
4answers
3k views
How do I recursively grep through compressed archives?
I'm trying to find out what modules use Test::Version in cpan. So I've used minicpan to mirror it. My problem is that I need to iterate through the archives that are downloaded, and grep the files ...
6
votes
3answers
4k views
How can I move files by type recursively from a directory and its sub-directories to another directory?
What would be a good way to move a file type from a directory and all of its sub-directories?
Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
6
votes
1answer
56 views
How to do `head` and `tail` on null-delimited input in bash?
find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
6
votes
1answer
113 views
find is missing a result — how is that possible?
What conditions explain this output:
root@ip:/# find / -name "server.xml" -print
/etc/tomcat7/server.xml
root@ip:/# ls /var/lib/tomcat7/conf/server.xml
/var/lib/tomcat7/conf/server.xml
I am ...
6
votes
2answers
2k views
How do I stop a find from descending into found directories?
I'm wanting to find all directories with a specific string so I can do another find on the files contained within.
So I don't want to waste time on ./my-search-term/dir/my-search-term etc.
How can I ...
6
votes
5answers
10k views
How copy and rename files found in “find” function Linux?
I have a folder named /home/user/temps which has 487 folders.
In each folder I have a file called thumb.png.
I want to copy all files named thumb.png to a separate folder and rename them based on ...
6
votes
3answers
520 views
Deleting lots of files
I accidentally created 8 million files and every time I'm trying to delete them the server almost dies because of the rm process eating all disk IO (the server is remote without console).
Should ...
6
votes
2answers
123 views
How can I substitute into this shell command?
I have a find command that I want to substitute a list of GIDs into.
Here's the command:
find / -follow \( -group 39 -o -acl_group 39 \) -exec ls -ln {} \; 2> $HOME/error.39.log 1> ...
6
votes
2answers
152 views
du command show a slash after directories?
How to use du command show a slash after directories?
For example:
du -ab /root/test/php-5.4.8/
Result:
1781 /root/test/php-5.4.8/main/internal_functions.c.in
973596 ...
6
votes
3answers
2k views
find -exec in bash script with variable expansion
I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir.
...
6
votes
1answer
131 views
tar: how can I exclude intermediate directories but include leaf directories?
I want to create a tar file suitable for extracting into /. I've created a work directory that represents the root of the file system, and it has all the stuff I want included in the tar underneath, ...
6
votes
3answers
648 views
Is it possible to nest a 'find -exec' within another 'find -exec'?
Something like the following is what I what I'm after,
but my code doesn't work, no matter how I escape {} and + ;
find ./ -maxdepth 1 -type d -name '.*' -exec \
find {} -maxdepth 1 -type f ...
5
votes
3answers
411 views
List the files containing a particular word in their text
I would like to list the files recursively and uniquely that contain the given word.
Example: Checking for word 'check', I normal do is a grep
$ grep check * -R
But as there are many occurrence ...
5
votes
7answers
9k views
How do I find text within a file and have it search multiple subfolders?
I'm looking for a function name and the folder structure is deep and there are a lot of files to look though.
Usually I go with something like find * | grep functionname but is that the best way?
5
votes
4answers
805 views
recursively chmod
I was trying to chmod folders and files with:
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
But I was wondering:
How to do it in one line using find and excluding the ...
5
votes
4answers
1k views
find not recursive when file at top
Imagine a source tree. There are xml files everywhere.
But since there is a XYZ.xml at the root of this tree it won't find my xml files.
find -iname *.xml
returns
./XYZ.xml
instead of
...
5
votes
5answers
2k views
How to copy all html files from a directory tree to a single directory?
I want to copy all the .html files in myDir and its subdirectories to ~/otherDir. Here's what I tried (it doesn't work):
$ find myDir -name *.html -print | xargs -0 cp ~/otherDir
usage: cp [-R [-H | ...
5
votes
5answers
5k views
How to report number of files in all subdirectories?
I need to inspect all sub-directories and report how many files (without further recursion) they contain:
directoryName1 numberOfFiles
directoryName2 numberOfFiles
5
votes
4answers
2k views
How to find a file in the filesystem from the command line?
I'm fairly new to Linux, and I've now found myself in a situation where I'd like to find where a file (with a partially-known filename) is in the file system. I'd like to know how to do this from the ...
5
votes
3answers
168 views
How do I remove every file that has x in its title?
I have a lot of directory where there are hundreds of files.
In every directory there are pairs of my_file-01.jpg and my_file-€01.jpg
I want to remove every file that contains € sign in its title: ...
5
votes
2answers
182 views
Collect files using find
I currently have this script:
find . -name '*.log' -print0 | xargs -0 tar zcf $file
To collect all the "*.log" files. I would like to modify it to include also all the ".txt" files but I don't know ...
5
votes
4answers
1k views
Delete files of certain size range
I want to delete files which size is between certain values. For example I have the following list of files:
-rw-r--r-- 1 smsc sys 558 Apr 30 13:07 stats.sfe.1.20120430130513.xml.Z
-rw-r--r-- 1 smsc ...
5
votes
4answers
8k views
How can I list subdirectories recursively?
The obvious
ls -dR
does not work.
I am currently using
find /path/ -type d -ls
but the output is not what I need (plain listing of sub-folders)
Is there a way out?
5
votes
4answers
3k views
How can I use bash's if test and find commands together?
I have a directory with crash logs, and I'd like to use a conditional statement in a bash script based on a find command.
The log files are stored in this format:
/var/log/crashes/app-2012-08-28.log
...
5
votes
2answers
284 views
How to make `find` output full absolute file names?
When I run find, it outputs relative (./-based) file names, but I need full absolute (/-based) names.
5
votes
3answers
1k views
Find files with same name but different content?
I want to generate a list of files that have:
Same name
Different content
in a directory (including all children directories and content).
How to do? Bash, perl, anything is fine.
So, two ...
5
votes
5answers
1k views
Recursive rename files and directories
I'm using below command
for fname in *;
do
mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ')
done
..but it only rename in current directory. Lets say I have many directories, and each ...
5
votes
2answers
656 views
Find command: Searching for executable files
What type of parameter/flag can I use with the unix find command so that I search executables?
(if this question is better suited for another stackexchange forum, I welcome you telling me so)
p.s. ...
5
votes
3answers
127 views
Use find result without ./
I'm trying to use find to create a bunch of symlinks but using the result with {} includes ./ before each filename. How can I avoid that?
find . -type l -name '*.h' -exec ln -s /sourcedir/{} ...
5
votes
2answers
120 views
Remove all Vim undo files in all but one directory
I just realized that I have tons of Vim undo (.un~) files sprinkled around my file system. I'd like to delete all of these files except in one directory—~/.tmp. My first problem is that I can't seem ...
5
votes
3answers
3k views
Find files which are created a certain time after or before a particular file was created
I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created.
If I go with find -newer, that means I'd have to create a temporary ...
5
votes
1answer
282 views
Why do some regex commands have opposite intepretations of '\' with various characters?
Take, for example, this command:
find . -regex ".*\.\(cpp\|h\)"
This will find all the .h and .cpp files in your directory. The period character '.' in regular expressions usually means "any ...
5
votes
4answers
460 views
Delete all folders containing files which match pattern
I'm trying to delete all subdirectories of my current working directory which contain a rar file.
My first attempt: find -name *.rar -exec rm -r {}/.. ';' failed because that is not a valid ...
5
votes
2answers
436 views
missing argument to find -exec
I want to remove certain files using find and -exec. But unlikely bash tells me, that I'm "missing" some argument.
find . -name *.png -exec rm {} /;
what do I miss?
same "missing argument" return ...
5
votes
5answers
3k views
List files larger than {size} sorted by date
I want to solve the problem 'list the top 10 most recent files in the current directory over 20MB'.
With ls I can do:
ls -Shal |head
to get top 10 largest files, and:
ls -halt |head
to get top ...
5
votes
2answers
377 views
find: Delete with exclude
This command is not DWIM-compliant:
find . \( -name .svn -prune -false \) -o \( -empty -delete \)
find: The -delete action atomatically turns on -depth, but -prune
does nothing when -depth is ...
5
votes
1answer
1k views
How to find files not of a certain type?
I'm trying to find out all of the different types of files in my unorganized music folder. I've been trying this command (to list files of types besides the ones I know are in there):
find ...
5
votes
1answer
144 views
How can I synchronize all PDFs from one directory with Dropbox?
I want to synchronize all the PDFs from one directory (my Zotero library) to Dropbox. Finally, I want to have a list of all the PDFs, not the directory names.
I successfully synchronized all my PDFs ...
5
votes
2answers
222 views
Find files that were not installed by the package manager
I'd like to get a list of all files in my Gentoo Linux system that were not installed by the package manager (Portage). This is because I want to keep my system as clean as possible, removing all ...
4
votes
5answers
2k views
Alternative to find?
Is there an alternative find program with a more conventional CLI interface? find works and expects parameters in a painfully different way from most other utils.
Clarification: I'm looking for a ...
4
votes
5answers
250 views
Script to remove spaces and lowercase in file names
I am trying to write a script that will replace spaces with "-" and make all letters lower case for all files in the current directory.
for x in 'ls'
do
if [ ! -f $x ]; then
...
4
votes
4answers
1k views
How can I run a specific command for each find result?
How would one run a specific command for each file that was found by using the find command? For the purpose of the question lets say that I would simply like to delete each file found by find.
I am ...
4
votes
2answers
556 views
How to search for files by size and extension ?
I want to delete all empty files with a particular extension from a directory and all its subdirectories.
4
votes
3answers
261 views
Recursively Remove SVN files
I'm still learning the bash shell.
I want to recursively find and remove svn files within the child directories of a given folder. I made the mistake of checking out instead of just cloning. So i'm ...
4
votes
2answers
168 views
Why 2 linux machine behave differently with command of the same syntax?
I am using 2 machine , which is both Red Hat Enterprise Linux AS release 3 (Taroon Update 2)
( I check it in /etc/*-release ).
I checked they are using the same default shell by ps -p $$, which is ...
4
votes
2answers
199 views
Append line to many files
I want to add some text to over 200,000 files
I am trying this
find . -name *.txt -print | xargs -I % echo "hello world" >> %
But nothing is happening. When i run find . -name *.txt it work ...
4
votes
4answers
3k views
How to search for a word in entire content of a directory in linux
need to search for something in entire content
I am trying:
find . | xargs grep word
I get error:
xargs: unterminated quote
How to achieve this? Thanks.
4
votes
3answers
2k views
How to find files in subdirs and sort them by filename in a single command?
Result of a normal find using find . ! -path "./build*" -name "*.txt":
./tool/001-sub.txt
./tool/000-main.txt
./zo/001-int.txt
./zo/id/002-and.txt
./as/002-mod.txt
and when sorted with sort -n:
...
4
votes
5answers
840 views
How to clean up file extensions?
I have a directories with .MP3 files which I'd like to change the extensions to .mp3. What's the easiest way to do this? I'm think something along the lines of:
find /RootPath -type f -iname "*.mp3" ...
