Questions tagged [find]

For questions pertaining to find, a command-line utility to search for files in a directory hierarchy. Use this tag for questions about find itself or questions about issues arising from using the find command-line utility.

Filter by
Sorted by
Tagged with
20 votes
3 answers
95k views

Find a file which is 30 minutes old

How can I find the file which is of 30 minutes old in /bin/ksh?
9 votes
3 answers
6k views

Find -exec dry run?

Is there a way to see what the result of a find . -exec somecommand {} \; would be with substitutions, without actually running the commands? Like a dry run (or test run or print)? For example, ...
1 vote
1 answer
2k views

Exclude directories for du command / Index all files in a directory

My goal is rather simple: I want to create a small database of all files/directories within a big directory. After looking for a tool suited I couldn't find anything but the good ol' du. I figured out ...
0 votes
1 answer
98 views

How do I copy variously named files with the same extension to all have a standard file name?

I have variously named files such as in different subdirectories e.g.: a/apple.txt b/orange.txt c/pear.txt How do I copy them to have a uniform name (fruit.txt) in their respective directories so the ...
1 vote
1 answer
233 views

Delete all folders except which are mapped in symlinks [closed]

I need to delete folders that are not in use. There are a few symlinks which points to this folder. My requirement here is in 3 step. 1) Get all the available folders at top level which are not ...
0 votes
1 answer
64 views

Prepend two lines containing comments and URLs before specific line in python-scripts using sed

In some of my python-scripts, I've put the line if __name__ == '__main__' in order to make the content only be executed, when the script is run itself as main-script (as opposed to being imported, see ...
234 votes
9 answers
310k views

Looping through files with spaces in the names? [duplicate]

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff $...
0 votes
2 answers
839 views

How to group files from find command into a single line where each file is inside double quotes? [duplicate]

This is a recurrent issue I have always had while dealing with iterations or actions over files found using find. I have the following files: $ find . -name "*ES 03-11*" ./01jan/ES 03-11....
1 vote
1 answer
4k views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f -mmin ...
37 votes
3 answers
37k views

How can I use two bash commands in -exec of find command?

Is it possible to use 2 commands in the -exec part of find command ? I've tried something like: find . -name "*" -exec chgrp -v new_group {} ; chmod -v 770 {} \; and I get: find: missing ...
0 votes
1 answer
2k views

Find file(s) recursively and filter them by their path matching specific substring(s)

Complete Linux newbie and need help with command to find filenames, list their respective paths, and then further filter that result set by only the paths that contain a specific substring(s). For ...
1 vote
1 answer
149 views

How do I see what files were changed by the "ed" command?

I'm trying to write a script that ensures all text files end with a newline character. When I run this command in a particular folder: find . -exec ed -s {} <<< w \; I get the following ...
2 votes
3 answers
661 views

Linux search for a string only in a given set of files

There are several files in a directory. I am trying to search and find all such strings ending with a given string. Instead of searching in all the files present in the directory, I would like to ...
0 votes
2 answers
89 views

Find and delete Syntax

I have a hard drive that contains about 300,000 x 3 files that were written by a recovery program. Some of these files are in the format: .doc.apple.quarantine These are easy to remove: find . -type ...
1 vote
3 answers
229 views

Combining Unique Pairs of Files with find

I have a series of actions I need to preform on pairs of files, on a fair number of files. For simplicity, I'll focus this down on just doing a simple cat on a pair, to discuss the pairing and how to ...
4 votes
2 answers
6k views

Finding files and copy with folder structure intact

I am searching files who have either been created or modified for the last 60 minuts. I find these via find ~/data/ -cmin -60 -mmin -60 -type f ~ the home directory /usr/wg/ After that I want to ...
0 votes
1 answer
104 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 ...
0 votes
1 answer
247 views

Flatten directories with single files

I have the following directory structure root_directory --sub_a ----index.html --sub_b ----index.html --sub_c ----index.css ----index.html now I would like to move the file to the parent directory ...
1 vote
1 answer
150 views

