Tag Info

Hot answers tagged

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 ...


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"


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. ...


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 \)


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 ...


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" ' {} \;


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 ...


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 ...


3

Use find for that: find . ! -name '.*' ! -type d -exec rm -- {} +


2

With zsh: vi ./**/*_test.mov(.s:_test.mov:_info.txt:)


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


2

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


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

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 ...


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.


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' {} \;


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 ...


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 ...


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


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 {} ...


1

Assuming your are on a Linux system, or at least that you have GNU touch and GNU date, you can do (in bash): $ shopt globstar $ for f in **; do touch -d "$(date -d "$(stat -c '%y' "$f") +3 months")" "$f" done That, however, will ignore hidden files. To match those as well, run shopt -s dotglob before the above commands. Explanation shopt -s ...


1

From the description of the problem I believe you are looking for the tool which can get time of last file modification and then add 3 months to it. You can do it with stat + touch + some shell arithmetic evaluation. For example to add 90 days to file timestamp you can write touch -d "@$(( $(stat -c '%Y' file) + 90*24*3600 ))" file Then just loop over all ...


1

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



Only top voted, non community-wiki answers of a minimum length are eligible