Questions tagged [find]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
47 views

Dealing with spaces in bash when piping the results from one command to another

I need to go recursively through several directories/files, in bash, replacing a certain string with another if it exists in a file. I had this solved in my script with the line: grep -rl "...
3
votes
5answers
497 views

How can I find files in directories listed in a file?

In a directory there are several subdirectories, something like: TopLevelDir +-- SubDir1 +-- SubDir2 +-- SubDir3 +-- SubDir4 +-- SubDir5 +-- SubDir6 I need to find files containing some specific ...
4
votes
6answers
429 views

How to find directories containing only specific files

I have several directories with useless files (like *.tmp, desktop.ini, Thumbs.db, .picasa.ini). How to scan all drives to find directories which contain nothing but some of those files?
0
votes
1answer
39 views

use Find command to copy and change names

Hello I have a bunch of folders with several images (jpg and png) at the same directory level (./ParentDirectory/contents/1680x1050.png for example) called the same (1680x1050.jpg or 1680x1050.png) on ...
3
votes
3answers
106 views

Recursively “find” file names containing string and symlink files in another directory

I am trying to symlink a set of specific files from a project I'm working on. There is a known string in each of the filenames I wish to symlink. Here is what I have so far: ln -s find ~/path/to/...
8
votes
6answers
622 views

Find only those folders that contain a File with the same name as the Folder

I want to find all subfolders, that contains a markdown file with the same name (and extension .md). For example: I want to Find following subfolders: Apple/Banana/Orange #Apple/Banana/Orange/...
2
votes
3answers
58 views

How to find the last occurrence of a string in column 1 and replace the corresponding value in column 3?

I have three columns in a file as such: apple1 10109283 20012983 apple1 10983102 10293809 apple1 10293893 2349823049 apple10 109283019 109238901 apple10 ...
1
vote
0answers
23 views

Returning the topmost directory owned by a user if nothing is owned by another user in that directory

Take the following directory structure and ownership: userA ./dir1 userA ./dir1/dir1.1 userA ./dir1/dir1.2 userA ./dir2 userA ./dir2/dir2.1 userA ./dir2/dir2.1/dir2.1.1 userB ./dir2/dir2.2 ...
0
votes
0answers
36 views

Unable to make find command work

My Goal is to find the files and delete them which are older than 1 day. I am using the command to find(list them) with find /trunk/logs/ -mtime +1 -name '*.log' -ls > $LogName or find /trunk/logs/...
0
votes
1answer
24 views

Aligning Columns to Achieve `ls -l` Style Listing with find

I'm trying to achieve the same format of listing that I get from ls -l when using find. Albeit with the full path name at the end rather than the filename. FWIW I'm using find (GNU findutils) 4.5.11. ...
0
votes
1answer
34 views

Trying to find all directories over 1TB in size, and then ls -l to see the users that own those directories

I'm looking to find the disk space on my current working directory... and then only look for directory sizes over 1TB in size... and then take that output, and ls -l all of those specific directories ...
0
votes
2answers
51 views

Piped greps for looking inside files

(self-migrated from ask-ubuntu because it's linux-related, not ubuntu, and my os isn't ubuntu) I'm trying to make a grep that looks like this: grep -r 2019 | grep -riv FAILED | grep -rl DSL I want ...
0
votes
1answer
34 views

intelligent way to read another file for words to exclude while reading logs

I want to have a separate text file which I can modify anytime for words to be excluded while grepping the logs file. I have written below basic script to serve my purpose as of now. in SunOS Please ...
0
votes
2answers
42 views

Find directories that do not contain a file in only directories proceeding a specific directory

I have a large project for which I'm trying to find directories that don't contain a *_out.csv file. I have looked at other similar answers and I think I am almost there. The problem I'm running ...
1
vote
2answers
33 views

Find empty directoris OR directories with no files in them recursively

There's the find . -type d -empty command, but that only finds literally empty directories. What I want to achieve is something a little bit more complex: I want to find empty directories or ...
0
votes
2answers
69 views

How to save the progress of the “find” command?

I have big directory tree of files. I often use the find command to locate something in that tree. The first time after a reboot it takes some time, but subsequent uses are almost instant. Obviously ...
0
votes
1answer
48 views

rsync + using the flag ignore-missing-args

