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
18 views

Find file while other file exist in same directory

I'm trying to do "one line script" or really small bash script. It have to find file (for example ./xxx/one.php) and if that file exist edit (with printf or echo) other file IN SAME directory (for ...
-2
votes
5answers
56 views

Print filenames containing multiple strings

Let's say I have multiple files with .ext extension containing multiple lines. I need to print filenames containing all 3 keywords: kwd1, kwd2, and kwd3. How do I do it?
-1
votes
1answer
22 views

Variations of the Same Command Return Same/Similar Result

I'm working on a public server, which offers games designed to teach people Linux and ethical hacking skills. The goal of each level (so far) has been to find the ssh password to the following level ...
3
votes
4answers
66 views

bash command to create array with the 10 most recent images in a dir?

I'm writing a bash script and I need to create an array with the 10 most recent image files (from new to old) in the current dir. I consider "image files" to be files with certain extensions, like ....
0
votes
1answer
25 views

Looping through all files, skipping some dynamically

rather new to unix. Trying to create a script to loop through all files and subdirectories given a directory and printing them. I would like to be able to skip certain directories dynamically though. ...
6
votes
1answer
218 views

Huge performance difference of the command find with and without using %M option to show permissions

On my CentOS 7.6, I have created a folder (called many_files) with 3,000,000 files, by running: for i in {1..3000000}; do echo $i>$i; done; I am using the command find to write the information ...
0
votes
2answers
44 views

Why does my find (+ sed) command work in the terminal but not in a makefile?

I have the following command: find stdlib/main -type f -exec sh -c "echo {} | sed -e 's/stdlib\/main\///g' -e 's/\.q//g' -e 's/\//\./g' -e 's~^~/resource:\"{},~g' -e 's/$/\"/g'" \; The goal is to ...
2
votes
2answers
49 views

find path excluding doesn't work when permission denied

There is some strange behavior while excluding path from find: find ~ -not -path "~/sandboxes/*" -name 'some-file.vmdk' gives: /home/user/VMs/win/some-file.vmdk find: ‘/home/user/sandboxes/debian7....
0
votes
1answer
59 views

Using “find” to delete files with a pattern of underscore/letters

Is there a way to find and remove files with a pattern like this (where the pattern is only that there are two underscores in the file name, separated by letters or numbers) ex. /file_name_name I ...
1
vote
1answer
40 views

Find all files a user can read from

At first, I wanted to simply use: find /etc -type f -perm -004 And it did work. But then there were two files from which a current user could not read, but a group this user was in could access it ...
0
votes
1answer
17 views

finding files with missing or old signatures

To update signatures in /boot I'd like to use find (GNU findutils) 4.6.0. I know I can just loop and check if the signature matches with gpg, but I'd like to know how to use find with -newer in the ...
0
votes
2answers
32 views

xargs issue with grepped files containing spaces

I have a range of .html files all containing spaces in between. What I need is to locate the file using find in conjunction with grep, and if a match is found, basically I just want xargs to open it ...
25
votes
1answer
852 views

Finding files for which a command fails

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?
0
votes
0answers
17 views

Copy specific named directories, where content changed the last 24 hours

I can recursively find and copy all my test-directories (with content) of the current directory: find . -name test ! -path "./my_dest/*" -exec cp -r --parents {} /path/to/my_dest \; But now I want ...
2
votes
1answer
24 views

How is find's {} substitution pattern vulnerable to injection attack? [duplicate]

I'm trying to understand more about this edit that was made to an answer of mine: https://unix.stackexchange.com/revisions/510388/5 How does running cd "{}" in the context of a find command ...
0
votes
1answer
66 views

How can I spawn an interactive shell for each directory returned by find?

Given base find command: find . -type d For each directory returned, I want to spawn an interactive shell that has that directory as the current directory.
0
votes
1answer
26 views

Find command - file path with white space

