Tag Info

New answers tagged

2

The modification time of a directory, like any other file (note how directories are called directories (a list of name/number mappings like a phone directory) and not folders) is updated whenever the content is modified. That is when a file is added (linked), removed (unlinked), or renamed in it. Beware that files can be linked to several directories. The ...


3

I would use find <PARENT_DIR> -type f -mtime 1 With 1 the time of last modification in days (you can prefix it with - or + to indicate "less than X days" or "more than X days") : so, if you want the the file modified in the last 3 days, you'll do -mtime -3


1

As the other answer states, there is no simple task to do that. You have to search the whole filesystem. Here is an approach: find / -type l -ls 2>/dev/null | grep -P " -> .*HORCM$" It uses find to search all links, then prints them in a form like ls -dils. At the end, the complete output is grepped for the folder you search. It may take a while to ...


0

There's no way of knowing what symbolic links exist that point to a particular directory or whatever, besides simply searching through the entire filesystem for symbolic links and checking what those links point to.


2

First, your snippet executes the command echo {} : ;if [ -f {} ]; then echo file; else echo directory;fi because it needs its output to evaluate the command substitution. Since there is no file named {}, this produces the output {} : directory Then the find command is executed with the arguments -exec, echo, {}, :, directory, so for every file, it ...


1

If I correctly understood the question this can be done quite simply with find . -mtime +5 -exec bash -c 'echo "${0%/*}"' {} \; | sort | uniq


1

I believe that this will do what you need. It looks through each directory in turn and checks that there are no "recently modified" files. find * -type d | while read DIR do LINES=$(find "$DIR" -maxdepth 1 -type f -mtime -5 -print -quit) test -z "$LINES" && echo "$DIR NOT RECENTLY MODIFIED" done If the find ... ...


1

find . -type f | grep "keyword" * search in current directory. To lookup from root, specify / instead of .


2

go for this one: find . -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-02 00:00:00" m The modification time of the file reference t reference is interpreted directly as a time


0

find has some mandatory param: find PATH type_of_seach arg find / -mtime -10 -mtime +4 find has + and - operartor, Also *time : mtime, atime and ctime : atime == Acccess Time mtime == Modified Time ctime == Create Time ...


-1

I think you can do it with below: find ./* -mtime -10 -mtime +4 -ls


4

You could use find + file and output the name of the files that have mime type image/jpeg: find . -type f -exec sh -c 'file --mime-type "$0" | grep -q image/jpeg && echo "$0"' {} \; or find . -type f -exec sh -c ' mt=$(file --brief --mime-type "$0") [ -z "${mt#image/jpeg}" ] && printf "$0\n" ' {} \;


6

As a start, you could print out files with a .jpg file extension with: sudo find / -name *.jpg -print See how that behaves, modify to suit, and you can then pipe the output into another function rather than just printout if you'd like. edit As mentioned in the comments below, this may be a better starting point for you: sudo find / -iname "*.jpg"


1

Information about O_NOFOLLOW is given in the info page of find: 9.2.1.1 O_NOFOLLOW .................. If your system supports the O_NOFOLLOW flag (1) to the open(2)' system call,find' uses it when safely changing directory. The target directory is first opened and then find' changes working directory with thefchdir()' system call. This ...


3

This is a complete answer derived from the answers of Ketan and daniel kullman, as well as my own research. Most of the "features" turn out to be query optimizations, since find is in general capable of (almost) arbitrarily complex queries on the filesystem. D_TYPE The presence of the D_TYPE feature means that find was compiled with support for the ...


0

When looking through the findutils source tree (http://git.savannah.gnu.org/cgit/findutils.git/tree/), I found the following: configure.ac: --enable-d_type-optimization,Make use of the file type data returned in struct dirent.d_type by readdir()), m4/withfts.m4: --without-fts Use an older mechanism for searching the filesystem, instead of using fts() I ...


1

You can do this with nested find calls: $ find ~ -type d -name bin -exec find '{}' -type f ';' Since I'm replacing an ls call, perhaps you did not want more than one level of listing in the second find call. In that case, add -maxdepth 1 after -type f above.


4

With -path, you could try: find ~ -path '*/bin/*' -type f This won't list bin itself, so to get both: find ~ \( -path '*/bin/*' -type f \) -o \( -name bin -type d \)


1

You can use -exec to create a new bash shell, then manipulate {} inside the shell by passing it as a parameter (it can be accessed as $0 in the new shell). You can remove the .md filetype ending with parameter expansion: find . -name '*.md' -type f -exec bash -c 'pandoc --filter ./filter1.py -o ${0%md}html' {} \;


2

It will work. For example consider a .txt file in a current directory find . -type f -iname "*.txt" -exec basename \{\} .txt \;


3

I would use while loop: i=1 find / -name 'HAHA' -print0 | while read -d '' -r file; do mv "$file" "/home/${file##.*/}$((i++))"; done Important here is print0 option of find which (together with -d '' option of read) treats properly files with white spaces in their names. If you need to do such operation only once then first line which sets i=1 is not ...


4

