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

11
votes
4answers
26k views

How to use “cat” command on “find” command's output?

I want to redirect the output of the find command to cat command so I can print the data of the given file. So for example if the output of find is /aFile/readme then the cat should be interpreted ...
0
votes
1answer
48 views

How can i terminate 'find' after the first match?

I am using find in a while loop. it takes a list of ips in ip.txt, searches for the ip in a directory of files and then writes the name of the file that each IP was found in to a file called results....
27
votes
1answer
4k views

Is it possible to use `find -exec sh -c` safely?

I'm trying to use find to echo 0 into some files, but apparently this only works with sh -c: find /proc/sys/net/ipv6 -name accept_ra -exec sh -c 'echo 0 > {}' \; But using sh -c with find -exec ...
0
votes
2answers
19 views

finding files of a particular pattern

I want to find names of the file having abc in its name. For example: Dozain123.ctabcln_WbLogReq.log' Dozain123.ctabcln_WbLogReq123.log Dozain123.ctabcln_WbLogReq456.log Dozain123....
1
vote
4answers
508 views

Bash command to “search and replace” file in changing directory tree

I've built a collection of files for research in a central repository on my server. I'm continually curating the repo changing the directory's tree structure by renaming and moving directories. And I'...
0
votes
2answers
24 views

Raspbian, debian: Howto make find $SOURCE return all directories under $SOURCE without itself [duplicate]

I use rsync to copy directories including files, with --remove-source-files I let rsync delete source files. Unfortunately it doesn't delete directories so I would like to delete all empty directories ...
3
votes
4answers
79 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
2k views

Find if the file is compressed or not

I need to find whether the file is compressed or not in script.If it is compressed I need to uncompress and send as attachement. My find command results in two files sum12.pdf.Z and sum23.pdf.Z My ...
-2
votes
5answers
62 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?
0
votes
1answer
19 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 ...
1
vote
1answer
98 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: backup-20151219....
3
votes
2answers
506 views

Faster search than find

Is there a way to find things faster than find . I am/was doing :- $sudo find / -perm +4000 But it takes ages to find the required info. and I know that most of the files which would that specific ...
-1
votes
1answer
26 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 ...
38
votes
9answers
30k views

Finding all “Non-Binary” files

Is it possible to use the find command to find all the "non-binary" files in a directory? Here's the problem I'm trying to solve. I've received an archive of files from a windows user. This archive ...
6
votes
5answers
1k views

I would like to find the largest file in each directory recursively

The output would include the directory name, file name and file size. One (largest file) for each directory from where the command is run. If possible the average size of the files in that directory ...
6
votes
4answers
1k views

what's the difference between using 'single quotes' or not in find command

find ~/ -name *test.txt find ~/ -name '*test.txt' I need to construct an example where the first form fails but the second still works.
6
votes
3answers
2k views

Meaning of @0 in a shell script

I was looking at the script /etc/init.d/sudo in my Ubuntu 14.04 Linux system. While reading the script, I found this statement : find /var/lib/sudo -exec touch -d @0 '{}' \; What is the meaning of @...
0
votes
1answer
103 views

Creating a script that organizes drums [closed]

I would like to create a script that looks in a specified directory, takes in a keyword (i.e. 'kick' , 'snare') and copies all related .wav files into a separate directory. I would then like for it ...
21
votes
9answers
28k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
4
votes
2answers
76 views

Invert matching lines, NUL-separated

I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from ...
3
votes
1answer
1k views

Exit bash when find gets to a folder with permission denied

I'm trying to write a Bash script. Where I go through folders recursively and make a list of and count files and folders. In a way it works but if "find" gets to a directory where it has permission ...
2
votes
2answers
114 views

How to delete files if a numerical part of their name is greater than a given number?

I've got files like this: cap_20151023T122915_791033959.png cap_20151023T122918_946392456.png cap_20151023T122920_227637228.png cap_20151023T122920_875467456.png and I would like to use the find ...
0
votes
1answer
64 views

Folder research task

I have a folder with 3 subfolders containing 6 files each.There are 2 files in each subfolders with :NOPM in their file names. I need to create a shell script that checks all the folders and their ...
0
votes
1answer
715 views

