Tagged Questions

find is a command line utility to search for files in a directory hierarchy

learn more… | top users | synonyms

8
votes
5answers
548 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
36 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
168 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
1k 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
3k 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
358 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
28 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
60 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
61 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 [ $# ...
3
votes
2answers
986 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
126 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
50 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
2k 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
89 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
141 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
3k 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 ...
2
votes
2answers
887 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
57 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
115 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 ...
2
votes
2answers
159 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 ...
6
votes
4answers
733 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 ...
1
vote
2answers
250 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
2answers
147 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
39 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
5k 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
119 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 ...
3
votes
5answers
191 views

How to prepend a particular text file contents to every text file in a directory and its subdirectories?

I hate to clutter my source code files with licensing/attribution comments but some times it is a requirement. So having dozens of source code files (organized in a tree of subdirectories) written I ...
3
votes
4answers
147 views

Find “.git” dirs but ignore some paths; or how does `find -not` work

I cant figure out how the find -not works. Let's say that I would like to locate all .git dirs in the tree. find -type d -iname .git No problems, but then let's say that I have some dirs that I ...
1
vote
2answers
149 views

Find last edited date of file (strange exec behaviour)

I am trying to get the last modified dates of all the word documents in all the directories below this one $ pwd /run/user/1000/gvfs/smb-share:server=myServer,share=myResources If I do a regular ...
2
votes
4answers
134 views

Find + Grep Recursive Search

I am mirroring a website using wget. On the server, there is a dump of the find / command, which includes filenames in the form : /dir1/ /dir1/page1.txt /dir1/page2.txt ... The mirrorring is very ...
1
vote
3answers
2k views

How to display “human-readable” file sizes in find results?

I'm trying to find all large files on my Centos server. To do that I'm using: find / -maxdepth 10 -size +100000 -ls I tried changing -ls to -lsh but it is not allowed. How can I display these ...
1
vote
1answer
139 views

`tar` with `find` with removing original file extension

I want to create tb2 files from bunch of text files like this. tar cfj $(basename ./2014_04_09.txt .txt).tb2 $(basename ./2014_04_09.txt) With this command I can create a archive file 2014_04_09.tb2 ...
2
votes
1answer
552 views

Find font file from font name on Linux

I have a font with the name Media Gothic. How can I find the file name of that font in Linux? I need to copy that file to another system. I've tried: find /usr/share/fonts/ -name '*media*' But this ...
5
votes
1answer
4k views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
6
votes
3answers
191 views

Find the top 50 directories containing the most files/directories in their first level?

How can I use find to generate a list of directories which contain the most numbers of files. I'd like the list to be from highest to lowest. I'd only like the listing to go 1 level deep, and I'd ...
1
vote
3answers
61 views

Detecting extension files doesn't executed for a period

How can I detect the .class files in my workspace which haven't executed for a certain period, and remove them?
2
votes
7answers
1k views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...
2
votes
3answers
215 views

Count result in a find/exec statement

I have some Perl files which I have to modify through a simple sed call. Basically, I have to remove the first line of all of them. Currently, I managed to do this : find <PATH> -type f -name ...
0
votes
1answer
36 views

echo keywords found

I'm trying to figure out which keywords are being found for [each] file in the script below. I tried adding echo $keywords and it just outputs every keyword. Code: keywords=("Alachua" "ALACHUA" ...
0
votes
1answer
67 views

Delete subfolder and keeping up parent folder

I need to delete folderx which are not accessed for seven days, easily I can do it with next: find /path/folder -type d -mtime +7 |xargs rm -rf The probelm is when I have subfolder marked for ...
2
votes
5answers
2k views

Find all files that have been last modified on a specific day - like Monday?

So I want to use find to return a list of all .html files in a given directory that have been last modified on a Monday. How can I do this?
4
votes
2answers
136 views

Find command returns wrong files

I'm trying to find files in a folder using find command which are a day older than the day on which the command is run.. I use the following command: FILES_dcn=($(find $dir_dcn -maxdepth 1 -type f ...
1
vote
3answers
397 views

Delete files with same name at the end of the file

Delete files with same name at the end of the file i have a lot of files in my folder and sub directories like ajax_hostel_room_master.php.php class_hostel_registration.php.php ...
3
votes
2answers
495 views

Symlink all subdirectories in a directory to another directory

I'm trying to symlink every directory in a folder to another folder. For example, in the structure below, I need the subfolders symlinked to folder2. - /home/chris/folder1 -- subfolder1 -- subfolder2 ...
6
votes
4answers
399 views

How to only zip the files of a specific user?

I like zip, it's simple, but recently I came with the need of only zipping the file owned by one user in a directory. I read the manual and I can't find any option to for example do things like: ...
6
votes
1answer
129 views

Expected behavior of `find -depth` if execute permission denied for subdirectory?

I'd like to know if I can rely on the behavior I am seeing when using find with -depth option and user does not have execute permission for a subdirectory. Assume the following directory structure: ...
3
votes
4answers
306 views

find -exec exit 1 \; Doesn't work neither does find -exec sh -c exit 1 \;

Using Enterprise Linux 5/6, Bash 4.x I want this type of logic: # IF temp file exists, exit because we are restarting already find /tmp/restarting_server -mmin -10 -exec exit 1 lsof -i TCP:1234 ...
19
votes
3answers
1k views

Find a file when you know its checksum?

I have the md5sum of a file and I don't know where it is on my system. Is there any easy option of find to identify a file based on its md5? Or do I need to develop a small script ? I'm working on ...
4
votes
3answers
483 views

Search for specified keywords in files and copy to a new filename based on the keyword

I'm trying to create an .sh script where if any keyword is found in a file then copy that file to the directory /pathtofolder/keywords/$thefirstkeywordfound (overwrite the file if it already exists). ...
3
votes
3answers
7k views

Why can't find -regex match a newline?

Why does this fail? touch "$(printf "a\nb")"; find . -regex './.\n.' I also tried these, none of which work: find . -regextype posix-extended -regex '.\n.' find . -regextype posix-awk -regex ...