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

learn more… | top users | synonyms

0
votes
1answer
20 views

How to change date format and position in find output

Sorry if this a basic question. Say i have the following command. It's set to display a list of the last 20 files modified on my drive with the paths included. find -type f -printf '%TY-%Tm-%Td %TT ...
-4
votes
1answer
39 views

How to tell xargs to unpack tar into certain directory [on hold]

I wrote my first script which goes: find /media/temp/test -type f -printf '%T@ %p\n*.tar.gz' | sort -n | tail -1 | cut -f2- -d" " | xargs tar -xvpf I would like to find latest modified file which ...
2
votes
2answers
64 views

How to find a specific file and move it to a specific directory?

How to find a specific file, and move it to the specific directory /var/tmp? For example I want to find the file 0914_Jul-2014.gz. Remark, the file 0914_Jul-2014.gz, is under ~300 subdirectories: ...
3
votes
3answers
149 views

Using `find`, how can I get `rm` to print a fuller path name than it does when executed through `-execdir`?

Summary of Answers: while literature promotes "-execdir" as safer than "-exec", do not ignore the operational difference. The former is not a simple reimplementation of the latter. Also, when using ...
4
votes
2answers
107 views

Find and create empty files with the same name in another location

I want create empty files with the same name, but in another location. Is it possible? find some files use only filenames touch an empty file in another place Something like this: find . -type f ...
0
votes
1answer
59 views

bash: What is the difference between these two script variants?

(Note: Both of these examples may require GNU or BSD find and may not work as-is with the POSIX "edition" of find). Both of the scriptlets below must be understood as excerpts from way more complex ...
1
vote
1answer
27 views

In which directory is node running?

In trying to figure out how some application that listens on port 8088 is running, I see that it has PID 15020: $ netstat -ntulp Proto Recv-Q Send-Q Local Address Foreign Address ...
1
vote
1answer
27 views

Copy only files between two times [closed]

I'm trying to copy pictures taken between two times, from one directory to another. I’ve managed to list them using this command find /mnt -type f -name "*.jpg" -newermt "2014-12-14 01:00:00" ! ...
1
vote
1answer
20 views

How do I find/list all files on filesystem with a certain SELinux “fcontext”

I'm having trouble finding information on what command, presumably from setools, I should use to find all the files on my filesystem that are labeled by SELinux with a certain file-context (fcontext). ...
1
vote
1answer
45 views

Change file ownership recursively without errors

I am trying to write a script that fixes the ownership of all files owned by a specific user, after changing the user's UID. Currently, I run: chown -Rhc --from=${OLD_UID} ${NEW_UID} / chown -Rhc ...
2
votes
1answer
45 views

Find files older than x amount of time in specific directory with ignoring subdirectories

My setup is as following: folder structure dir |--correctfile1 |--correctfile2 |--correctfile3 |--subdir1 |--wrongfile1 |--wrongfile2 |--wrongfile3 |--subdir2 |--subdir3 I need to ...
0
votes
2answers
39 views

How to save stat of all files found in a search?

