Stack Exchange Network

Stack Exchange network consists of 174 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
votes
1answer
26 views

run grep and wc -l in multiple files in recursive manner

I have multiple fasta files I want to count the lines starting with ">" (no quotes). What I usually do is grep ">" file.fasta | wc -l This works for one file at the time. I'm trying different ...
1
vote
2answers
53 views

find: exclude n different directories and m different files present at any level but include few files from some excluded directories

I want to recursively find all directories and files inside a path but want to exclude some other directories and files that match given patterns. I then want to execute further commands on the search ...
2
votes
0answers
24 views

locate: using updatedb to create a database of directories only?

GNU findutils' man page for updatedb says it has a --findoptions parameter. Does it mean I can specify a find-like option there to create a specific database for locate? Like this, to include ...
1
vote
1answer
45 views

Linux grep for file starting with certain letter AND contain certain words

Trying to search a file directory for file names beginning with "h" and containing "enu"? So far this is what I've got, I just don't know how to handle both grep statements in one command line? find ...
1
vote
1answer
74 views

I want to find if a word exists in a file

I have a directory with some files. I want to know if a word exists in each file. $1 is my directory that I give it as a parameter e.g. ./myscript.sh /mnt/c/User/er/Desktop/shows I have written ...
0
votes
1answer
38 views

Creating text files in every sub-directory

I have a directory hierarchy named, for example, abc and a text file names.txt. I need to choose several lines from the text file and then create new files with sample text, say "Hello world", in ...
1
vote
2answers
41 views

search through all *.py files [duplicate]

I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py What is the best way to achieve this? I wanted to put 1 ...
-1
votes
1answer
28 views

How to search multiple files for a specific string one by one based on partial name

I'll try to explain my problem as best as I can, but please pardon my English .. What I'm trying to do, seemed simple enough to me, however every solution I've found so far just won't work. I wanna ...
3
votes
4answers
107 views

Search recursive for files that contains a specific combination of strings on the first line

I need to find all files that cointains in the first line the strings: "StockID" and "SellPrice". Here is are some exemples of files : 1.csv : StockID Dept Cat2 Cat4 Cat5 Cat6 Cat1 ...
0
votes
2answers
30 views

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

I am extremely confused, since a command I'm rather confident in, returns something completely different than I imagine! My assignment is simple: Find files (in a specific directory that is given) , ...
0
votes
1answer
58 views

Is this bash argument substitution?

While studying bash process substitution, I found this: counter=0 while IFS= read -rN1 _; do ((counter++)) done < <(find /etc -printf ' ') echo "$counter files" If I understand correctly,...
1
vote
1answer
46 views

How to rename a file to have the same name and extension as another file in same directory [closed]

I am trying to use the find command to edit files named "msf.txt" in many different sub-directories and I want it to take the same filename and extension as whatever file shares the same extension in ...
0
votes
1answer
26 views

How can I use command expansion on `\{\}` in `find -exec`?

I would like to find some directories via find /path/to/a/dir -type d -links 2 and then for each pathname found by find, assumed to be stored in variable pathname, I would like to stow -d "$(...
-1
votes
3answers
25 views

The most recent files in directory with a specific format in each one

I would like to have in a variable the most recent file with a specific format. exemple : in /home/test, 5 files : file_test_hadoop_20181130.csv (This is the last modified one for hadoop file) ...
0
votes
1answer
41 views

Bash - Find - move files bigger than certain size

How can I move all files bigger than lets say 10MB into a different folder? -rw-r--r-- 1 nath nath 4,3M Apr 21 2018 "file1.mp3" -rw-r--r-- 1 nath nath 1,7M Jun 10 2017 'file2.mp3' -rw-r--r-- 1 nath ...
0
votes
2answers
51 views

Rename Files to Same Filename Without Extension with find Command

I'd like to rename a group of files to their same filename but without extension. They are scattered in my home directory and I don't know where they are located precisely, but I do know the extension ...
0
votes
3answers
52 views

find log files recursively and print “INVALID” if no log found (bash)