Better way to only include real filesystems in find?

This works, and is generic across systems (at least Ubuntu 18.04 and RHEL 8.3) with different mountpoints, but is there a Better Way? (Ignore that I'm trying to find pg_ctl and excluding "...
20 votes
3 answers
32k views

How to exclude the folders proc and sys from search with find command ?

I wanted to execute a script that picks out a random directory path: find / -type d | shuf -n1 Unfortunately I get error messages about the prohibition of entering certain directories. How can I ...
3 votes
4 answers
357 views

find command: how to ignore pathname?

I have to find some type of files in a directory and it's subdirectories and I only have to print out the filenames. So here's the main command: find -type f -name "*.c" Now, how could I cut the ...
1 vote
1 answer
165 views

find command with negated condition still considers the given directory [duplicate]

Wanting to find for files except for those, that are in /home directory (directly or in one of subdirectories of any level), I run the following command: find / ! -path '/home/*' However, I get error ...
1 vote
1 answer
282 views

Passing argument of a function to exec in find

I would like to define a function to find and replace text in multiple files. I find the command line find . -type f -exec bash -c 'mv "$1" "${1/<string_to_find>/<...
2 votes
1 answer
2k views

Linux show files in directory larger than 1 GB and show size

I am trying to find a command that displays files larger than 1 GB and displays those files ordered by size. I have tried find . -maxdepth 2 -type f -size +1G -print0 |xargs -0 du -h |sort -rh but for ...
4 votes
4 answers
20k views

Find executable files recursively

I have got the directory called Test and a few directories inside it. Both Test and the directories inside it have executable files. I'd like to print them with ls. I'd use this command. ls -l `find ...
4 votes
5 answers
2k views

How to exclude the . and .. using ls or find?

I have 35 files and directory in my home at the first level (without descending into subdirectories). But the results are "faked" and report 36 because they include the . special directory. ...
112 votes
2 answers
121k views

How can I use `find` and sort the results by mtime? [duplicate]

I want to use find but sort the results reverse chronologically as with ls -ltr. Is this possible through any combo of flags or pipelines?
0 votes
1 answer
26 views

Find: how to discover which directory contains a SlackBuild file?

With this line find mydir/ \( -exec test -d '{}'/.svn \; -or -exec test -d {}/.git \; -or -exec test -d {}/CVS \; \) -print -prune is really easy to discover which directory contains a subdirectory ....
3 votes
5 answers
25k views

Difference between 'ls -ltr abc*' and 'find ./ -name abc*' command? [duplicate]

To search a file in a directory, I found two commands as below: ls -ltr initialfilename* find ./ -name initialfilename* Sometime, first command gives me the search result but sometime I used to ...
1 vote
1 answer
125 views

Search files by specific time e.g. changed in the last 14 days

I am using Nextcloud and since the "retention" app is still not working on v20 I try to code an autodelete script for myself. The problem is, when I upload files to the Nextcloud share the ...
0 votes
1 answer
341 views

Hacker hid folder/file with name pattern from Linux ls

My server was hacked by internet hackers. The server hides any files or folders with name pattern *system-sleep* from the ls/find command. I can use some commands like chmod to the hidden folder. But ...
0 votes
1 answer
108 views

How to move all files in dir to another, but copy latest?

I'm trying to write a backup script that moves all files from a directory, but only copies the latest modified/newest file. I'm running into some trouble where I'm not able to return the correct ...
1 vote
1 answer
587 views

Need to convert a batch of wav in flac in different folder

I need to convert a lot of *.wav in different folder, i try to use find and flac to convert all this without missing name of the track in the folder. This is the line I try to use : find ./ -type f -...
5 votes
2 answers
1k views

Is it ok that find displays double forward-slash?

Is it a bug that, when I find ./path/here/ I get: ./path/here//foo ./path/here//bar I know find wants me to specify the path without the trailing slash, but surely it can detect the path that tab-...
-2 votes
1 answer
2k views

how does find's -printf statement work?

find /home/lead_admin -type f -printf '%s %p\n' | sort -nr | head -10 in the above statement what exactly does -printf '%s %p\n' do?
0 votes
1 answer
179 views

Storing find results in variable then passing to cp?

I have a need where I must work with a set of files based on time elapsed (as I do not have control over when new files are added to the remote directory). I must do several operations with this set ...
0 votes
1 answer
2k views

How to use tree with grep and find to locate files by name?

How can I use tree and either grep or find in conjunction to find, for example, csv files using ".csv" as a file extension: ├── ./Videos ├── ./vscode │   ├── ./vscode/foo.csv │   ├── ./...
0 votes
0 answers
58 views

Find Command Example - OEL7

find /path -type f -name '*' -not -name "data*" -mtime +1 -delete I want to ask about this command. As I understand, this command go to path and delete according sysdate-1 all of the files ...
0 votes
2 answers
213 views

Renaming files using part of the path name

I need to rename all logs using part of the directory name. The logs appear like so: friday13/stack123/FooBar-QA-123/000001.gz friday13/stack123/FooBar-QA-123/000002.gz friday13/stack123/FooBar-QA-123/...
0 votes
2 answers
189 views

How to delete all the "*.exe" files which is 132kb

My external hard disk got a windows virus which makes lots of filename.exe copies of 132.6 kb. When I write find . -type f -name "*.exe" it founds thousands of .exe files and only 100 or 200 ...
2 votes
1 answer
8k views

Find files and recursively append text to them

I have been looking for an answer to this problem for a while: how can I use find append text to all hits? My original method was something like sudo find / -type f -name "*.py" -exec cat somecode.txt ...
0 votes
2 answers
1k views

Tcl command to find latest created folder in a directory

i have a folder where there are subfolder with dates example : Parent/2020-11-09_15.47.36 Parent/2020-11-10_16.52.02 and so on. now I want to find out which is the latest date folder inside Parent ...
-1 votes
2 answers
2k views

Shell script to check file name with two extension and if file with both the extension are present call a script otherwise it should fail

I need to check a file with two extensions (.txt and .ctl) in a directory and if file is present with both the extensions call a script. If not the job should fail. I tried some methods but it is not ...
3 votes
3 answers
511 views

List files not having another file with suffix

Consider a directory with the following files: file1 file1.suffix file2 file3 file3.suffix I need to list all files such that there doesn't exist another file having the same name and a known suffix....
0 votes
3 answers
11k views

Find command to list the directory names which consists only of "numbers" (0-9) [duplicate]

In a particular path, I have a few directories (date as filename), for example: if the directory name is like 20180423 it should be listed if the directory name is like 20180423-backup or ...
1 vote
1 answer
323 views

How to extract specific files using FIND + TAR command

I would like to know if it is possible to extract a specific file inside tar file using find command. Example: Normal situation: find filaname called "file1" and extract tar xvf tarfilename ...
0 votes
2 answers
464 views

How to find hidden filename that is 2 or 3 characters long

I want to find a hidden file with a name that is 2 or 3 characters long on a Linux machine. I tried: ls .?[a-zA-Z][a-zA-Z] ls .??[a-zA-Z] I also tried find . -name "???" and find . -name &...
0 votes
3 answers
597 views

Run find on find

I did a web seach for "linux run find on find" but it produced no relevant results. I want to build list of files by find and then run find again on that list. After fixing some "silly&...
6 votes
4 answers
5k views

How to find directory in directory?

How can I find a directory with a certain name but only if it is in another directory with a certain name? For example when I have the following directory structure a ├── b │   └── e ├── c │   └── e └─...
-3 votes
1 answer
89 views

Basic command problems

I tried to figure out what is the difference those commands (for a school project), but for me its chrashed or running for more than 10min~ So, the sample: sudo find / -type f -exec file ’{}’ ; | ...

1
17 18
19
20 21
71