I had a cron which removes all files with a specific pattern from temp. find /tmp/* -type f -iname magick-* -exec rm {} \; Now, I want to log the stat of all files before deleting them for future ...
4
votes
2answers
228 views

How to quote arguments with xargs

Suppose that I want to delete all files in a folder that are greater than 1 MB. $ find . -size +1M | xargs -0 rm This will not delete files that have space in their names. So I want it to quote all ...
3
votes
1answer
36 views

How to find files/directories with specific ACL

How to I do something like find . -acl u:jim:rx find . -acl u:*:r find . -noacl u:jim:r etc. I know that the find command does not support this but, you have the idea. Are there any scripts, even ...
2
votes
3answers
143 views

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue

Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash). $ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \" The problem is the ...
2
votes
2answers
48 views

Deleting files older than a month [duplicate]

Need to delete all sub-directories which are a month old. But last day of the month data should be ignored for previous three months. The data representation is as follows: bkp_01102014 ...
0
votes
3answers
37 views

Cannot prompt user using rm bultin prompt option -i with xargs and find

I am using xargs and rm with find in order to remove files that follow a specific pattern defined by find as follows. touch file find . -name file | xargs rm Everything works fine with the above ...
2
votes
1answer
40 views

find command sometimes results in non-matching files being zipped

I'm trying to make a zip file of all the files in a specific directory which were modified in the last x minutes. Here's my command: find "/path/to/dir" -mmin -30 -not -name ".*" -exec zip -r ...
2
votes
1answer
38 views

Find Command: File Path vs -name Argument

I'm currently building a script to handle some files in a directory. In the first example, I use the find command and pass a directory in as the argument. In the second I instead use the -name switch ...
0
votes
1answer
42 views

How to find files which have been modified in the last 50 days? [duplicate]

How can I find all the files which have been modified 50 days before? I'm trying this: find -maxdepth 1 -mtime -50 is it the right command to find files that have been modified in the last 50 ...
2
votes
2answers
42 views

find and delete gives false status

I tried to execute delete as per many previous discussions occurred find & delete however my attempts lead to different experience. find . -type d -name "koko" -exec rm -rf {} \; deletes the ...
0
votes
2answers
49 views

linux + find command with rm -rf

why the following command removed the tmp directory under /var and how to avoid this? find /var/tmp -type d -ctime -1 -exec rm -rf {} \; pwd /var/tmp [root@linux /var/tmp]# find /var/tmp -type ...
1
vote
2answers
29 views

Find command with -ctime +0 for testing

The following command will delete directories and sub directories that are older then 100 days: find /var/tmp -type d -ctime +100 -exec rm -rf {} \; But actually I want to perform the test to ...
1
vote
3answers
46 views

Remove old directories according to directory's name?

In my bash script I create a directory each month for backups as follows: DAY=$(date -d "$D" '+%d') MONTH=$(date -d "$D" '+%m') YEAR=$(date -d "$D" '+%Y') mkdir -p /var/app/backup/$DAY$MONTH$YEAR ...
1
vote
2answers
32 views

How to limit the number of search results per directory

How to limit the number of search results per folder, for example: With this command: grep --include=*.php -Ril '<?' '/var/www/' I get the following: /var/www/test.php /var/www/test1.php ...
2
votes
1answer
31 views

'Tar' the result of a 'find', preserving the directory structure

I want to tar all the *.txt file, that I get from the result of a find, that exist into a directory having a tree like this: Directory_name dir1 file1.pdf file1.txt dir2 file2.pdf ...
2
votes
3answers
55 views

Find files that have a confirmed duplicate in same directory recursively

Say I have the following directory structure: root |-- dirA |-- file.jpg |-- file-001.jpg <-- dup |-- file2.jpg |-- file3.jpg |-- dirB |-- fileA.jpg |-- ...
0
votes
1answer
37 views

Issue finding lines using grep in UNIX [closed]

I am trying to use a .txt file with around 5000 patterns (spaced with a line) to search through another file of 18000 lines for any matches. So far I've tried every form of grep and awk I can find on ...
6
votes
4answers
304 views

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

find ~/ -name *test.txt find ~/ -name '*test.txt' Can anyone help me to construct an example where the first form fails but the second still works. And tell me the difference between them.Thanks!
1
vote
0answers
35 views

trash and restore script - issue restoring

#!/bin/bash echo "Are you sure you want to move this file to the Recycle Bin?" "(Yes/No)" read ans case "$ans" in Yes) echo "$(readlink -f $1)" >> "$HOME/TrashLog" && mv "$1" ...
0
votes
1answer
65 views

What does newermt mean in find command?

I know I can use this option to find file between particular modified times. But I'm curious about what does this mean? I used man find | grep newermt trying to find something. But I got no direct ...
0
votes
3answers
62 views

How to find a file in Unix using find command?

I have been trying to search for a file which contains a specific pattern. The pattern is itself in a variable tmpfl echo $tmpfl --> ack_2* Now to find for the file in the current working ...
1
vote
2answers
102 views

Sort files according to their extensions

I have made a script that will sort files according to their extension and place them in the proper folder. For example, place abc.jpg in the directory jpg. #!/bin/bash #this script sorts files ...
3
votes
6answers
95 views

How to show distinct directories on find?

I want to find all directories containing, for example, files named *.txt. but the output must not contain duplicates. How to do it?
-1
votes
3answers
44 views

How to print the base file name using find in Unix?

I have been trying to print out the base file names using find in Unix. To simply print out the file names the command I have been using is this find . -type f -name \*.out -print It prints out ...
2
votes
4answers
72 views

Find files that end with number

Im trying to make some backup script as the log files get bigger and bigger. What i have is coping the current file, (for example secure file in /var/log/) and remove the content from that file. But ...
2
votes
3answers
62 views

Remove files from listing that are created/modified on Saturday

I am not sure if it is possible. I do ls -l, it gives all the files in the current directory. Is there a way to say list only files that weren't created/modified on Saturday's with shell command?
2
votes
1answer
34 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
1
vote
1answer
31 views

Using double or no quotes with wildcards

I came across this article which attempts to explain the find command.It gives an example of find /tmp -iname "data*.txt" now this article here states that Double quotes do not suppress the ...
1
vote
2answers
62 views

Seaching a File in Unix for a given string and then another set of Strings within this file and print file properties too

I am using command to search for files staring from a given Directory in Unix , files ending *.sas and containing the string DB2. I then inturn want to search the resultant set of files for the ...
0
votes
1answer
28 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
1
vote
1answer
56 views

What does `{\} {}` mean in `find` command?

Please explain this command in detail. I am using this command to find large files above 6MB and split in to 5MB chunks in the same folder. Then it removes the original files (larger than 6MB) in the ...
0
votes
1answer
79 views

find - exec rm vs -delete

I'm trying to understand the difference between these two commands: sudo find / -name .DS_Store -delete and sudo find / -name ".DS_Store" -exec rm {} \; I noticed that the execmethod is ...
0
votes
4answers
45 views

Print only directories with more than 31 files

I am using this script to count files on my directory and sub-directories: for i in $(find . -type d) ; do printf "$i %s\t" ; ( find $i -type f | wc -l ) ; done This script works fine. What I ...
0
votes
1answer
22 views

Query for displaying UNIX files created on particular timestamp

I wish to list down all files which were created on particular time. (For ex: files created on time: Nov 13 09:09) -rw-r--r-- 1 bitt1 cerillio 43268 Nov 13 09:02 sendEsbUpdateEvents.log ...
3
votes
4answers
205 views

what is the difference between `find .` and /home/user/* as an input to for command

What is the difference between find . and /home/user/* as an input to for command.? For example: for var in $(find .) do echo "$var" done or for var in /home/user/* do echo "$var" done In the ...
1
vote
2answers
103 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
1
vote
1answer
32 views

Different results OS X/Linux with “find PATH -mount \( -type f -o -type d \) -print0 | LC_ALL=C sort --zero-terminated > OUTPUT.txt”

this command is part of a script I use for comparing files: find test/ -mount \( -type f -o -type d \) -print0 \ | LC_ALL=C sort --zero-terminated > OUTPUT.txt // test/ is the PATH ...
1
vote
2answers
58 views

how to I change permissions to all subdirectories except for 1 folder using a single find command?

I need to change the folder and file permissions in all subfolders except for 1 folder. Currently, I'm running several find/exec commands to make it work. e.g. find /mystuff/temp/videos -type d -exec ...
2
votes
2answers
49 views

How to pipe a the output of find to another find invocation

Here's what I'm trying to do find . -maxdepth 1 -type d -print0 | xargs -0 -P4 find -name 'war' -type d I would like to create a list of directory names, null-terminated, and then pass this list to ...