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
1 vote
0 answers
31 views

delete all folders containing deployfiles but not containing name DEV in absolute path

I would like a generic/posix/ansible solution to the below requirement for non-windows(preferably Solaris and Linux) -> I wish to list all files under /web/bea_apps/dev/TomcatNode01/deploy -> ...
Ashar's user avatar
  • 481
0 votes
1 answer
34 views

Find specific files in sufolders, and move them into a specific folder, batch

I am quite new at using Linux and the terminal and I am stuck with something. I have about 50 parent folders, all containing subfolders. One subfolder is called filtered_feature_bc_matrix. In an other ...
Camille Cohen's user avatar
1 vote
1 answer
86 views

How to exclude different levels of subdirectories with cp?

This is a follow-up question to my original post: find & cp command doesn't copy 1st level directory I have a directory structure like this: test folders ├── 1 │   ├── 1-1 │   ├── 1-2 │   └── ...
anmac1789's user avatar
0 votes
1 answer
60 views

find & cp command doesn't copy 1st level directory

I have a directory structure like this: test folders ├── 1 │   ├── 1-1 │   ├── 1-2 │   └── 1-3 ├── 2 │   ├── 2-1 │   ├── 2-2 │   └── 2-3 ├── 3 │   ├── 3-1 │   ├── 3-2 │   └── 3-3 └── 4 ├── 4-1 ...
anmac1789's user avatar
0 votes
1 answer
25 views

How do I correctly define and interpolate this variable into my find command? [duplicate]

I wrote a Bash script, mscript.sh for managing my music files, a part of it creates a list of such files. all_exts=" -iname \"*.webm\" -o -iname \"*.mkv\" " #all_exts=' -...
John Smith's user avatar
0 votes
1 answer
71 views

Pipe sql query to find command

OS: RockyLinux 8.5 This command works wonderfully: sqlite3 files.db "select file from A;" | rsync -R -av --files-from=/dev/stdin /SOURCE /DESTINATION/Out result without pipe: sqlite3 files....
Gary Schermer's user avatar
0 votes
3 answers
78 views

delete subdirectories only at maxdepth 2 and above

I have directory with 6 subdirectories but I wish to delete subdirectories from only 3 of them, hence I used a for loop to 'cd' inside these 3 directories, but I want to delete the subdirectories at ...
user16454406's user avatar
2 votes
1 answer
266 views

"ls" counterpart to "find" operator "-printf"?

The find command has a handy -printf operator that prints user-specified metadata for each found file/folder. Is there such an option for the ls command? As an alternative, I can feed the list of ...
user2153235's user avatar
0 votes
1 answer
36 views

Slow down a `split`

I have a really large archive consisting of really small files, concatenated into a single text file, with a "" dilimiter. For smaller archives, I would split the archive using "" ...
Alex's user avatar
  • 1,145
0 votes
1 answer
59 views

Basename detects an extra operand if I use it with find

I try to execute basename via find like this: find ./test_folder -type f -exec basename {} + But I get the following error: basename: extra operand './test_folder/test/file.crt' Why I get this ...
Dimitrios Desyllas's user avatar
1 vote
4 answers
95 views

How to sort and filter images by modification time and view them in nsxiv on FreeBSD

I am using nsxiv to view JPEG and PNG images on FreeBSD. However, I am unable to find a way to sort and filter the images by modification time to view them in nsxiv on FreeBSD. On Linux with GNU ...
Flux's user avatar
  • 2,770
0 votes
2 answers
34 views

bash using "find" in dir1 and delete these files in dir2

I have two folders. I want to find files with a specific extension recursively in dir1 and delete files which are found in dir1 from dir2. I think this can be done with -exec command in find. Deleting ...
DF8OE's user avatar
  • 33
0 votes
2 answers
87 views

find exec - use only partial filename from {}

I have following directory structure: ├── file1.json ├── file2.json └── file3.json I want to remove the .json suffix. I know the best way would probably be the rename command or to use a for-loop, ...
Pixelbog's user avatar
  • 661
1 vote
1 answer
89 views

`find: fts_read: Invalid argument` when working with around 8000 files

