Questions tagged [find]
A commandline utility to find files and directories.
666
questions
305
votes
9
answers
1.3m
views
Find a file by name using command-line
I would like to determine the location of a file using command-line. I have tried:
find . -type f -name "postgis-2.0.0"
and
locate postgis-2.0.0
to no avail. What is the command to determine the ...
276
votes
10
answers
1.1m
views
How to list all symbolic links in a directory
I have a symbolic link in my /var/www/ directory that links to WordPress. When I run the command ls -la from the /var/www/ directory the link to WordPress doesn't show up. Is there a way to list all ...
206
votes
9
answers
381k
views
Find number of files in folder and sub folders?
I want to find the total count of the number of files under a folder and all its sub folders.
198
votes
11
answers
219k
views
How to exclude/ignore hidden files and directories in a wildcard-embedded "find" search?
Starting from (notice the wildcards before and after "some text")
find . -type f -name '*some text*'
how can one exclude/ignore all hidden files and directories?
I've already been googling for far ...
132
votes
2
answers
468k
views
Removing files older than 7 days
I write below command to delete all files that are older than 7 days, but it doesn't work:
find /media/bkfolder/ -mtime +7 -name'*.gz' -exec rm {} \;
How can I remove these files?
97
votes
10
answers
226k
views
Get absolute path of files using 'find' command
Is there a way to get absolute path of a file that is being searched?
For example:
find .. -name "filename"
It gives me results like ../filename but I want the full path.
What I need is to find in ...
93
votes
5
answers
67k
views
Find directories that DON'T contain a file
Yes, I'm sorting out my music. I've got everything arranged beautifully in the following mantra: /Artist/Album/Track - Artist - Title.ext and if one exists, the cover sits in /Artist/Album/cover.(jpg|...
85
votes
4
answers
331k
views
How to find a folder on my server with a certain name?
I have a directory somewhere on my server wth the name "exampledocs". I tried to find it's location using:
ls -d */ | grep -E 'exampledocs'
and
find * -regextype posix-extended \-regex '...
75
votes
2
answers
208k
views
How to find location of installed library
Background: I'm trying to build my program but first I need to set up libraries in NetBeans. My project is using GLU and therefore I installed libglu-dev. I didn't note the location where the ...
72
votes
9
answers
90k
views
How do you output the filename in find command while using -exec?
I use the following line to find all sub-directories of the PWD and run svnadmin verify on each directory (I already know that they're Subversion repositories)
find ./* -maxdepth 0 -exec svnadmin ...
60
votes
6
answers
197k
views
command to find files by searching only part of their names?
Say there are files with names:
batman.c
debate.c
cricketbat.c
What command and how should I use it to list all these files by using the searchtag bat?
60
votes
2
answers
63k
views
What does "{} \;" mean in the find command?
Sometimes I see the following command:
find . -name * -exec ls -a {} \;
I was asked to execute this.
What does {} \; mean here?
58
votes
10
answers
126k
views
Filenames with spaces breaking for loop, find command
I have a script which searches all files in multiple subfolders and archives to tar. My script is
for FILE in `find . -type f -name '*.*'`
do
if [[ ! -f archive.tar ]]; then
tar -cpf archive....
53
votes
6
answers
149k
views
Find the latest file by modified date
If I want to find the latest file (mtime) in a (big) directory containing subdirectories, how would I do it?
Lots of posts I've found suggest some variation of ls -lt | head (amusingly, many suggest ...
46
votes
3
answers
153k
views
How to find files between two dates using "find"?
I have an email account that has passed 60GB of emails, and currently I'm having a lot of trouble using an email client to archive emails of last year (2011).
Via terminal, I am trying to use find to ...
40
votes
4
answers
196k
views
how to find a word in text files from a directory [duplicate]
Suppose that I have a directory with name _file and includes two sub directory like _1 and _2 and on each one I have some text files. I want to search a word like foo in one of these text files. How I ...
38
votes
1
answer
5k
views
What is the difference between using '+' (plus) and ';' (semicolon) in -exec command?
I'm wondering to know that what difference is the between using + and ; at the end of -exec command when I use in find command?
find .... -exec ... \;
VS
find .... -exec ... +
36
votes
2
answers
72k
views
Sort files alphabetically before processing
I use the command
find . -type f -exec sha256sum {} \; > sha256SumOutput
to hash every file in a folder hierarchy. Unfortunately, sha256sum doesn't get the file names from find in alphabetical ...
35
votes
3
answers
45k
views
Piping find -name to xargs results in filenames with spaces not being passed to the command
Normally to remove files with spaces in their filename you would have to run:
$ rm "file name"
but if I want to remove multiple files, e.g.:
$ find . -name "*.txt" | xargs rm
This will not delete ...
35
votes
2
answers
9k
views
find vs. locate
There are the commands find and locate to search for files on the disk.
I know that find recursively processes all needed subdirectories to search files and therefore is slow but up-to-date, whereas ...
34
votes
3
answers
20k
views
How do I get mlocate to only index certain directories?
I'd like to use mlocate on my Ubuntu server, but only to index certain directories (e.g. /home and /data, but not everything under /). However, mlocate's standard configuration works the opposite way; ...
34
votes
3
answers
34k
views
Using grep with pipe and ampersand to filter errors from find
I am using cygwin to find a file on the cygdrive.
However I need to suppress the permission denied messages (otherwise the results get hidden in the error messages). The following command works:
...
34
votes
1
answer
36k
views
Get total diskspace usign du for multiple directories
I know about du -sh which gives me total disk space used for given directory.
My problem is the directories I am interested are scattered in lot of subdirectories. I have right "find" command that ...
26
votes
2
answers
34k
views
Find and delete all files without extensions witin a folder and its subfolders
I have a folder without around 500 subdirectories. There is a lot of trash to be found in it and I want to clean it up.
I have already deleted certain filetypes that I don't want, like images, with ...
25
votes
2
answers
6k
views
Did I just delete everything with find -exec mv?
I tried to figure this out on my own. Here's the command I used in the terminal:
find . -name "*.jpg" -exec mv {} pictures \;
I did not create a directory named pictures first. What happened was a ...
25
votes
1
answer
7k
views
Ubuntu 19.10: why is the "locate" command missing?
OS: Ubuntu 19.10
When I ran locate plymouth, I got
dkb@dkb-uee:~$ locate plymouth
Command 'locate' not found, but can be installed with:
sudo apt install mlocate
dkb@dkb-uee:~$
So I installed ...
23
votes
4
answers
49k
views
How can I find the location of an icon of a launcher in use?
I have a launcher on my desktop and want to add another one manually with the same icon.
When I go to the preferences of the existing launcher and click the icon, it doesn't take me to the folder ...
22
votes
4
answers
76k
views
Using locate to find a directory
I use locate all the time to find files that I know the name of, locate is very fast and I love that. For recently created files find is great, normally with recently created files I know where ...
22
votes
5
answers
13k
views
Why is using the '-execdir' action insecure for directory which is in the PATH?
Why is it insecure to use the combination of -execdir action of find while using -exec isn't?
When I'm running the below command I'm getting the following prompt message:
/path/to/currentDir/$ find ....
22
votes
4
answers
20k
views
How to find all images with a certain pixel size using command line?
I am trying to find all JPG images within a folder with subfolders that have either width or height below 300px.
This way I want to detect old thumbnails and delete them.
For sure I can find all ...
20
votes
5
answers
67k
views
Find files in linux and exclude specific directories
I have a find looking like this:
rm -f crush-all.js
find . -type f \( -name "*.js" ! -name "*-min*" ! -name "*console*" \) | while read line
do
cat "$line" >> crush-all.js
echo >> ...
20
votes
1
answer
62k
views
What does "paths must precede expression" mean when using find?
I want show all the files that have a .bak extension.
kaykav@ubu2:~/Documents$ ls
cdIndex1-60 met.bak tem.bak
I type the cmd : $ find . -name *.bak
I'm in the correct Directory for this. I get ...
19
votes
2
answers
2k
views
Why I can find *main.o but cannot *.o?
This one is correct:
$ find . -name *main.o
./main.o
So, why I can't find *.o?
$ find . -name *.o
find: paths must precede expression: main.o
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|...
19
votes
2
answers
32k
views
Count number of files in a folder per day
I can find number of all files in folder but I got pretty large number.
find . -type f | wc -l #find number of files in DIR
ls -lrt #list all files order by date
How to ...
19
votes
3
answers
4k
views
What does the asterisk and period do in find -name "*.mp3"?
In find -name "*.mp3", there is an asterisk before the .mp3. Doesn't the * match the character before it any number of times? But there is nothing in front of the asterisk, so what does the *...
18
votes
5
answers
13k
views
Recursively search a pattern/text only in the specified file name of a directory?
I have a directory (e.g., abc/def/efg) with many sub-directories (e.g.,: abc/def/efg/(1..300)). All of these sub-directories have a common file (e.g., file.txt). I want to search a string only in this ...
18
votes
4
answers
69k
views
How can I find world writable files and folders and set the sticky bit?
I want to do the following:
Need to find all world writable files and folders from / root.
If found, I need to check whether the sticky bit is set or not.
If the sticky bit is not set, then set it.
...
17
votes
4
answers
43k
views
How can I find all video files on my system?
I tried using the Unity Lens File search for *.* and filtering by Last Modified=All, Type=Videos, and Size=All, but found nothing, although I know there are some .3gp files in my Pictures folder. I ...
17
votes
2
answers
105k
views
Save the result of find as a variable in a shell script [duplicate]
I want to find the path to a file, and save that output to a variable in a shell script. Specifically, in the bash shell, if I write
GCC_VERSION="find *-gcc"
Then
echo ${GCC_VERSION}
Prints
...
17
votes
3
answers
8k
views
How do I find files with no group permissions?
I just want to know how I can find, in a folder, the files that have no group user permission (no read/write/execute) at all, using the terminal.
15
votes
8
answers
10k
views
How can I count files with a particular extension, and the directories they are in?
I want to know how many regular files have the extension .c in a large complex directory structure, and also how many directories these files are spread across. The output I want is just those two ...
15
votes
4
answers
5k
views
Delete empty subfolders, keep parent folder
When I use
find /home/user/parentdir -type d -empty -delete
it looks recursively for empty subfolders inside /home/user/parentdir and deletes them. But if /home/user/parentdir is also empty, it ...
15
votes
1
answer
3k
views
What's wrong with this 'find' command?
I am executing the following command (to find all files with .ts extension and deleting them):
find . -type f -name "*.ts" –delete
An error shows up:
find: paths must precede expression: `–delete'
...
15
votes
2
answers
2k
views
What's the missing argument to -exec?
I use the following command to clear a directory, of files and directories over 30 days old, and move them to an archive directory which I can delete after a few weeks if nobody asks for their files ...
15
votes
2
answers
5k
views
Find files based on permission
How can I find a list of files that have some specific permissions?
I want to find files owned by root user that have rwx permission for the owner.
Is there any way to find a list of such files? I ...
15
votes
1
answer
49k
views
How can I use find command more efficiently?
I wanted to know, what is the best way to use the find command efficiently?
I generally use, find [filename] [dir] which gives me a long list of file names none of them any way related to my search.
...
14
votes
5
answers
7k
views
How do I prevent a folder inside of /tmp from being cleaned up?
This question is about Ubuntu 14.10 on my developer laptop.
I've got a folder in /tmp that is used by an application to put temporary stuff in there. This application usually makes a temporary folder ...
14
votes
1
answer
51k
views
Find file or directory in whole directory structure
How can I find a file with a specific name in bash. I want to search through the whole system. I tried with find, but that only work through one level.
13
votes
3
answers
4k
views
How to combine the output of multiple `find` commands?
find -type f -name "*.avi" -exec md5sum {} + > checklist.chk
find -type f -name "*.mp4" -exec md5sum {} + > checklist.chk
How to combine these two commands?
Either by combining both search ...
13
votes
2
answers
9k
views
Why does the find command blow up in /run/?
I used the following command to check python versions as given by this answer. It does work except for one error, shown below. Can any one explain why?
$ sudo find / -type f -executable -iname '...