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
0 votes
1 answer
22 views

How to combine find and cp in linux to copy specific files

I am having the following problem in linux: I need to find specific files from a directory and copy those files (if they exist) into another directory this is the command (i need to find specific text ...
user avatar
  • 3
0 votes
1 answer
42 views

How to use find and sed to replace certain sentences in files

I am using find and sed commands to find and replaces the occurrences of certain sentences in the whole directory with some other sentences. For example if I want to replace all occurrences of the ...
user avatar
  • 157
2 votes
2 answers
148 views

Looping through 'find' files and 'grep' to file character set result (standard input)

I'm using find to analyze a list of files. I want it to identify the files that are not ASCII files. So this is what I've tried on the command line: for me in `find 2022*`; do file -i $me | grep -L '...
user avatar
3 votes
2 answers
311 views

Filtering find results by length

I want to find all subdirectories inside a single directory. I need to filter by the name length. I have come up with the following: find ./directory -maxdepth 1 -type d How do I filter the results ...
user avatar
0 votes
3 answers
125 views
+100

Find number of lines between a pattern inside specific filetype

I have a notes.json file inside each directory. The following command counts length of each notes.json file and returns a sorted output by each file's number of lines. find . -name notes.json | xargs ...
user avatar
  • 7
2 votes
2 answers
254 views

find files matching pattern inside directory matching another pattern

Before I resort to writing Python to do this - there must be a way in bash with find or similar tools. I want to search a tree, and find all files whose name matches a pattern, that are in a ...
user avatar
0 votes
1 answer
44 views

`find` command doesn't return array like element, how to work around this

In powershell I'm used to doing something like this: > $python_files = get-childitem *.py > echo $python_files[0] The second command allows me to extract the first file, since get-childitem ...
user avatar
  • 101
0 votes
2 answers
61 views

xargs running more than one command?

Is it possible to use xargs to run more than one command? The only related information I found was this question, but the answer was not related to xargs. I'm running a simple du / -ah | sort -r -n | ...
user avatar
1 vote
2 answers
78 views

How to search filenames by regex with "find" and rename this files

I trying to find all files ending with : ancestors-the-humankind-odyssey-trailers-720-1262.mp4 high-tech-divers-1080-1234.mp4 amazon-divers-720-1323.mp4 and rename this files like this : 720-1262....
user avatar
1 vote
1 answer
57 views

How can I use `find` to find the files and awk to search within the files?

In a folder and its subfolders, I want to search a pattern. For this I am using: grep+cut+awk+tr pipeline. printf "I am so wide alper world zorro the end\t\t\talper\n" > alper.txt ...
user avatar
  • 230
0 votes
2 answers
32 views

Piping find to xargs works in terminal, but not in shell script [duplicate]

I'm trying to write a Bash shell script that copies all the files in the current directory, minus a few exceptions, into another directory. The script builds a command, stores it in a variable, and ...
user avatar
  • 101
0 votes
0 answers
21 views

find: unrecognized: -ctime (radial/busyboxplus:curl)

In a docker container running in a kubernetes pod I am using the below busybox docker image: containers: - name: busyboxplus image: radial/busyboxplus:curl I need to run something like this: ...
user avatar
  • 871
0 votes
1 answer
52 views

Deleting files using xargs prints lots of No such file or directory (but seems to work...)

I have a script that deletes files older than N minutes. The script basically runs: find /some-folder/* -mmin +59 | xargs rm -rf But for some reason it prints tons of: No such file or directory but ...
user avatar
  • 871
0 votes
0 answers
14 views

Debugging find query with -mtime

For some reason reason find command with -mtime option is not working for us. We have files that meet the mtime criterion specified but find is not giving any hits. First of all here are all the ...
user avatar
  • 137
0 votes
0 answers
17 views

find command with exec: are there differences between \; and + [duplicate]

I am looking at a crontab and there is an entry like: 0 * * * * find /path/to/file -type f -mtime +1 -exec rm {} + >/dev/null 2>&1 Now personally I would have used \; instead of + Are the ...
user avatar
  • 137
3 votes
1 answer
146 views

Handle names with spaces when iterating recursively over files [duplicate]

I am trying to recursively convert all .mkv files in a folder structure with subfolders to .mp4. I got a standard line that works in just the present folder for video in *.mkv; do ffmpeg -i "$...
user avatar
  • 135
0 votes
0 answers
21 views

find command behaving abnormally on rhel7 host

find command seems to be behaving abnormally when used with -user option find /var/tmp -type f -user `whoami` -name * or find /var/tmp -type f -user udunto -name * when used , prints file from root ...
user avatar
  • 89
0 votes
1 answer
56 views

How to remember, which order grep and find takes the parameters?

Every time I use grep and find I'm stumbling through, which order I should type the commands: When I should write the path and when I should write the flags, if it needs double quotations or not, etc. ...
user avatar
  • 145
0 votes
2 answers
37 views

How do I handle strange path characters when piping find output?

I had a problem where I wanted to find the length of each path from a find command. My first attempt was to run something like this: find . -exec sh -c "echo {} | wc -c" \; I got this idea ...
user avatar
0 votes
1 answer
26 views

How to display the paths to all files that have a size greater than the specified limit

I need to output the paths to all files that have a size greater than the specified limit (declared as a variable). I've done it using find script: FILESIZE = "+10M"; find "$1" -...
user avatar
  • 39
0 votes
0 answers
19 views

awk or sed - find and replace in multiple files according to a key [duplicate]

I have hundreds of files in which I need to make various replacements - and those replacements are not the same in all of the files. For example, I want to replace: WinEventLog with Windows SysMon ...
user avatar
0 votes
1 answer
38 views

A printf format for "find" or a means to control diff in comparing files across file systems

Working from home, the contents of my laptop undergoes a lot of changes. Before lockdown, I was usually in the office, and I could manually mirror files to a network drive. Working from home means no ...
user avatar
-1 votes
1 answer
18 views

xargs -I# showing unexpected behavior - why?

I'd like to zip a whole bunch of folders which are in a certain directory, creating one zip file per folder. To do that, I use the following command: $ find -maxdepth 1 -mindepth 1 -type d | xargs -I@ ...
user avatar
  • 2,191
0 votes
1 answer
24 views

Script for copy bookmarks from one pdf to another

I want to transfer bookmarks from a series of uncompressed pdf files to their compressed copies (these copies do not have the original bookmarks). I know how to do this one by one using pdftk. First I ...
user avatar
  • 218
0 votes
0 answers
27 views

why does find alter matching behaviour when -exec is appended here? [duplicate]

Consider the following: /tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' ./spam ./eggs /tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' -exec ls \{} \; ./eggs /tmp/tmp....
user avatar
  • 753
0 votes
1 answer
36 views

Command substitution with xargs inputs [duplicate]

I'm trying to write a simple command that will create symlinks for all files in a specific directory (Yes, exactly like lndir but I cannot use it so I try to mimic it). I tried the following using ...
user avatar
0 votes
0 answers
19 views

Linux Bash how to find only xdev links

How can I just find paths (linux find command or another) which are omitted by -xdev option. Meaning looking for a command/script fpr finding links which are pointing to paths on other devices and for ...
user avatar
  • 1
3 votes
1 answer
673 views

Linux Bible 10th Edition: why -exec cp can't copy files even with super user privileges?

I read "Linux Bible 10th Edition" at 130 page. Exercise №7: Create a /tmp/FILES directory. Find all files under the /usr/share directory that are more than 5MB and less than 10MB and copy ...
user avatar
  • 135
0 votes
1 answer
16 views

how to "execute command on file in multiple subdirectories within containing folder" i.e cd into each subdirectory containing file and execute command

I have a file named filename.sh in different directories. I am trying to simultaneously submit this file to run on a number of cluster nodes. I need to find this file wherever they may be, cd into ...
user avatar
0 votes
0 answers
23 views

Error "File System Loop Detected" Permission Denied to Decrypt folder with ecryptfs-recover-private

I'm trying to open encrypted files from a full encrypted drive that is unlocked and mounted. I have tried various commands and have been unsuccessful. How can we fix the find "file system loop ...
user avatar
  • 13
0 votes
1 answer
26 views

Find with optional parenthesised arguments

How to add optional grouped argument lists to find? For example, using an array of base arguments that define files that will always be found, no matter what other variable conditions are specified. # ...
user avatar
  • 147
1 vote
0 answers
79 views

Use of _ in bash find command

What is the function of the underscore (_) in the find command below which is a command to create a file in all directories? find . -type d -exec sh -c 'echo "nameofyourwebsite" > "$...
user avatar
  • 11
0 votes
2 answers
53 views

sed and awk in sh script not replacing text

The desired work to find a string, and replace to another (all occurrencies), and rewrite/update the file too. The file is an pbxproj file. I linked a sample of this file sample of the file (please ...
user avatar
  • 13
2 votes
3 answers
49 views

How I can find all files that corresponds to pattern like .gitignore

So for example. I have a file like .myignore. In that file, I have strings like: .vs/ *.suo *.user *.log Then I want to find all files that match to the pattern in file .myignore.
user avatar
  • 123
0 votes
1 answer
36 views

Move and rename video files (*.mp4) shorter than 3 min

I am trying to create a bash script that moves/renames (and / or creates a symbolic link) to all video files that are shorter than 3 min. So far I have this Find command: find "$findpath" -...
user avatar
2 votes
2 answers
57 views

How does find . -type f -print -o -name . -o -prune actually work?

As background, I'm using git on an hp-ux 11.11 (11v1) system. I'm doing an extensive .gitignore file to exclude many many files. My .gitignore is basically "Ignore everything, except these ...
user avatar
0 votes
1 answer
26 views

how to remove/rename an extension from a folder

I have a few folders like name1@domain.com, name2@domain.com, name3@domain.com. i want to rename them so that it will be name1, name2, name3 etc. i figured out that if they are vise versa i.e name1, ...
user avatar
0 votes
2 answers
43 views

Find files that are named from a list of patterns in file #1 and grep inside them for patterns found in file #2

I am trying to fix a bash script that is supposed to: Go to a directory (RESULT_DIR) Find csv files that have matched names from a list file (Names.txt) Grep from patterns listed in (Patterns.txt) ...
user avatar
0 votes
1 answer
163 views

Rsync files by date

I have this file structure: ...folders/to/copy ...folders/to/mirror I've been doing: rsync --ignore-existing -raz --progress $source $destination This is serving well for the purpose of keeping ...
user avatar
0 votes
0 answers
35 views

when to use -I in xargs

I have difficulties understanding how to use xargs especially using flag -I. I have two html files in my current directory $ ls $ hello world.html hi.html junk I know if I want to copy these ...
user avatar
  • 1
1 vote
1 answer
42 views

Discover root cause of find command running

This morning I came in and noticed my hard drive light was solid on. This was unusual so I ran iotop and saw a find command was searching my filesystem. I decided to run ps auxZ to dump the processes ...
user avatar
-2 votes
3 answers
49 views

cp with matched pattern of parent directories

copy directory with a matched pattern of parent directories cp dir/group1/sub01/./././DCM dir/group2/sub01/././DCM to dir/Base/group1/sub01/Time1/ dir/Base/group2/sub01/Time1/ with matched group ...
user avatar
0 votes
1 answer
34 views

How to pass more than one argument from `find -exec` to a `bash -c` sub-shell?

Is there a way to pass more than one argument from find -exec to a bash -c sub-shell? Given this working invocation which searches all videos matching a glob pattern (eg "*dogs.mp4) and then ...
user avatar
  • 1,425
1 vote
1 answer
282 views

bash count files and directory, summary size and EXCLUDE folders that are fuse|sshfs

I need help for a bash script that counts files and folders in a specified directory on a Linux system (Debian), but I want to exclude a specified folder. I have a main directory named workdir with ...
user avatar
-1 votes
1 answer
88 views

Find "latest" path, filename, date, and time at every level of a folder subtree with Bash [closed]

Using Bash, I want to find for any specified directory and its subtree the filename, creation_date and creation_time for the file last created in that directory. For example, the output would be: /...
user avatar
  • 9
0 votes
1 answer
213 views

find files, exclude directories

I would like to compose a string of command line arguments in a variable, then use those to execute a command. I show a simplified example below. It's is a script called "listfiles." It ...
user avatar
0 votes
3 answers
181 views

Find Directories Older Than X Days Named in YYYY-MM-DD & Delete If Exists

I tried to create this one liner bash script which finds and then deletes directories older than X days based on their file names and code works flawlessly if directory exist. The only issue is that ...
user avatar
0 votes
1 answer
52 views

preserve environmental variables with find -exec

Is it possible to preserve environmental variables with find -exec? I don't see any options using the FreeBSD version of find. I can switch to a for loop if absolutely required, but was hoping to ...
user avatar
  • 1,122
0 votes
1 answer
28 views

How might I save the the output of "find .... -execdir ..." to a log?

I cannot get the following script: #!/usr/bin/bash /usr/bin/find ~/CS -iname "*.html.pmd" -type f -execdir /usr/bin/raco pollen render {} \; > ~/rendering to redirect the output to the ...
user avatar
0 votes
2 answers
41 views

How to use find command to search strings in filenames in the order that I typed?

Say I'm trying to find a file name that contains the two words One and Two. The sequence must be in that order e.g. ./fksklknejnwjOnesvjnh9uibivuwTwojnwovno. At the same time, I would want to exclude ...
user avatar

1
2 3 4 5
66