How do I delete directory and file, if .picasa.ini is the only file in the directory?

I want to start from a root directory and recurse through the tree. I want to delete the directory and file if there is only one file in the directory called .picasa.ini It seems like the "find" ...
2
votes
4answers
71 views

Listing files recursively, grouping by user and summing its size

I need to verify the size occupied by each user on my Linux server (all files recursively inside my data folder). With the code below I can get all of my files and their users, but I don't know how ...
2
votes
4answers
2k views

Use find + sed + cp to find files and copy them to a directory with a different name

I'm trying to copy a bunch of files named folder.jpg into a folder. The problem is because all the files are named the same thing, I need to rename them in the process. I know I can probably do it ...
1
vote
1answer
468 views

xargs: 'ls' terminated by signal 13 [duplicate]

find . -type f -print0 | xargs -0 ls -ltr | head -n 10 | awk '{print $NF}' | xargs rm This command is giving me this: xargs: 'ls' terminated by signal 13 However, it's executing fine. It's supposed ...
4
votes
3answers
2k views

Find files in the order of timestamp

dir has two regular files. file1 has abc\n, file2 has def\n. Compress these two files with gzip, as shown below, #ls #echo 'abc\n' > file1 #echo 'def\n' > file2 #gzip file1 #gzip file2 #ls ...
-1
votes
6answers
3k views

How can I compare two files line by line?

I have two files A and B which are almost same with some lines different and with some lines jumbled. Since the two files are systemverilog files the lines also contain special characters like ; , = + ...
2
votes
2answers
1k views

Concatenate file contents AND names

I've been writing for many months. The files I create are dated files named like 2011-06-13.markdown with daily content. I've decided I want to have all the writing in one file instead but I'd like ...
-1
votes
3answers
3k views

Find files less than 1 week old with match TODO in files

My unsuccessful proposal find ./ -newerct '1 week ago' -print | grep TODO No output although should be. Files are text files like Lorem % TODO check this out Lorem ipsun How can you find less ...
1
vote
4answers
3k views

Find a directory created today

How can I find a directory whose name starts with cy and that was created today?
0
votes
2answers
890 views

Find a file and execute a command in the file's directory

I am trying to use find so it would find a script file and if found execute it in the same directory it found it in. Something like this: find . -name "CLEAN" -execdir "CLEAN" {} \; except {} is ...
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. ...
26
votes
1answer
867 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?
2
votes
1answer
254 views

cp not evaluating dirname properly in find operation [duplicate]

I'm trying to create a script which will find files of a certain filename, copy a file to that file's location, and then delete the found file. Ignoring the delete part for now, this is what I have ...
0
votes
2answers
228 views

Find files greater than X value, sort by size, show in ls format

My assignment is: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format. This is what I execute: find /home/...
3
votes
3answers
390 views

Append to files

I have a directory full of files. My goal is to append text to the beginning of the file. The text that goes at the beginning is the same for each file. This is my attempt #!/bin/bash ...
2
votes
1answer
63 views

Extract the number of pages of PDFs recursively and dump them to a CSV

I need to get a list of PDFs in various sub-folders of a directory structure and the number of pages of each PDF file. All saved into a CSV file, i.e. <filename>,<number_of_pages>. I have ...
6
votes
1answer
219 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 ...
415
votes
6answers
660k views

How to run find -exec?

I'd like to find the files in the current directory that contain the text "chrome". $ find . -exec grep chrome find: missing argument to `-exec' What am I doing wrong?
7
votes
3answers
1k views

How to find total filesize grouped by extension

I work on a cluster shared with other colleagues. The hard disk is limited (and has been full on some occasions), so I clean up my part occasionally. I want to do this quickly, so until now I do this ...
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
4answers
66 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 ...
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
1answer
60 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
3answers
932 views

Why does find -inum iterate through the whole filesystem tree?

It surprises me to see find iterate/walk through the complete filesystem when I do a simple find -inum 12345 Without background info it seems to me that there should be much easier ways for to tell ...
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
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 ...