I am using the rsync version - 3.1.2.0 /usr/bin/rsync_bpc --version rsync_bpc version 3.1.2.0 protocol version 31 in order to copy files from /opt/dir to /tmp I am also using the flag- --ignore-...
1
vote
1answer
35 views

Find (and delete) all files with hard link count = 1

I'm having a tough time trying to reclaim some unused disk space on one of my macOS 10.13 partitions. Thanks to GrandPerspective, I think I found out that every time I delete some items in Photos for ...
2
votes
1answer
48 views

How to add double quotes to zsh function arguments?

I defined a function in .zshrc as follows: fdtnxg () { find $1 -type $2 -name "$3" | xargs grep "${@:4}" } If I want to use fdtnxg to grep alias mot in all files whose names start with tt. in ...
3
votes
1answer
48 views

Stuck With Using find and sed to Replace String in Filenames

Following this post as a reference, I'm able to run a find and sed command without it throwing an error, but the filenames remain unchanged. Trying to strip pronunciation_de_ from all mp3s in the ...
0
votes
2answers
62 views

Find file and rename on one command in bash

How can I find a file in a RHEL 7 server and rename it? Can this be done in one command? For example, I could: find . -name filename then cd to the directory then mv filename.conf filename2.conf, ...
1
vote
1answer
32 views

Removing directories not accessed in X days

I have written some scripts for downloading and caching music, and I like to delete the directories in the cache location that have not been accessed in X days. I can do that via: gfind "$music_dir" ...
0
votes
2answers
55 views

Find not working as expected with space in directory

I have a script calling this find "/mnt/Data/Shared/$1" -type d -exec bash -c 'fixperm "'${1}'" "fd" "$0"' {} \; $1 is a directory, when the name contains no spaces it works, when there is a space ...
0
votes
2answers
73 views

Sed could not edit : not a regular file

I have tried various solutions mentioned in SO to solve this problem i am facing. I want to find all files recursively and change certain text. This is the command I am using in cygwin in windows ...
5
votes
3answers
217 views

find mmin X min - is it X min when starting “find” or when “find” find the file?

Assume, I have about 10,000 files in a folder. I have been using hourly crontab to find files that are modified in the last 60 min then process it. Invoke find -mmin -60 at 01:00:00 Assume 1st file ...
0
votes
2answers
39 views

Find string2 when exist string1 in file

