Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [find]

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

0
votes
1answer
26 views

Recursively replace path in a files in directory, except binary files

How to recursively replace strings (location path) in the files in directory, except binary files? I tried command find . -type f -exec sed -i 's/foo/bar/g' {} + but it replaces also strings in ...
2
votes
1answer
28 views

Find command oddity [duplicate]

I've found using the 'find' command to search for individual files that some inconsistencies occur. Eg, I wanted to search for a particular file with the word paper in its name. If I type sudo find /...
0
votes
1answer
35 views

Find file name in content of other file [on hold]

There are many text file in folder. I want to know which file's contain that mention to other file name in folder example: Is name of file1 has mention in other file in folder1? folder1 ├── folder1....
11
votes
5answers
1k views

How to sort human readable size

I'm basically looking for files then sorting by the size. The script works if I don't sort the size by human readable. But I want the size to be human readable. How can I sort sizes that are human ...
-1
votes
2answers
46 views

Display contents of the file searched by grep or find command [on hold]

I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but ...
0
votes
2answers
844 views

Difference between find and GNU find

Consider some common *nix systems (say Debian, CentOS, Arch and Kali). I always used find; I don't recall using GNU find, but from one example I've seen I assumed the syntax of GNU find might be ...
0
votes
2answers
113 views

How can I use an argument from xargs to evaluate another expression?

