6
votes
1answer
262 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 ...
2
votes
3answers
39 views

Reference a path name in `find` output results

What I would like to do is to be able to reference a find path name result as a parameter to another command without laboriously typing the full path name. Example: $ find -name testfile path1 ...
1
vote
2answers
45 views

Find doesn't want to find *.sh in certain level [duplicate]

I have a problem with find. It doesn't find *.sh files if I am in certain directory level. It does, however, find *.sql files. /path$ cd do_not_upload/updates/1.1.1/ ...
0
votes
2answers
48 views

Find an archive and extract it in the directory where it is located

I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory ...
1
vote
1answer
31 views

How to delete older files in a folder in unix?

Can anyone help me find the meaning of the below statement? I am new to Unix programming. find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ \;
-4
votes
1answer
39 views

What is the significance of the the leading “4” before the listing of modified files?

After running the following command: find /Users/UserName/Documents -type f -mtime -1 -print0 | xargs -0 du -sk | sort -nr I receive the following output: 4 ...
3
votes
1answer
230 views

find files without extension

Let say I have: foo.txt bar baz.ooo If I use ls -1 !(*.*) then I'll get only bar on the output. Great, now I wish to have same results with find - some find -regex that will do the job. NOTE: ...
4
votes
3answers
117 views

zsh's “echo SomeText >> **/filename” in other shells

I need to fill all files with a specific filename (recursively) with a text. In zsh this can be done with echo SomeText > **/TheFileName I search generic solutions for sh-compatible and/or tcsh ...
0
votes
1answer
31 views

better use of find - rvm.sh

I am trying to find rvm.sh as I am receiving the infamous rvm is not a function error. The file in most linuxes is supposed to be at /etc/profile.d/rvm.sh However on opensuse it is not there so I ...
4
votes
1answer
119 views

Blank lines when executing “grep | xargs” in a “find -exec”

I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all). I've managed to get the list of blocking .htaccess but when I try to extract ...
1
vote
0answers
51 views

Why below script is not able to find and delete files [closed]