I found a simple solution with a small script. The script is called cpf (or whatever name you give it) and is as follows: #!/bin/bash dir=xyz # Directory where you want the files num=1 for file in "$@" do base=`basename -- "$file"` mv -- "$file" "$dir/$base.$num" num=$(($num+1)) done You execute the command as follows: find . -name ...


9

I can think of two possible solutions: If you have installed mv from GNU coreutils (which probably is the case), then the following command... find / -name "HAHA" -type f -exec mv --backup=numbered "{}" /home \; ...will move all files called HAHA to /home. The --backup=numbered option of mv ensures that every time the mv command executes, it will check ...


0

Most systems have a locate database which is updated every night. This does a find over the whole system and stores the result in an optimized database. In this case locate mysql-connector-java should have given an answer quicker than the find solution. Note that locate will only show files that are findable by every user, so files in protected directories ...


0

find / -mount -name '*mysql-connector-java*' -print the -mount predicate is so that find skips searching virtual filesystems like /proc and /sys (useless to search) and other things that might be mounted like network-mounted filesystems (which could make it really slow!), but you can omit it if you want to search absolutely everything.


-2

grep -rli trim \` find . -name *.q \` Give you the list of .q files contains the keyword trim


1

find path-to-base-dir -maxdepth 1 \ -type d ! -name bunch-of-exceptions \ -mtime +7 -exec rm -rf {} \; -print You did not include path-to-base-dir in the bunch-of-exceptions. (You included . but that would only match if path-to-base-dir was exactly .) The only condition that the directory path-to-base-dir might fail if -mtime +7. If the ...


0

Put those [dir1] strings in quotes, otherwise the shell will try to expand them because of the brackets, which may or may not succeed according to the contents of your current working directory.


1

According to man find, juxtaposition (which is an implied "and" operator) takes precendence over the -or operator, so one might expect the arguments to be evaluated like so: ( -name '.amandahosts' -or -uid 11 ) and ( -exec ls -ld {} + ) In fact, if I add the parens to the find command, it works as expected: [pitserver ~]% sudo find ...


0

Read the find manpage's description of -cnewer -cnewer file File's status was last changed more recently than file was modified. Emphasis mine. All of the files were modified before 22:00 and were changed after 22:00, so they were all changed after any one of them was modified. Thus they are all listed. So the result seems correct. Whether that ...


-1

I would use perl, it is faster and more efficient for this than find + rm 0,30 * * * * cd /var/www/magento/var/session && /usr/bin/perl -e 'for(<sess_*>){((stat)[9]<(unlink))}' Deleting my log directory with over 500,000 logs in it daily clears it out in under ~6 minutes.


0

If the only thing in that directory is sess_* files, you can just leave out the -name 'sess_*', and find will traverse through anyway. Test what it would match by removing the -exec part. $ /usr/bin/find /var/www/magento/var/session -type f -mtime +1 Then for the cron job, 0,30 * * * * /usr/bin/find /var/www/magento/var/session -type f -mtime +1 -exec rm ...


1

Don't bother exec'ing rm at all, find can handle it: 0,30 * * * * /usr/bin/find /var/www/magento/var/session -name 'sess_*' -type f -mtime +1 -delete


5

Use bash arrays: pa=("/home/user/folder1" "/home/user/fol der2") find "${pa[@]}" -name '*xy*' ... Discussion Observe that the \ does not do what one hopes: $ pa="/home/user/folder1 /home/user/fol\ der2" $ printf '%s\n' $pa /home/user/folder1 /home/user/fol\ der2 The \ in the definition of pa becomes a literal character in the string, not an escape. ...


0

Use an array variable and put one path value in each element of the array. If that really isn't possible, another approach would be to use something other than space as your item separator. p[0]="hello" p[1]="happy" p[2]="world" echo "p[0]=${p[0]}, p[1]=${p[1]}, p[2]=${p[2]}" for p in "${p[@]}" do echo "p=$p." done Etc.


1

This is simple: find ~/ -mtime -3 -exec cat {} + | wc -c The above sends counts each character in each file to wc which counts them. If the files are big, the above would involve of a lot of reading from disk. If would be much more efficient to simply add the sizes of the files. Methods for getting the size of a file vary among Unix versions. If your ...


1

With find, cat and wc: find ~ -type f -mtime -3 -exec cat {} + | wc -c -mtime checks for modification times. Depending on your OS and filesystem, the creation time is not easy to get. Modification time is a reasonable compromise. -3 means less than 3 days (as opposed to +3). Actually, 72 hours. -type f - restricting ourselves to regular files. -exec cat ...


1

Try this find ./ -type f -mtime -3 -exec wc -c {} \; | perl -lane 'BEGIN {$total=0}; $total+=$F[0]; END {print $total}' Examples ❮njia@mb-125:~/src/ansible/roles❯➤ find ./ -type f -mtime -3 -exec wc -c {} \; 12288 ./base/tasks/.check_glibc.yml.swp 185 ./base/tasks/check_glibc.yml ❮njia@mb-125:~/src/ansible/roles❯➤ find ./ -type f -mtime -3 -exec wc -c {} ...



Top 50 recent answers are included