Questions tagged [find]

search for files in a directory hierarchy

Find is used to look files in a directory hierarchy. You can refer to its manpage here.

Examples:

Look for all files on a server owned by user siegfried:

 find / -user siegfried

Find all files ending in php en remove them:

 find / *.php -exec rm '{}' \;
314 questions
3
votes
4 answers

Use 'find' to determine files modified yesterday

I'm sure this is an age old question with a simple answer, but I've tried every combination I know to try and haven't come up with anything. And searching Google is less than pleasant since searching this topic comes up with hundreds of way to "find…
Corey S.
  • 2,487
  • 1
  • 19
  • 23
3
votes
5 answers

Deleting files in Linux

I need to find all files matching a certain criteria and delete them - here's a snippet: /var/www/somesite/releases/{many directories}/tmp/attachment_fu I'd like to find all files in any tmp/attachment_fu directory and delete them - the problem is…
user18816
  • 165
  • 4
3
votes
2 answers

Why is my find -type d performing fstat on every file in a folder?

I'm running find . -type d on a rather large directory tree. I am only interested in finding directories within this tree, but when I ran an strace against the process to make sure it was doing what I expected it to be doing, I noticed that there…
Nathan
  • 515
  • 2
  • 9
3
votes
1 answer

List directories not containing a file which has a variable prefix

I'm checking the output from a script. In some cases the script has failed, and a certain file hasn't been produced. I want to check whether this file is present in a directory and if not, print the directory name. The directories look…
Conor
  • 131
  • 2
3
votes
1 answer

How to list every file that is written to, on Linux?

What is the best way of getting a list of all files which have been written to, since power on? Is a simple find (with mtime) best for this, or are there other ways? (find won't list files which are written to, then deleted.) I'm using Ubuntu Linux…
fadedbee
  • 2,068
  • 5
  • 24
  • 36
3
votes
4 answers

How to properly pipe find with grep and cp in this use case

I am interested in recursively grepping for a string in a directory for a pattern and then cp'ing the matching file to a destination directory. I thought I could do something like the following, but it doesn't seem to make sense with linux's find…
imaginative
  • 1,971
  • 10
  • 32
  • 48
3
votes
1 answer

How to run a recursive chmod that stop at FileSystem Boundaries

I have a directory with lots of files and inside a mounted directory. var/ log/ nfs/ (a NFS remote directory) www/ How can I chmod/chown everyfiles inside that directory without changing nfs ones.
Natim
  • 626
  • 1
  • 6
  • 16
3
votes
3 answers

find and remove duplicates filenames in directory hierarchy

#!/bin/sh LASTBASE="" find $1 -type f -print | rev | sort | rev | while read FILE do BASE=$(basename "$FILE") if [ "$BASE" = "$LASTBASE" ]; then rm "$FILE" LASTBASE="$BASE" done
stefcud
  • 185
  • 1
  • 10
3
votes
4 answers

`find` command not available in web host, how to implement a delete based on modification time using other commands?

I'm creating a simple datebase backup solution for a client using web hosting at DataFlame. The web hosting account provides access to cron but not a shell. I have a database backup script creating regular backups and I want to automatically remove…
3
votes
1 answer

How to find any symbolic links that point outside a given folder tree?

I have a bunch of folders/files that are 10+ levels deep. How can I find any symbolic links that point outside this folder tree? I tried find -type l but this returns all soft links... even those whose destination is with in the folder…
nonot1
  • 1,099
  • 1
  • 12
  • 16
3
votes
3 answers

sh script to remove just txt files using find and exec rm warns me of missing argument to exec

find /full/path/dir -name '*.txt' -exec /bin/rm {} \; Fine in a shell, but pop it in a sh script along with some similar lines, to get it to run nightly from a cronjob, and it reports: find: missing argument to `-exec' on everything. I've tried…
talkingnews
  • 67
  • 1
  • 8
3
votes
1 answer

List directories without a specific folder

I need some help constructing a directory listing using 'find'? An example directory structure looks something like this: / (root) - /foo - /folderA - /folderB - /bar - /folderA -/search - /folderB What I want to find is a list…
Derek Downey
  • 3,955
  • 4
  • 27
  • 29
3
votes
3 answers

How to use find to replace several files of the same name

I have several files of the same name (say, somefile.php) scattered within several directories under /var/ If I want to replace all of them with a new version of somefile.php located in, say, /home/me/somefile.php ... how would I do that? Every…
Callmeed
  • 2,725
  • 4
  • 20
  • 15
3
votes
3 answers

How to delete everything except .svn directories?

I have quite complex directory tree. There are many subdirectories, in those subdirectories beside other files and directories are ".svn" directories. Now, under linux I want to delete all files and directories except the .svn directories. I found…
Arek
  • 155
  • 4
  • 9
3
votes
3 answers

How do I find the total number of lines in a set of found files (using Linux command-line tools)?

I can find the number of lines of each file matching a particular pattern using (for example): $ find . -name "test.save*" -exec wc -l {} \; 673000 ./test.save8.txt 24000 ./from/test1/test.save3.txt 100 ./from/test1/test.save1.txt 513000…
Daryl Spitzer
  • 2,996
  • 9
  • 33
  • 40