I'm trying to use a script that will run through a bunch of different folders and find Indesign files with "16x9" in the file name, and then loop them through a small AppleScript portion of code. I'm ...
1
vote
1answer
42 views

How to kill a for loop with hundreds of inputs

Every now and then I have to kill a for loop that looks through hundreds of directories for something and I have yet to find a way to do it with a single command. Every time I do it just skips that ...
0
votes
2answers
71 views

How to pass multiple dynamic ! -path arguments to find

I have a file which contains a list of directories/files that I want to ignore when searching using find. It looks like this: .git .vim config .vimrc .bashrc This list is not exhaustive and can have ...
2
votes
1answer
35 views

Recursively find directories but do not print subdirectories of matches

Considering the following directory structure: dir1 [domain.com] foo dir1 subdir1 subdir2 FooFile dir2 [domain.com] foo dir2 subdir3 [domain.com] foo dir3 subdir4 ...
0
votes
1answer
22 views

Extract lines from files containing a string but not another in that same line

I am using grep within a script to obtain a list of filenames of the files that contain a certain string. The basic instruction would be this one within a do loop: if grep -q "$str" Inputs/inp$n; ...
2
votes
0answers
15 views

Appending the content of a file to files in another directory tree

I want to append the content of a file in my current directory to all the files in another directory recursively (so I need to append the content of that file to the files in the subdirectories too). ...
3
votes
4answers
55 views

How to sed chunks text from a stream of files from find

I have a directory of many *.org files. I want to select a section of text out of all these org files. There is a * Learnings header in the content. I would like to select from the * Learnings header ...
11
votes
2answers
358 views

Is it possible to search for a directory/file combination?

I need to find an image, say ABC.jpg, that I know will have been programmatically placed into a directory named ABC_MPSC. I've tried: cd / find . -name "ABC_MPSC/ABC.jpg" But that doesn't return ...
1
vote
1answer
23 views

How to rename all md type files under subfolders recursive?

$ tree . . ├── tmp1 │   └── acsfd.md ├── tmp2 │   └── adb.md └── tmp3 └── aa23aa.md ... └── tmpn └── random.md Want to rename all md files to index.md, I tried: find . -name "*.md" -exec ...
1
vote
2answers
51 views

Using wildcards for -group or -user with find command

I'm trying to find owners of files on the system that all start with a specific name, for example [unu@here findtest]$ find . -ls 17295583 0 drwxrwxr-x 2 unu unu 74 Mar 28 03:14 ....
0
votes
2answers
72 views

How to search for large directory containing thousands of files?

Under the folder /grid/sdh/hadoop/yarn/local/usercache/hdfs/appcache we have more than 100 recursive folders. One of the folders contain thousands of files. Is it possible to identify this folder? ...
1
vote
0answers
38 views

awk print tab delimited columns with find execdir

I am trying to print out columns that are separated by tabs. First, I use find command to identify a list of files to process. Second, I parse the file path to generate the filename to be used for ...
2
votes
1answer
362 views

Find fails if filename contains brackets

I'm trying to use find inside a loop to create a variable that contains a file matching the filename + desired string Example: file1.en.srt file1.mkv file1.pt.srt This is the relevant part of the ...
0
votes
1answer
21 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
4answers
65 views

Grep a file which has spaces on it by expanding a variable

I have a find result saved in a variable and I am protecting the spaces in filenames by adding a single quotes around the output. So the for loop works flawlessly. My problem is when I intend to ...
5
votes
2answers
241 views

Removing files under particular conditions (number of files, file age)

I want to create a shell script that will count files (1 hr older files) and if files are more than 1000, then delete all. For read and delete I am using those command at putty for count: ls /tmp/...
2
votes
2answers
39 views

Using `find` to exclude multiple paths matching patterns

I'm trying to locate nested YAML and HTML files to replace a string with sed after creating the list; I'm not sure I fully understand how to use the -prune option, here's what I have: find . -type f -...
-1
votes
2answers
52 views