Why below find command does not find and delete files ? I am launching it like this ./script.sh 1 MYFOLDER days_period=$1 myuser=$(whoami) folder_prefix=$2 LOGS_DIR=~/$folder_prefix/logs if [ $# ...
2
votes
2answers
167 views

find the single largest file

We host a share of size 4 TB. How efficient is it to find a file with highest size. Usually we use: du -ak | sort -k1 -bn | tail -1 and it is not easy to scan through a share of such huge size and ...
2
votes
1answer
99 views

How to find text in files and only keep the respective matching lines using the terminal on OS X?

I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool for search files for specific text strings. I have a folder with many huge text files and ...
1
vote
3answers
783 views

How to display “human-readable” file sizes in find results?

I'm trying to find all large files on my Centos server. To do that I'm using: find / -maxdepth 10 -size +100000 -ls I tried changing -ls to -lsh but it is not allowed. How can I display these ...
1
vote
1answer
121 views

`tar` with `find` with removing original file extension

I want to create tb2 files from bunch of text files like this. tar cfj $(basename ./2014_04_09.txt .txt).tb2 $(basename ./2014_04_09.txt) With this command I can create a archive file 2014_04_09.tb2 ...
4
votes
1answer
2k views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
2
votes
7answers
653 views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...
2
votes
3answers
163 views

Count result in a find/exec statement

I have some Perl files which I have to modify through a simple sed call. Basically, I have to remove the first line of all of them. Currently, I managed to do this : find <PATH> -type f -name ...
4
votes
2answers
120 views

Find command returns wrong files

I'm trying to find files in a folder using find command which are a day older than the day on which the command is run.. I use the following command: FILES_dcn=($(find $dir_dcn -maxdepth 1 -type f ...
1
vote
3answers
226 views

Delete files with same name at the end of the file

Delete files with same name at the end of the file i have a lot of files in my folder and sub directories like ajax_hostel_room_master.php.php class_hostel_registration.php.php ...
3
votes
4answers
276 views

find -exec exit 1 \; Doesn't work neither does find -exec sh -c exit 1 \;

Using Enterprise Linux 5/6, Bash 4.x I want this type of logic: # IF temp file exists, exit because we are restarting already find /tmp/restarting_server -mmin -10 -exec exit 1 lsof -i TCP:1234 ...
4
votes
3answers
333 views

Search for specified keywords in files and copy to a new filename based on the keyword

I'm trying to create an .sh script where if any keyword is found in a file then copy that file to the directory /pathtofolder/keywords/$thefirstkeywordfound (overwrite the file if it already exists). ...
2
votes
1answer
169 views

How to find files that contain newline in filename?

I am trying to find files that have a newline in the filename. But I can't figure out what pattern to use. The following works, but is not very useful if I want to use it in indented code. find . ...
12
votes
3answers
523 views

Two find commands comparison

Recently I received this find one-liner, but I'm not able to explain where the difference of the below two comes from: Example 1 [root@centos share]# find . -exec grep -i "madis" {} /dev/null \; ...
-1
votes
4answers
88 views

Using 'find' to create text file, and later deleting files listed

I'm trying to use find to create a text file with the result. And then later be able to delete files, based on that list. I'm using find /volume1/video/ -iname "sample" to give me the results. How do ...
0
votes
2answers
120 views

Handling files with whitespace in their names

I have a lot of files that I need to sift through, specifically grep for certain keywords IN THE FILE, not he FILENAME. I have some 300+ files on a filesystem (so the files are within multiple ...
3
votes
2answers
396 views

Save find -exec output to text file

I have a set of videos in the folder. I would like to get the info about this videos using ffmpeg -i command and save the output to file. So I wrote the line: find . -type f -exec ffmpeg -i {} \; ...
2
votes
4answers
251 views

print parent directories full path of find output

what I want to do is to find all files based on some search query and get parents parent directory (../..) full path. For example find . -name "__openerp__.py" and then for each file execute ...
2
votes
4answers
202 views

Using a generated list of filenames as argument list — with spaces

I'm trying to invoke a script with a list of filenames collected by find. Nothing special, just someting like this: $ myscript `find . -name something.txt` The problem is that some of the pathnames ...
9
votes
3answers
2k views

identify files with non-ASCII or non-printable characters in file name

In a directory size 80GB with approx 700,000 files, there are some file names with non-English characters in the file name. Other than trawling through the file list laboriously is there: An easy ...
0
votes
1answer
182 views

How to escape spaces while using command's output in command line [duplicate]

I want to perform the following command in command line : $ md5sum $(find . -type f) But this would cause problems when it encounter files with spaces in filenames : md5sum: Kaufmann: No such ...
1
vote
2answers
85 views

visit all directories under version control

Is there a find incantation that would allow me to visit all directories under SVN version control? I am trying to use the execdir switch to add to the svn:ignore property in each one of these ...
4
votes
3answers
454 views

find with execdir

I run a find with execdir both I don't get the results I was expecting. SSCCE below: mkdir -p a/b/c find . -type d -execdir touch foo \; $ tree a a ├── b │   ├── c │   └── foo └── foo Directory c ...
2
votes
2answers
84 views

Pipeline with grep and find prints numbers infront of result

Am using the following "find" command to extract some files, find /lag/cnnf/ -maxdepth 3 -newer ./start ! -newer ./end | grep -nri abc | egrep '([^0-9]45[^0-9])' | grep -nri "db.tar.gz" >> ...
1
vote
3answers
166 views

Prevent wildcard expansion on find

Is there a way to prevent wildcard expansion on the find command so that the following would work? find . -iname "foo [bar]" As pointed out here, I tried running set -f, set -o noglob and setopt ...
4
votes
4answers
1k views

What is the most efficient way to move a large number of files that reside in a single directory?

CentOS 5.x I apologize if this is a repeat question. I've seen a lot of similar questions (regarding deleting files) but not exactly the same scenario. I have a directory containing hundreds of ...
4
votes
2answers
6k views

Remove all files created before a certain date

I have a directory containing a high number of files (like logs for every day of the year). I would like to remove all files created before let's say 22/11. How can I achieve that ? Must I use find ...
2
votes
2answers
91 views

What is the “initialization time” in the find command?

When I try to refer find command's man page , I come across -mmin n The value of n can be one of the following: n Evaluates as True if the file modification time ...
2
votes
4answers
218 views

Recursively apply a command to modify all files in a directory

I have a command that reads a file, and outputs a modified version on stdout: ./convert /path/to/file How can I recursively apply this command to all files in a directory, and overwrite the ...
1
vote
2answers
365 views

How to find certain files and move them to a new directory in the same command?

So I was looking around and all I have found is how to do this only if the directory is already made, which is this: find source -name '*.z' -exec cp {} destination \; But how can I make a new ...
2
votes
2answers
101 views

Filtering the result of the find command, so that it returns only directories

Is it possible to get only the results from find that are directory paths? Using find with some option, or using grep or some other utility the results are piped into as a filter? I thought something ...
1
vote
2answers
1k views

Find and move directories based on file type and date

I have a directory "New Movies" containing 200+ subdirectories "Movie Name (year)". The subdirectories "Movie Name (year)" contains a single video file (avi/mkv) and several related jpg/xml files. I ...
3
votes
1answer
595 views

find and rysnc?

I want to be able to search for files over 14 days and over 10k and than rsync those found files to a destination. Is there a way to combine these two commands? find ./ -mtime +14 -size +10k rsync ...
3
votes
3answers
475 views

How to find file/directory names that are the same, but with different capitalization/case?

How can I list the file/directory names in a directory recursively that are the same, but with different capitalization/case? ex.: INPUT (not the ls command, the directories): [user@localhost ...
0
votes
2answers
105 views

find command and tar

find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar -cvjf> So I ran this command and I can't find the file after it was done running (probably because I never named it?). The ...
0
votes
2answers
142 views

Why are there empty lines in the output of my command?: find ~/x/y/ | shuf > ~/Desktop/z.txt

As it turns out the reason for this problem was one filename with several newlines. (No idea how that happened.) find ~/x/y/ | shuf > ~/Desktop/z.txt This command works pretty much as expected ...
4
votes
4answers
134 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
2
votes
3answers
347 views

How to use arguments with 'find -exec'? [duplicate]

I'm trying to generate static html files for all php scripts inside dir: find . -name "*.php" -exec php {} > {}.html \; But it just dumps all results to {}.html. How to do it properly? And how ...
3
votes
1answer
81 views

find utility does not recognize bracket notation

I've two files in the current folder: submitWeb.m submit.m the following find does not show the two files: find . -regex .*submit\(Web\)?\.m But the above regex expression works fine in ...
3
votes
3answers
533 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...