I have a configuration file (from Nagios) with the following structure: define service{ use pruebaspre-service,srv-pnp host_name server1.es servicegroups ...
0
votes
1answer
26 views

Grep “Pattern 2” only in files containing “Pattern 1”

I am trying to search for a "pattern 1" only in files that contain another string "pattern 2" E.g. A.txt Pattern 1 ... Pattern 2 B.txt Pattern Z ... Pattern 2 I intend to filter out files that ...
0
votes
0answers
22 views

Can't Find Installed Software in Ubuntu Search

I have installed some software from downloaded files (not from a repo) but I would like to be able to find them through the Ubuntu search engine in order to have them available in my task bar. For ...
1
vote
1answer
103 views

find: unknown predicate `-p'

find /log/ -mtime -31 -type f -name ""*data.txt"" -printf ""cp -p %p /Backup/%Td/\n"" | sh I am trying to set up this command in a cron job and it's complaining about unknown predicate -p. Not really ...
-1
votes
2answers
36 views

Weird behavior when looping over files in folder

No idea what's happening here. I am on Bash 3.2 on a Mac. I have: ores_resource(){ for f in "$(cd "$HOME/.oresoftware/bash" && find . -type f)"; do f="${f:2}" echo "my file $f"...
2
votes
1answer
39 views

Why is the warning about find important?

I'm reading how Linux works by Brian Ward and he has issued the following warning "Don't try options such as -exec before you know this form by heart" find -name file -print Thus far, I have not ...
0
votes
2answers
42 views

show number of files not matching certain file name pattern

I have some non standard and standard filenames like the ones below . I need to get the count of files that are NOT standard.. Standard file names: XYZABC.txt, XYZABC.csv, *.msg Non standard file ...
0
votes
0answers
48 views

How to execute the output of a “find” command using “-exec”?

This is related to my last question [How to always print an output with certain number of digits using AWK. So, now I have the following command; the goal is to copy bunch of files into different ...
1
vote
4answers
63 views

How to find and print files that are missing in a directory?

I want to find and list all directories that contain a file that ends in .grid in a parent directory /work/user/folder1/*/* find /work/user/folder1/*/*/ '!' -mindepth 1 -maxdepth 1 -name *.grid The ...
0
votes
3answers
40 views

How to copy files into another dir based on timestamp (day of the month) of the files?

Say I have these files in dir1: -rw-r--r-- 1 user user 10240 Jul 2 11:54 10_data.txt -rw-r--r-- 1 user user 36048 Jul 4 11:56 95_data.txt -rw-r--r-- 1 user user 35634 Jul 7 11:56 01_data.txt ...
0
votes
1answer
62 views

find . -type d -mtime +1 only shows one file in a 4 day span [duplicate]

I was trying to use find with -mtime +1 to find all directories older than 24 hours but having issues getting this done. I understand that using -mtime +n should remove n*24 hours of data but it seems ...
2
votes
1answer
35 views

Find exec - Why {} can't be used as the output file name? [duplicate]

I tried this command to compress all the css files in all subdirectories. find . -iname "*.css*" -exec gzip -c '{}' > '{}'.gz \; But it only creates a {}.gz file. I ended up using this: find . -...
-1
votes
2answers
45 views

linux + find + delete files on remote machines except particular files [duplicate]

we have redhat 7.2 Linux version I want to remove on remote machines all repositories files under /etc/yum.repos.d except the following files under /etc/yum.repos.d local.repo redhat.repo cluster....
0
votes
2answers
65 views

Find searches only for the first matching entry

I have to find all directory paths with specific subfolders. The search pattern is as follows: find /foo/*/searched_folder/bar -maxdepth 0 -type d ̶I̶t̶'̶s̶ ̶w̶o̶r̶k̶i̶n̶g̶ ̶p̶r̶e̶t̶t̶y̶ ̶w̶e̶l̶l̶ ...
1
vote
1answer
354 views

what does “$@” mean inside a find command [duplicate]

I recently saw a script in which below find command was used: find "$@" -type f -name "*.iso" What does "$@" mean here?
2
votes
2answers
149 views

find - how do i make an alias to do something like (find . -iname '*$1*')?

I have a findn function: findn () { find . -iname "*$1*" } Using this function has one downside that I cannot use -print0 | xargs -0 command (I am using mac) following findn filename to extend ...
0
votes
1answer
42 views

How to select a path in a find […] -exec cp {} dest_dir \; command?

I'm having a hard time trying to limit the path with find. I have this command find ${DIR_PATH} -type f -name ".py" -exec cp --parent {} ${DEST_DIR} \; Which give me this output : ${DIR_PATH}/a/...
0
votes
1answer
78 views

How do I write a shell script to flatten directories?

I wrote a simple script to delete useless files from a directory using the find command. Now I'm wondering if I can add lines to the script to flatten directories, but not completely flattened. e.g.,...
1
vote
1answer
27 views

Delete groups of lines that have the same first line, except for the first occurence

This may be a couple questions in one, but this problem has me stuck. I have a text file with groupings of four lines separated by an empty line. The first line of every grouping begins with a '>' ...
0
votes
2answers
30 views

Chaining find exec and a while loop

I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec ...
0
votes
1answer
24 views

Can anyone help me figure out what this “find” command with curly braces is saying? [duplicate]

I found some old notes where someone suggest I run the following command to set some file permissions: find /perl/lib/ -type f -exec chmod o+r \{\} \; Would you happen to know what the \{\} part of ...
1
vote
0answers
24 views

Find + regex: looking for a file name with multiple extensions, but missing the basic filename.jpg

I'm both a regex & SE Unix and Linux newbie, so I hope I'm doing everything right. I'm looking for files that have a name inside of the filename, and could have different extensions. I based my ...
0
votes
2answers
43 views

Print all subdirectories in the current directory that do not contain a .git

I'm trying to write a bash line that will look at all the subdirectories in my current folder and tell me if any do NOT contain a ".git". Pseudo: for subdir in currentdir if .git does not exist ...
1
vote
0answers
7 views

How to change modification dates uptill a certain date?

I want to copy the modification dates from my backup to my newly created server (forgot to specify the -p option on cp). As I changed files since I made the copy I only want to have the modification ...
0
votes
2answers
53 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 ...