Pipe each batch of xargs trough wc -l

So my task is to find the file with the most hardlinks in a directory. So far i have : find . -name "file*" | xargs -I{} -n 1 find . -samefile {} which gives me: ./hardlinkFIle245 ./...
3
votes
2answers
39 views

find command outputs files without a directory structure

I want to tar some Python files and send it across a server. I do: find /some/path -iname "*.py" -exec tar czfv python_files.tar {} + Followed by: pv python_files.tar| ssh some_user@some_server '...
4
votes
2answers
204 views

pipe commands inside find -exec?

Let's suppose I want to find all .txt files and search for some string. I would do: find ./ -type f -name "*.txt" -exec egrep -iH 'something' '{}' \; What if I want to do a more complex filtering, ...
2
votes
1answer
364 views

How can I get files using find command

How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?
0
votes
0answers
66 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 ...
1
vote
2answers
85 views

Using Linux Find

I'd like to find the MAIN.TXT file in a directory folder. If it is older than 24hours then output YES to the MAIN.txt file. If it hasn't been modified in 24hours then leave the file alone. I got as ...
0
votes
0answers
38 views

Working with strange filenames [duplicate]

How can the script below be made to always work no matter the filenames returned by find ? #!/bin/sh cmds_should_always_work() { echo "\n\n*********************************" $1 stat --...
0
votes
1answer
43 views

Getting find: bad option -o -name abc -o -name xyz when perform search for *.properties excluding set of directories from search [closed]

#!/usr/bin/ksh # ***************************************************************************************** # copy_properties.sh # This script copies *.properties files from all directory excluding ...
0
votes
1answer
45 views

Creating a for loop with find -exec and while

I am trying to make this script that loops through video files created between hours 00 and 12, convert them with ffmpeg and then remove them. The script works in terms of finding the files and ...
0
votes
2answers
52 views

Why is find showing different ordering on CentOS vs RHEL?

I have 2 different machines - one running RHEL7 and one running CentOS-7.5. find --version reports version 4.5.11 on each. I've created the following dierectory structure on each. ./dir/some-file ./...
-3
votes
1answer
64 views

List files not owned by root at the / directory

The actual homework question is List all files/directories NOT owned by root and not created in July. I can't find a way to use ls and grep to output a file ~/NotOwnedByRoot.txt find / \!...
1
vote
3answers
73 views

Characters randomly disappearring from the output of “find”

I'm having a really strange behaviour of find, he is "eating" path characters, can't understand why. This is using a simple shell script to remux some mp4 files using ffmpeg. Here is the script: #!/...
0
votes
1answer
173 views

cp or ls command. File exist, but I get no such file or directory message

I have an linux car player. I need to copy libmedia-navi.so file from device to sd-card. But I can not. ls command lists some files with only "file name" and some files with "file name -> another file ...
0
votes
2answers
59 views

Find files inside numbered directories

In the directory below I want the list of files nested inside numbered directories at depth 1, which in this case are 6 to 11. $ ls * 1.org 2.MOV 3.MOV 4-1.MOV 5-1.mp4 5-2.MOV 5-2.org~ 9-2....
0
votes
1answer
27 views

Generate a sfv file with bash (crcs along with the paths)

How would I script something so that it gives me a list of crcs along with the paths, like an sfv file? I could code this in python but there is probably a simpler way in shell. So far I have: find ....
2
votes
1answer
49 views

Get list of files deleted by `find -delete` [duplicate]

This command lists all the files match the provided name: find . -iname .DS_Store But when I use -delete parameter with it, I can't see the list of deleted files. They just get deleted. Preferably ...
1
vote
2answers
91 views

How to search for a specific string in files from a specific date?

How can I search for a specific string in files from a specific date? For example, I have 3 files named 'a1' dated: 20 Feb, 'a2' dated 21 Feb, 'a3' dated 22 Feb. Now I want to search for a certain ...