I would like to evaluate a basename expression given an argument from xargs. I tested: find . -name '*.txt' | xargs -I f cp f DIR_OUT/copied_$(basename f) which gives no file or directory because $(...
2
votes
3answers
1k views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
-2
votes
1answer
40 views

Why can't i “find” files *.png [duplicate]

System: Ubuntu 11.04, regular user account: find /usr/share -name *.wav works okay, but if i do: find /usr/share -name *.png it does not produce any output How do i change the last command to ...
1
vote
2answers
25 views

Discard “access denied” stderr natively in find

Is there an option in find that allows me to suppress the error messages that I get from it trying to access directories for which I don't have access? I know I can just discard stderr, but it seems ...
2
votes
1answer
34 views

How does find -name work?

I can't for the life of me figure out how find with the test -name works. I run find / -name *in and returns a bunch of results: /sbin /sbin/sulogin /dev/stdin to name a few. It's as if it ...
11
votes
5answers
33k 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 ...
0
votes
1answer
50 views

Is Unix find overwhelmed by multiple prunes and type f?

I have spent days on this Rubik's cube. Anything I do to fix one problem breaks another. I am on POSIX compliant MacOS X 10.5 thru 10.14. I am calling this from a Perl script in a context of ...
0
votes
0answers
24 views

run script continuously and check for error

I have written below script and it reads the file and when ever there is any 400* or 500* word it will give me error message, and now I want to add two more functionality to my script. I added the ...
0
votes
2answers
1k views

How to make a script to move files with find and regex

Im trying to make a find regex script so i automaticly can copy files to specific directory. find . -regex "*test.*s01e([0-9][0-9]).*" -exec cp {} /storage/tv/test/s01/ \; Made this script, dont get ...
44
votes
1answer
20k views

Understanding the -exec option of `find`

I find myself constantly looking up the syntax of find . -name "FILENAME" -exec rm {} \; mainly because I don't see how exactly the -exec part works. What is the meaning of the braces, the ...
3
votes
4answers
1k 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
3answers
159 views

Regex that Matches Random String of File Names

I had a user on our shared host who let their Wordpress install fall victim of an exploit that allowed for arbitrary file creation as the apache user. The files generated are obviously generated with ...
0
votes
1answer
28 views

Can't seem to concatenate multiple files in different directories

I'm trying to concatenate multiple files together that are in different directories using the following command: ~$ find . -name ‘*.text’ -exec cat {} >> combined.text \; However it doesn't ...
22
votes
2answers
18k 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 ...
243
votes
3answers
304k views

find - exec rm vs -delete

I'm trying to understand the difference between these two commands: sudo find / -name .DS_Store -delete and sudo find / -name ".DS_Store" -exec rm {} \; I noticed that the execmethod is preferred....
1
vote
2answers
29 views

Busybox: Find all files on partition that have been modified since power-on

I am trying to come up with a Busybox-compatible script (or one-liner) that lists every file inside a specified partition that has been modified since the last power-on. This should include files that ...
0
votes
1answer
16 views

Explaining xargs output from two find commands

I have a directory structure of folder1 folder2 folder2a folder2b folder3 folder3a folder3b I am confused by the xargs output of the below command: XXXXXX:folder1 user$ find . -type d -...
0
votes
2answers
47 views

only use the filename for move

I have to move some files from one folder to another, criteria set by a find and grep. When I try to move the files it breaks. The actual move it's trying is mv /somefolder/export//somefolder/storage/...
4
votes
2answers
3k views

Using “find” non-recursively?

Using /bin/find /root -name '*.csv' returns: /root/small_devices.csv /root/locating/located_201606291341.csv /root/locating/located_201606301411.csv /root/locating/g_cache.csv /root/locating/...
0
votes
4answers
55 views

Linux command to find and remove text from several files at once

I have my site infected by a virus. This virus added this line in several files in my site. My idea is to remove this line of text with a unique command from the terminal. Let's say I have the folder ...
0
votes
1answer
12 views

CronJob command to delete multiple subdirectories by name in a given directory

I have two IP cameras which are sending image snapshots to an FTP server every 10 seconds, from 08:00 to 20:59. The directory structure looks like this: `-- public_html `-- securitycams |-...
1
vote
1answer
37 views

How to express `find`'s -writable and -readable tests, when they are not available?

Sometimes on old Linux systems, I experience that find doesn't support -writable and -readable tests, which test whether the file or directory is writable/readable resp. for the current user. Say, I ...
1
vote
2answers
53 views

Why does `find -type d -exec rmdir {} \;` command produce “No such file or directory message”

For testing purposes, I created the following directories. user@linux:~$ mkdir dir0{1..3} user@linux:~$ ls -l total 12K drwxr-xr-x 2 user user 4.0K Mei 31 10:45 dir01 drwxr-xr-x 2 user user 4.0K ...
5
votes
5answers
2k views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
3
votes
2answers
2k views

How to get the exit code of commands started by find?

I am using "find" in a Travis-CI to check a particular file type with a program. (To be exact, it is a shellcheck check.) However, when using find the exit codes of the command(s)/subshells executed ...
0
votes
1answer
236 views

cannot find Trash folder! Ubuntu 18.04

I am running a preinstalled version of ubuntu 18.04 but cannot find Trash folder. The typical places don't have the folder. ~/.local/share/Trash <-- does not exist /root/..../Trash <-- does ...
0
votes
1answer
2k views

What is the difference between “find -H” and “find -L” command?

When I executed the command both commands gave the same output. I created a soft link and a hard link for a file but still both commands gave the same output. Is there a difference between find -H and ...
0
votes
0answers
37 views

BASH Script to find files of multiple types

I switch a lot of people from Windows to Linux. As we all know, not all files on Windows end at their intended location (i.e.: the Downloads folder). I'd like to run a BASH script to search for all ...
0
votes
3answers
52 views

How do I use command line arguments passed to a shell script that uses xargs?

I have a script that will iterate a set of git checkouts and run a git command in each directory. I now want to be able to pass a parameter to the shell script from the command line and have that ...
0
votes
1answer
37 views

find command - how to ignore case in -path option?

when searching filename or dirname case-insensetively, we can use option -iname. but if I want to ignore case in -path option, what should I do? can I do it with only find command, without using ...
0
votes
0answers
17 views

find -name vs locate [duplicate]

Why this command: locate $FILENAME is NOT the same of find / -name $FILENAME 2>/dev/null ? Sometimes locate finds nothing, while find never fails.
1
vote
3answers
26 views

How can I eliminate untracked files from find output?

I want to find within my project directory, but I'm only looking for files that are tracked by Git. Is there a command I can use as a filter for the find output (or any other means) to limit the ...
9
votes
6answers
600 views

Finding all files with a given extension whose base name is the name of the parent directory

I want to recursively look for every *.pdf file in a directory ~/foo whose base name matches the name of the file's parent directory. For instance, suppose that the directory structure ~/foo looks ...
0
votes
0answers
54 views

What is a great way to list files found in a directory that add up to a certain file size

This list will then be used to create tar balls for easy movement. This is what I came up with so far. Add up files that are just greater than 10GB list them to file. find . -type f -exec ls -al {} ...
0
votes
0answers
33 views

Continuously detect a change of chksum of files under folder with inotify-tools [duplicate]

I just installed inotify-tools. I would like to continuously detect change of chksum of files under folder /path Once a change was detect ( under /path ) then it will print echo “chksum of files ...
0
votes
2answers
49 views

Get filenames and write them on place of previous namespace

I have hundreds of sources codes files. I want to rename namespace according to the filenames path. Of course slashes must be replace by dots. I have tried with find -exec but I failed to get the ...
-1
votes
0answers
43 views

find with -not -name not filtering out the previous -name files

I am working on a script which gunzips files older than X days. I am using below command to skip the existing gzipped files howevere it still not filtering out the existing gzips find /home/xyz -...
3
votes
1answer
33 views

Can the output of find with the -printf flag be colorized?

The command find . -type l -not -xtype l -printf "%p -> %l\n" prints all nonbroken symlinks under the directory .. I want to colorize this output so that the %p part is blue. I've tried find . ...
0
votes
2answers
55 views

Unix command to get 0 count , when no files present for the day along with count

How to do I get the list days were no files been received. Have used the below command to get the file count along with the date: find . -maxdepth 1 -type f -printf '%TY-%Tm-%Td\n' | awk '{array[$0]+=...
0
votes
1answer
39 views

How to find duplicate directory paths even if the contents are different?

I've searched high and low but it seems all but one (Find and list duplicate directories) topic I've found actually deals with my situation, and the result isn't quite what I need. Edit: Here's some ...
2
votes
2answers
89 views

How do I delete files except some specific files passed as parameters?

The task is to write a shell script with n+1 arguments where the first one is the directory and the rest is the specified files and will delete all but specified files. E.g. calling rmexcept . '*....
2
votes
2answers
701 views

Using truncate \ find

This command won't work: $ truncate -s 0 $(find . -size +1c type -f -exec grep -LwE 'keyword1|keyword2|keyword3' {} +) "find: paths must precede expression: type Usage: find [-H] [-L] [-P] [-Olevel] ...
4
votes
3answers
572 views

Using find command

I have a bunch of directories. Inside these directories is a cover letter and a zip archive of work. I wanted to run a quick and easy query to open up all the cover letters so I can decide if it's ...
4
votes
2answers
43 views

list files with specific group and user name

Do you know a command to list all files on the server with specific group and user name? I am looking for something like this: find -ls -group 'groupname' && find -ls -user 'username' this ...