I have ~750 log directories I need to search for the latest log file available: These are captured by the allLogs.txt file and each entry contains a wild card '*' so that ONLY the log with the latest ...
0
votes
2answers
71 views

Why doesn't grep remove lines of terminal output from find command by default? [duplicate]

I am constantly frustrated by this simple command: find / | fgrep somestuff.ext When I don't use sudo, I get line after line of permission denied - which is fair enough, but why isn't this output ...
0
votes
1answer
25 views

Problem with find excluding files of type socket when creating tar archive

I am trying to make a tar archive of all files in my /var directory. Naturally, I want to exclude the Unix sockets in there. So I try a command that looks something like: sudo find /var \! -type s ...
8
votes
3answers
301 views

How to find files by file type?

I know I can find files using find: find . -type f -name 'sunrise'. Example result: ./sunrise ./events/sunrise ./astronomy/sunrise ./schedule/sunrise I also know that I can determine the file type ...
0
votes
1answer
22 views

find and replace a substring and change to uppercase

I think it's best done with an example Contents of my file name="apple" parameter1="value1" parameter2="value2"; name="orange" parameter1="value1" parameter2="value2"; name="tea" parameter1="value1" ...
0
votes
2answers
36 views

Are `-name` and `-exec` options or non-option arguments of `find`?

Are -name and -exec options or non-option arguments of find? They look like short options, and they are called find expressions, if I am not mistaken. For example, find . -name "*.txt" -exec echo {} ...
0
votes
2answers
34 views

Excluding Bash File from modifying itself

I'm learning how to make script "fool-proof". I have some scripts that modify files in the current folder but they also modify the script itself. I know it all boils down to the "for" loop with "find" ...
4
votes
2answers
312 views

find -exec {} + argument list limit

I know that when the maximum argument list size is reached, xargs keeps creating new lists until all of the files are included; but does find -exec <command> {} + do the same thing or will it ...
-3
votes
1answer
33 views

Gnu/Linux: Listing files, with certain characters in the file-name, while in a different directory

How do I list all files and directories in the /etc/ directory, which have one or more digits in its file-name, and save the output to a file, in the home directory. The output must have the full ...
1
vote
1answer
49 views

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

apologies for the fairly trivial question but I am a linux beginner. 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 ...
0
votes
1answer
42 views

Combining if/else with variables in find command in bash script

I am writing a script that prompts for user inputs and then runs a find command. What I have works, but it feels like I have a lot of duplicated code due to the if / else structure. Is it possible ...
0
votes
2answers
34 views

size of file bash [closed]

i have to show size of all files .conf which are in /etc and redirect size output to a file.txt but i want to add to my command a flag which set a limit of redirected output my command is: find /etc ...
-1
votes
2answers
50 views

Recursively find ONLY the latest logs in all sub-folders and save to file

I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'...
0
votes
1answer
40 views

Eliminating multiple-extension file names from find output

I need to find the size of all files in /etc with the .conf extension. I tried to do this with find /etc -type f -name "*.conf" -exec du -chB1 {} +, but find gave me .conf files that have two or three ...
7
votes
5answers
687 views

find exec '{}' not available after >

Exec allows us to either pass all arguments at once with {} + or to pass them one by one with {} \; Now let's say I want to rename all jpeg, no problem doing this: find . \( -name '*.jpg' -o -name '*...
1
vote
2answers
105 views

How does the find command know how many arguments to feed with “-exec … {} +”?

In a command like this: find /data ! -type d -exec rm -f {} + the + is for batch execution of rm -f. find should batch as many arguments as possible. But how does it know the limit?
-1
votes
2answers
35 views

find files and move them to another folder with -exec

