Questions tagged [gnu-findutils]

GNU's basic directory searching utilities (Unix filesystem CLIs)

The GNU Findutils package comprises the following CLIs, which relate to finding directories and files on Unix systems:

  • find - search for files in a directory hierarchy
  • locate - list files in databases that match a pattern
  • updatedb - update a file name database
  • xargs - build and execute command lines from standard input

Linux distributions typically come with find and xargs from this package; while locate and updatedb are typically also present, they may come from a different source.

See http://www.gnu.org/software/findutils/

82 questions
1
vote
3 answers

How to use GNU find command to find files by pattern and list files in order of most recent modification to least?

I want to use the GNU find command to find files based on a pattern, and then have them displayed in order of the most recently modified file to the least recently modified. I understand this: find / -type f -name '*.md' but then what would be added…
devLinuxNC
  • 81
  • 1
  • 8
1
vote
0 answers

the rules of find -cmin 0 and -ctime 0

I was studying the command find, and I saw: -cmin n File's status was last changed n minutes ago. -ctime n File's status was last changed n*24 hours ago. but when n is zero, comes the difference, is there a sound…
joker
  • 11
  • 2
1
vote
1 answer

Find's cost-based optimiser breaks short-circuit evaluation

Quoting the man page of find (GNU findutils 4.7.0, emphasis mine): GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence (see section…
Cassio Neri
  • 19,583
  • 7
  • 46
  • 68
1
vote
1 answer

Write to all file matches in find command

I want to echo some text into all file matches with the find command in linux shell. I tried this" find . -type f -name "file*.txt" -exec echo "some text" > - '{}' ';' But this does not work.Is there anyway I can fix this?
Dickson Afful
  • 708
  • 1
  • 6
  • 20
1
vote
1 answer

How can I remove empty lines in every file of a directory?

How can I remove empty /blank lines in every txt file of a directory (ideally subdirectories too)? find . -name '*.txt' -exec ex '+%s/\ / /g' -cwq {} \; Above code is pulling list of files correctly but i am not sure what regular expression to pass…
Ammad
  • 4,031
  • 12
  • 39
  • 62
1
vote
0 answers

Problems finding terms in multiple .gz files recursively

We have various archive files in a folder, and I'm trying to recursively search through these for a particular string. I've found lots of examples of various ways to do this, but I've not been successful. This is from my latest iteration: find .…
agsYAV49
  • 11
  • 2
1
vote
2 answers

GNU find "or" function is not working with -print0 | xargs -0 tar

I'm using this command to find specific files (2 files) which works as it should be on it's own; find . -iname '*.txt' -o -iname '*.pdf' and returns the correct…
Marry Jane
  • 305
  • 2
  • 15
1
vote
1 answer

Is there a way to pass options as an array to find command in bash?

In rsync I can just define my exclusions/options in an array and use those arrays in the subsequent command, e. g. rsync "${rsyncOptions[@]}" "${rsyncExclusions[@]}" src dest I wanted to achieve the same using the find command but I couldn't find a…
TylerDurden
  • 697
  • 1
  • 5
  • 16
1
vote
1 answer

How can I recursively go to every folders and execute shell script with the same name?

I have this directory. . ├── animation │   ├── animation-events │   │   ├── app.js │   │   ├── app.mustache.json │   │   ├── create_view.sh │   │   └── assets │   │   └── dummy_character_sprite.png │   └── change-frame │   ├── app.js │   …
notalentgeek
  • 4,939
  • 11
  • 34
  • 53
1
vote
4 answers

Write the file name before deleting

I want to delete all the .png files in a directory and save the delete files names in a text file. I managed to do this with the following command: find . -name "*.png" -delete -print >> log.txt Everything works fine and in the log I get the entire…
Dragos Cazangiu
  • 207
  • 1
  • 3
  • 14
1
vote
1 answer

grep -f with a here document

Here documents avoid creation of an intermediate, one-time use file. I was hoping to make use of this when getting the full paths of 20 possible files (without using find -o syntax). I expected the following to work: find | grep -f…
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
1
vote
3 answers

Loop over all *.js files in a directory skipping *.spec.js files in bash script

FILES=`find . -type f -name '*.js'` for file in $FILES do # some task done This will loop over all *.js files but let's say there are some .spec.js files as well which I want to skip. a.js a.spec.js b.js x.spec.js c.js should iterate…
Vaibhav Nigam
  • 1,334
  • 12
  • 21
1
vote
1 answer

Combine file modified date and "grep" results through "find", in one line

We want to show each file's modified date and time when applying grep to selected files by the find command. The final result should look like: 2016-10-17 Mon 20:38:57 ./rest/47results.php: 5 :σχόλια, ιδέες facebook Running the following from…
marikamitsos
  • 10,264
  • 20
  • 26
1
vote
2 answers

Can find push the filenames of the found files into the pipe?

I would like to do a find in some dir, and do a awk on the files in this direcory, and then replace the original files by each result. find dir | xargs cat | awk ... | mv ... > filename So I need the filename (of each of the files found by find) in…
ericj
  • 2,138
  • 27
  • 44
1
vote
1 answer

Using bash shell on RHEL 7 - why does find find more files when I don't use -exec?

I'm looking for all setuid/setgid files. When I don't use -exec, it works as expected: # find /usr/bin -type f -perm -4000 -o -perm -2000…
roartechs
  • 1,315
  • 1
  • 12
  • 15