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

1
vote
0answers
24 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
325 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
14 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
50 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
212 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
34 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
41 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
36 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
170 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
351 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
37 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
81 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
36 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
40 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
39 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
50 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
47 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
votes
0answers
36 views

Find and replace based on directory name using csv

I have to edit a bunch of html files in different directories and am trying to find a quick way to do it. For example: In directory ABC I want to edit index.html replacing with text that I have in ...
1
vote
3answers
72 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
75 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
57 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
24 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
35 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
54 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 ...
1
vote
1answer
31 views

remove files under specific folder

What is the diff between the following two approach ? find /calc -type f -delete find /calc -type f -exec rm -f {} + my target is to remove any jar file/s under calc folder any prefered of one of ...
1
vote
2answers
78 views

How to recursively copy only the files from folders and subfolders?

Under /home folder we have many subfolders, as the following: /home/user1 /home/user2/user_sub_2 /home/user3/user_sub_3/info_sub /home/user4/INFO_FOLDER We want to copy all the files under /home, ...
7
votes
2answers
488 views

What is wrong with my use of “find -print0”? [closed]

I'm confused by this experiment (in Bash): $ mkdir 'foo\n' $ find . -print0 | od -c 0000000 . \0 . / f o o \ n \0 0000012 As you can see, "find" is correctly delimiting the output ...
1
vote
1answer
61 views

Lockdown find command in sudoers with regex

I want to allow a service user to search for files via a dialog script, but lock down the find command via sudoers, so only one command including a regex is allowed. This exact command should be ...
1
vote
3answers
43 views

move files from subdirectories to current level and rename if exist

since I'm on a mac, the mv is a bit different which doesn't support the --backup attribute, the best I can come up with is find . -mindepth 2 -type f -print -exec mv {} . \;
0
votes
0answers
53 views

Using egrep in a find command to search for a variable and a constant

I'm working on a bash script to search a set of log files that record login attempts to the server and isolate if the most recent attempt resulted in an account lockout. First, I crafted a a variable ...
0
votes
1answer
45 views

Log the files found with the linux find and sed command

I have a folder with txt, html, jpg and png files. Now I want to go over all textbased files (txt and html) and start a search and replace. I did the following and it is working fine: find ./ -...
1
vote
1answer
21 views

How to use 'find' and 'cpio' to exclude parent directories

I want to copy over all html files in a nested directory but I want to prevent the parent folders above it from being generated as well. That is if my source path is /project/ng1/src/templates/**, ...
0
votes
2answers
82 views

Use FIND with MV to rename files. Delete the found string then prepending it to the filename?

find . -type f -name '*authors-name-string*' -exec bash -c 'mv "$0" "${0/authors-name-string/}"' {} \; I am trying to rename files nested in several layers of directories that contain an author's ...
0
votes
3answers
44 views

how to get the logs of integrated command of find and mv?

I used this command to my script to find specific files and to moved to different folder; however, I would need to generate a log of which file/s I have moved. find $1* -prune -name "*.$2" -mtime +$3 ...
0
votes
0answers
44 views

IFS variable and filenames with spaces and newlines

(Using Bash 4.4 and 5.0) I am dealing with the issue of filenames that contain spaces, newlines and backslashes. I often read the suggestion to use code like this: oldIFS=$IFS IFS= while read -rd ...
0
votes
0answers
35 views

find: paths must precede expression: in bash shell script [duplicate]

I can run this from the command line and it works: find /var/www/vhosts/foo/httpdocs/content/templates/ -name '*.plg' -print | xargs sed -i 's|mysql_|mysqli_|g' So I wrote the following sed.sh file ...
6
votes
4answers
787 views

how to list all python test scripts that contain “def test” [duplicate]

Want to list all python test scripts that contain "def test" This command line did not work while individual command works find . -name "*.py" | grep "def test"
0
votes
1answer
47 views

Find all files with group write only permissions

In the following example directory $ ls -l total 0 -rw-r--r-- 1 user testgroup 0 12 feb 12:00 file1 -rw-rw-r-- 1 user testgroup 0 12 feb 12:00 file2 -rw--w-r-- 1 user testgroup 0 12 feb 12:...
0
votes
1answer
37 views

How can I use an argument from xargs to evaluate another expression?

I would like to evaluate a basename expression given an argument from xargs. I tested: find . -name '*.txt' | xargs -I f cp f DIR_OUT/copied_$(basename f) which gives no file or directory because $(...
3
votes
1answer
120 views

How to find and delete duplicate video (.mp4) files? [closed]

I have 16,000+ short video clips and there are lots of them that are exactly alike to the human eye, but if you examine very closely you will find that one or the other may have an extra 1 second (or ...
0
votes
2answers
51 views

set -f inside function

I have a directory with files file1.c, file2.c and file3.c. The command find outputs: $find -name "*.c" ./file1.c ./file2.c ./file3.c Then I would like to use find without the quotes around .*c. ...
0
votes
3answers
85 views

Regex that matches this list of files?

I had a user on our shared host who let their Wordpress install fall victim of an exploit that allowed for arbitrary file creation as the apache user. The files generated are obviously generated with ...
1
vote
2answers
47 views

Command to find and combine files matching a complex name pattern

My Linux directory contains a dump of files and they look like: EDW_Infile_ABC_Daily_Activity_20190204.csv EDW_Infile_ABC_Daily_Activity.zip EDW_Infile_PQRInc_Daily_Activity_20190204.csv ...
0
votes
1answer
132 views

Ignore case in Find command

I want to search file in 2 different directories using find command, find $file_dir1 $file_dir2 -name 'searchpattern*' | tail -10 I am using this command now, but it is case-sensitive search. I ...
0
votes
2answers
85 views

How to list all filenames in the system [closed]

I want to perform checks on all files in the system. For that I need the full paths of all files in the system. My initial idea was to do something like this: for file in $(sudo find / ); do if [ -...
0
votes
0answers
37 views

find `-delete` doesn't delete files? [duplicate]

Look at this example: $ ls -l /home/kossak/.asdf/shims/gettext -rw-rw-r-- 1 kossak kossak 0 Feb 6 13:51 /home/kossak/.asdf/shims/gettext $ find ~/.asdf/shims -name 'gettext' -or -name 'gettext.sh' /...
1
vote
1answer
43 views

Terminal: rename multiple JPG files to HEIC format giving a condition

I have a folder where there are many pictures taken with my iPhone. Turns out that half of them are JPGs and half of them were supposed to be HEIC format. For some reason, all pictures in this folder ...
-1
votes
1answer
47 views

Did I Mess Up My Computer with Recursive rm of '*.h"

So I was basically trying to print all files with a .h file extention out of curiosity, and so I simply googled how to do that. Unfortunatley, I didn't pay close enough attention to the answer and ...
0
votes
4answers
82 views

How to find filenames, sort it alphabetically then only head the first 3 characters?

I want to find all files in the current directory, sort them alphabetically before processing their content to extract the first 3 characters in each of them. Doing so will create a sentence that I ...
0
votes
2answers
42 views

Batch rename a lot of file using a number find in filename

I have hundred of file name with a number tag in filename like this: AAAA #12 SSSS.TXT BBB #231 CDF.TXT CDFSDAAAA #1 AAAASS.TXT and i want to rename so: #012 - AAAA #12 SSSS.TXT #231 - BBB #231 CDF....