I tried to find files and move them to another folder $ find ~ -iregex ".*cheat.*\.pdf" -exec mv "{}" cheatSheet + find: missing argument to `-exec' However, the test works find ~ -iregex ".*cheat.*...
0
votes
1answer
27 views

Distinguish a command not a native second transmitter

suppose [root@iz2ze9wve43n2nyuvmsfx5z /]# find . -maxdepth 2 -type d | ls bin dev home lib64 media opt root sbin sys usr boot etc lib lost+found mnt proc run srv tmp ...
1
vote
2answers
74 views

What is the history behind the name of the xdev option in find?

I find the name of the xdev option counterintuitive. For me it seems like the abbreviation of 'cross device (search)'. However it does the opposite, it restricts the search to a single file system. ...
0
votes
2answers
36 views

for loop is pending not to execute

I tried to find all the lines containing word heaq in *.md file $ for i in $(find . -regex ".*md$"); do grep -i "heaq"; done #pending #pending However, it constantly pending there. What's the ...
-1
votes
1answer
43 views

Find files in specific directories

I have a college exercise which is "Find all files which name ends in ".xls" of a directory and sub-directories that have the word "SCHEDULE", without using pipes and using only some of the commands ...
3
votes
1answer
265 views

Finding a string in a file on a file system using Grep

I need to do a search on a number of files in a file system to look for a string "RUSH2112". I have completed the following command however I am not sure if this is correct. I stand in the mounted ...
0
votes
2answers
39 views

Find the longest file name

I have to find the symbolic link which contains the longest folder name in a folder full of symbolic links. So far I have this: find <folder> -type l -printf "%l\n" I was wondering if there's ...
-1
votes
3answers
32 views

Formatting the display of all files in directory and subdirectories

I want to display all files in directory and subdirectory between the bytesize 30000 and 50000. I want to display my files the following way: file1.xxx md5sum bytesize file2.xxx md5sum ...
0
votes
1answer
44 views

How to find the filename without path?

Currently, I have a function to find the filename, size and type; however, it includes the path as well, which I don't really need. find . -type f -exec stat --format="%n %s %F" which returns ...
0
votes
1answer
30 views

combine find statements

How can i combine both of the below commands? I want to get a single file with the owner and the size of the files find /test -type f -size +$(df -k /test| awk 'NR == 3 { printf "%d", $1/4 }') -exec ...
1
vote
2answers
47 views

Recursively delete empty directories with a dotfile / directory exclusion?

How do I recursively delete all directories which do not contain any files and make an exclusion of hidden directories? A lot of the directories that I wish to delete contain hidden directories (dot ...
1
vote
2answers
70 views

Sort the files by size retrieved from a series of folders

I retrieved all the pdfs in $HOME directory $ find -E ~ -regex ".*/[^/].*.pdf" It print more than 1000 files; I intent to sort them by size and searched $ stat -f '%z' draft.sh 184 I drafts the ...
1
vote
2answers
70 views

Create hardlinks instead of copying files with rsync

The following command finds recursively all files containing foo (but not bar) and preserves the directory structure in the target directory, for example if I have /path/to/2017/foo.ps and /path/to/...
0
votes
1answer
45 views

Use small script inside another On AIX, or a solution in a single command

I want put on a small script (perl-script.pl) inside another in order to use use it with a find command, like this: #Saving the previous permission information for a possible recovery. case "$STAND" ...
1
vote
2answers
64 views

Removing digits from beginning of filename [duplicate]

I was hoping this would work: $ find . -type f -exec basename {} \; | while EFS= read -r f; do echo "${f##[0-9]}"; done But, for example, for files named as: 1foo 11bar it returns: foo ...
1
vote
1answer
56 views

How to use istat on AIX like stat on Linux distributions

In Linux, I use the following command to show this output: find /backup/$INSTANCE/tsm/* -exec echo '"{}" ' \; | xargs stat --printf "chown %U:%G '%n'\nchmod %a '%n'\n" >> /tmp/permissions.txt ...
1
vote
1answer
34 views

How to search for a folder or file in parent folders [duplicate]

I tried to search for a folder in its parent folders instead of its child sub-folders (usually any search bash command will do). I need to know whether any reverse alternative for any search commands ...
3
votes
5answers
333 views

Find command if filename doesn't exists in directory

How I want to display the folder that do not have certain file. But the concern is, the file is same name but different cases. Case study: In tools directory, there are subdirectories that contain ...