Tag Info

Hot answers tagged

8

Use the -perm test to find in combination with -not: find -type d -not -perm 775 -o -type f -not -perm 664 -perm 775 matches all files with permissions exactly equal to 775. -perm 664 does the same for 664. -not negates the test that follows, so it matches exactly the opposite of what it would have: in this case, all those files that don't have the ...


8

The pattern given to -name has to match the entire base filename. The behaviour of the -name pattern is defined as: The primary shall evaluate as true if the basename of the current pathname matches pattern This means it's true when the whole of the basename matches the pattern you gave. You can think of a pattern as being basically like a shell glob: ...


6

It's not related to find command itself, it's a feature of shell call history expansion. If your shell supports history expansion, you can refer to past command you typed and do some thing with it. Example in bash, your action refer to history command by event designator. From man bash: Event Designators An event designator is a reference to a ...


5

The man page for rmdir says:- Remove the DIRECTORY(ies), if they are empty. If you want to remove all empty directories then it will be safe. The question you need to ask is:- Do you want to remove all empty directories? Some applications need a directory even if it's empty. For example, journald can be configured so that it only logs to persistent ...


5

The ; has to be its own separate argument to find: find /home/shredtest/ -depth -exec /home/test.sh "{}" \; (note space between {} and \;). After -exec: All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. (from man find). That is, the argument has to consist entirely of ; to ...


5

Something like this should work: find . \( -iname "*.mp3" -o -iname "*.jpg" \) -printf '%TY%Tm%Td %TT %p\n' | sort -r This should find the files that (case-insensitively) find files ending with mp3 or jpg, print out the modification time, then sort it in reverse order. It seems to show both file-types when you run it effectively as two commands: ( find ...


4

With zsh: setopt extendedglob zmodload zsh/stat zstat -F %F +mtime -- **/(#i)*.(mp3|jpg)(Om[1]) Note that it's based on last modification time, the creation time (whatever that means) is generally not readily available on Linux. It doesn't consider hidden files. I you want them, add the D globbing qualifier above.


4

Once you hit a directory that's not executable, find tries to go into it, but it can't because, well, it's not executable. You need to tell it not to try by using -prune. And put that condition first, so it's not short-circuited. find . '(' '(' -not -executable ')' -and -type d -and -prune ')' -or \ '(' -not -readable ')' -or \ '(' -not ...


3

you could use: find . -type f ! -name "*.*" the ! negates the following expression, here a filename that contains a '.' you can also use the -maxdepth option to reduce the search depth.


3

The argument to -regex has to match the whole path that is found. A command like find . finds paths like ./dir/subdir/somefile, while a command like find ~/dir finds paths like /home/adam/dir/subdir/somefile. So your regexp has to match the /home/adam part at the beginning. The command find -E . -type f -regex '^\..*[^~]' finds files whose name doesn't ...


3

On Linux, there is no track of the creation time of a file. You can only access: the last modification time of the content (a creation counts as a modification of course), mtime, the last access time, atime, the last modification time of the meta-data, ctime. If you want to look for files with a test based on these times, find (man find) can help you. ...


2

I assume that your file names don't contain newlines. find /home/setefgge/public_html -type f -ctime -1 -exec ls -nls {} + | sort -k 10 Using + instead of ; to terminate the -exec action makes it faster by batching the invocations of ls. You can sort by piping through the sort command; tell it to start sorting at the 10th field (the first 9 are the ...


2

With GNU find, you can use -regex option: find . -type f -regex '.*\.\(c\|h\|cpp\)' -exec ls {} \;


2

Try adding the expressions into parentheses as stated in the man page: find . -type f \( -name '*.c' -or -name '*.h' -or -name '*.cpp' \) -exec ls {} \; should work.


2

Like this: find . -name '*.bor' -exec zip '{}.zip' '{}' ';'


2

Try this oneliner find /home/cde -ctime -1 -name "Sum*pdf*" | uuencode files.txt | mailx -s "subject" abc@gmail.com


2

AIX's find lacks the nice GNU features. You can work around this easily. Create two "reference" files with timestamps that mark the boundaries of interest: touch -amt 201407251200 myref1 touch -amt 201407251230 myref2 Now do: find . -type f \( -newer myref1 -a ! -newer myref2 \) -exec ls -ld {} + This references a file's mtime or modification time. ...


2

Also see the following: find . -type f -mtime -1 \( -name '*.mp3' -o -name '*.jpg' \) -printf '%AY-%Am-%Ad %P \n'


1

Argument of -name parameter in find command works exactly as wildcard characters in file/directory names in command line. * is any string and ? is any character.


1

To complement @JRFerguson's answer. To obtain a reference file whose modification time is 30 minutes in the past, you can do portably (precision of one second): TZ=ZZZ0 touch -t "$(TZ=ZZZ0:30 date +%Y%m%d%H%M.%S)" /some/ref/file And then do: find . -newer /some/ref/file That only works for intervals of 50 hours: TZ=ZZZ-24:59:59 touch -t ...


1

You should use -cmin. From man page of find, -cmin n File’s status was last changed n minutes ago. -ctime n File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpreta- tion of file status change times.


1

You can use mtime to do so: find . -mmin 30 #exactly 30 minutes old


1

In Linux, you can't get the created date of file. ctime is not created date. It changes when your file is updated content or metadata. In Mac OSX, you can use option -U: ls -tU So you can try: cd $(ls -tU parent/cv* | head -n 1)


1

Your issue is due to the fact that you've taken control of the formatting of the output generated by find, splitting on newlines now, \n. In order to get xargs to process your output when using -0 the output needs to be separated by null characters, \0. Here's an easy way to fix it though: $ find . -type f -printf "%C@ %p\n" | sort | tail -n 2 | \ cut ...


1

Either avoid -0 option with xargs, or use -print0. A snippet from the man page for xargs In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator. If ...


1

You can try to use find -D tree . [expr..] to understand what find does with your original command. You must understand that the -type f and also the -exec ls .. expressions are and'ed to the rest of the expressions with higher precedence than the ors. So your original command will get parsed into something like this: (-type f AND -name *.c) OR -name *.h OR ...


1

If I understand you right, you want to have the attachments have filename like Sum123.pdf instead of homecdeSum123.pdf. I assume the latter name is produced by your mail program that removes the slashes in the path name when saving. I think you should use a different way to call uuencode, removing the path name on the second parameter: find /home/cde ...


1

-type f will only find files, not directories. -maxdepth 0 will only ever find the directory you're searching in (.). You'll have to find the files you actually want to pass to rm. The standard way to do this is to exclude directories and all their contents like this (untested!): find . -mindepth 1 \( -name '*log*' -o -name 'crash-reports' -o -name ...


1

Try: find / -xdev -type f -size +100M It lists all files that has size bigger than 100M. If you want to know about directory, you can try ncdu. If you aren't running Linux, you may need to use -size +204800 or -size +104857600c, as the M suffix to mean megabytes isn't in POSIX. find / -xdev -type f -size +102400000c



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