GNU bash, version 3.2.48 has this bug; already version 3.2.57 does not. Make a file with 8000 identical lines (say each line says 1). Run split -a3 -p "1" on it (-p is a BSD split option ...
Alex's user avatar
  • 1,145
0 votes
0 answers
24 views

In `find -exec`, using back quotes (backticks) with `stat` [duplicate]

I would like find to execute a different command depending on what the stats of a file are. If I run the command find . -name "*" -exec echo {} \+ then I get the list of files in the ...
Alex's user avatar
  • 1,145
4 votes
6 answers
1k views

Is there any elegant way to find only symbolic links pointing to directories, not other files?

find -type l and ls -l | grep '^l' show symbolic links but do not distinguish between symlinks pointing to directories and those pointing to files. A very kludgy way to do something like this is find -...
Adam J. Kessel's user avatar
2 votes
1 answer
59 views

Replacing a character in all files names of a directory

This is homework! I'm trying to replace all spaces in file names with an underscore in the yay directory. It asks me to use the commands xargs and sh without using $(command). I tried using conducts ...
cow's user avatar
  • 81
-1 votes
1 answer
65 views

Why doesn't realpath --relative-to work in a command substitution?

user@debian:~/test/B$ find .. .. ../A ../A/x ../A/y ../A/z ../B user@debian:~/test/B$ find ../A -type f -print0 |xargs -0 -i% realpath --relative-to=../A % x y z user@debian:~/test/B$ # But user@...
FriendFX's user avatar
  • 357
4 votes
4 answers
1k views

Delete all files without user permissions

I have a prompt that asks me to delete all the files in a directory that the owner (u) can't r, w, nor x, in one command. I tried this command: find data -type f ! -perm -u=rwx -exec rm -f {} \; ... ...
cow's user avatar
  • 81
0 votes
5 answers
164 views

How can I find all of the directories that contain one or more files?

I have a hierarchy of directories. Some directories do not contain files and they only contain other directories. Some contain files. For example: - movies - 2022 - action - movie.mp4 ...
Saeed Neamati's user avatar
0 votes
1 answer
31 views

How to make emacs start in bash by visiting a find command result containing whitespace in its name and double quotes in path? [duplicate]

I'm confronted with an escape challenge: The process: Step 1 - the file retrieval: Within bash, find command will be invoked. Find commands output is 1 single file with a path like this: ./vacation/...
user avatar
1 vote
3 answers
314 views

How to remove files according to their MIME type?

(Hello! And especially hello to everyone as it is my first post here.) I want to remove files according to their MIME type with a command, in a folder and its sub-folders, say .webp and .png pictures. ...
UnixToo's user avatar
  • 11
1 vote
1 answer
37 views

How I can aggregate my matches from find command by grepped values?

I am looking for all occurences of <source_model>.*</source_model> at any files located at ./vendor/magento/*/etc/adminhtml/system.xml: find ./vendor/magento/ -type f -path */etc/adminhtml/...
Dimitrios Desyllas's user avatar
0 votes
1 answer
75 views

grep -rlw but only on files that are as newer than 7 days?

Currently, I use this version of grep -rlw grep -rlw . -e "string_to_search" To search for overall files containing "string_to_search". I want to modify it to find files that are ...
achhainsan's user avatar
0 votes
2 answers
65 views

Basename in find -exec

I need use in find results full path and dir name. This not work: find ./1cv8 -maxdepth 1 -type d -wholename "./1cv8/*" -exec bash -c 'echo vrunner -src "{}" -o ./builds/"${...
Dmitriy's user avatar
-1 votes
2 answers
92 views

Search for a string at proximity with another string?

Say I want to search for '123456789' and I want it to be near 'firstname'. Is there a way to do it? I've 0 logic to do this. Maybe piping greps could work? What kind of algorithm is best suited for ...
achhainsan's user avatar
1 vote
1 answer
36 views

remove all file types from dir not working

My dir is as following: Music: 1.mp3, 2.flac, 3.wav, 4.ogg and 5.mp4 I'm trying to remove all files with extensions: .mp3, .wav, .flac and .ogg with the following command: find ./Music -type f -name \(...
Mathew's user avatar
  • 235
0 votes
2 answers
78 views

how to get file path without the filename itself

im trying to find my .csv files then cd into their directory: find Documents/notes -type f -name "*.csv" | head -1 | xsel -b this copies the first file dir into my clipboard and i'd like to ...
Mathew's user avatar
  • 235
0 votes
0 answers
46 views

linux Find Command not finishing

I have a directory /home/history/customer find /home/history/customer -type f -mtime +90 -print there are no files older than 90 days. but this command just doesn't stop running and doesn't return ...
Barnardx's user avatar
0 votes
2 answers
23 views

Using find in order to detect a magento module

At magento routes are located in adminhtml/routes.xml each module has a folder named adminhtml with a file routes.xml each module has its own folder. In other words I have the following file structure:...
Dimitrios Desyllas's user avatar
0 votes
2 answers
65 views

Stuck at finding the most recent file from a list of directories

I want to find a list of directories, then search for a given file inside them, then choose the most recent one. This is what I try: find /Temp -type d -name Ast 2>/dev/null | while read Dir; do ...
Saeed Neamati's user avatar
3 votes
1 answer
246 views

How does `ls` find hard links?

Setup The following sequence of commands is setup for my question. root@cd330f76096d:/# cd root@cd330f76096d:~# ls root@cd330f76096d:~# mkdir -p my_dir/my_subdir root@cd330f76096d:~# ls -...
Sweet Shell O'Mine's user avatar
6 votes
3 answers
479 views

Pass result of find command as another command's multiple options

I have a CLI tool that can take an option with multiple values - The syntax is like this: CLI -I path/to/file1 -I path/to/file2 ... How can I pass the result of the find command to this CLI? For ...
hongweiy's user avatar
1 vote
3 answers
111 views

Make `xargs` use the maximum multiple of N arguments

I have a a file that contains more than a hundred thousand of IDs. Each ID is composed of 8~16 hexadecimal digits: 178540899f7b40a3 6c56068d 8c45235e9c 8440809982cc 6cb8fef5e5 7aefb0a014a448f ...
Fravadona's user avatar
  • 561
0 votes
1 answer
38 views

How to find and exec with or [duplicate]

I am trying to find files with *.c and *.h extensions. I use the following command find "$path" -type f -iname "*.c" -o -iname "*.h" -exec ls {} \; This only executes ls ...
Bret Joseph's user avatar
1 vote
2 answers
37 views

Move and rename multiple subdirectories to new location

My directories are setup in this way: dir 1 001 11-20-2001-RT SIMULATION-57976 002 11-20-2001-RT SIMULATION-30560 003 08-24-1998-RT SIMULATION-72882 and so on for about 250 entries. My goal is ...
goldenburrito's user avatar
0 votes
5 answers
65 views

How do I find all directories that contain matching files?

I am looking for directories that contain files that match a pattern, say, foobar*.csv. Directories that do contain such files may contain hundreds of them (and no subdirectories!), so I want find to ...
sds's user avatar
  • 1,656
2 votes
1 answer
98 views

Find command with -mmin not working as expected

In our production servers(AIX)there are multiple API calls which made every micro seconds and those API call details will be appended in an log called ins.log. On the other hand, we are using this ...
thelak kumar Anbalagan's user avatar
5 votes
6 answers
1k views

How to find files that don’t have a suffixed version?

I have a few million .jpg files and I want to generate a .jpg.webp version for each one (foo.jpg -> foo.jpg.webp). For this, I need to find all files ending in .jpg for which there’s no .jpg.webp ...
bfontaine's user avatar
  • 168
-5 votes
1 answer
63 views

Why does `find . -type d -not -perm 775` print out directories with `rwxr-xr-x` permissions? [closed]

I want to find all directories without a specific set of permissions. As seen from the below image, find prints out directories that should not be listed. Can someone describe why?
Shuzheng's user avatar
  • 4,203
3 votes
2 answers
227 views

I want to find lines where a specific word appears in a file along with line number and take the line numbers in an array .How to do that in bash?

This returns line numbers but they are in a string: grep -n -F -w $word $file | cut -d : -f 1
Arpan Koley's user avatar
1 vote
2 answers
107 views

Execute on all files without corresponding extension

How can I find and execute a program when the said file does not have a corresponding file? Example files: /file1.c /file1.h /file2.c /file3.c /file3.hpp /file4.c/unrelated.txt find / -type f -...
wjwrpoyob's user avatar
  • 420
7 votes
4 answers
435 views

Is it possible to selectively apply minimum depth in a find command?

I have a file hierarchy like: data ├── debug.log ├── messages │   ├── msg001.txt │   ├── msg002.txt │   └── msg003.txt └── pictures ├── msg002 │   └── pic001.jpg └── msg003 ├── ...
Tom Anderson's user avatar
2 votes
3 answers
120 views

Deleting files whose filenames match strings contained in a file

There is a text file, del.txt, containing a list of randomly-generated identifying strings, for example: 07ckv978yk0 HuinLBoZHcY _oR7ccXiunY I would like to delete any files whose filenames contain ...
Clayton's user avatar
  • 23
0 votes
1 answer
50 views

find -exec bash -c {} +: why only one file of found two?

touch 1.txt 2.txt find . -name "[12].txt" -exec sh -c 'echo "${1}"' sh {} + -exec echo {} + ./2.txt ./2.txt ./1.txt Why echo within sh -c outputs only one file? Today I thought I ...
Alex Martian's user avatar
0 votes
1 answer
67 views

cp AND rsync exclude all files of all types from all subdirectories, only keep directories [duplicate]

when using find . -type d it excludes all files whether in parent directory or in subfolders from the search. I want to extend this into a -exec cp -p or rsync "{}" destination \; so that ...
anmac1789's user avatar
0 votes
1 answer
23 views

Find(1): test 'A' pass but test 'A -o B' fails [duplicate]

This function doesn't print out anything; skyrimse_testroot() { local directory="$1" find "$directory" \ \( -type f -ipath "${directory}/data/scripts/*.pex&...
B. Bergeron's user avatar
0 votes
1 answer
52 views

Just as there is "locate" to "find". Is there a database for a faster "grep"?

locate (or rather, updatedb) is somewhat simple: it takes the output of find for the required paths (usually '/'), sorts it, and then compresses it with a front-compression tool (frcode), in which the ...
Sebastian Carlos's user avatar
1 vote
2 answers
346 views

find command - list all directories with a set sticky bit

This doesn't work find / -type d -perm 1000 The problem is, that it matches only the exact permission (1000), but I only want to find out if the sticky bit is set or not. I don't care about the other ...
Pixelbog's user avatar
  • 661
1 vote
1 answer
51 views

Rename the sub-sub-directories of a directory named _QWE

I can run a command in all directories named _QWE using: find . -name '_QWE' -type d -execdir touch {}/1234.txt \; However, I need to run -execdir rename 's!^\./(\d+ -)\s(\d+\.)!$1!' {} \; in all the ...
Ahmad Ismail's user avatar
  • 2,560

1
2 3 4 5
70