Tag Info

Hot answers tagged

23

Bad Things ® ™. It's (almost) the equivalent of sudo rm -rf / - it will, as root, find all files or directories starting from / and recursively descending from there, and then execute the rm command against each file/directory it finds. It won't actually delete directory entries as there's no -f or -r options passed to rm, but it will remove all ...


10

Use this with bash: find $1 -name "* *.xml" -type f -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done find will search for files with a space in the name. The filenames will be printed with a nullbyte (-print0) as delimiter to also cope with special filenames. Then the read builtin reads the filenames delimited by the nullbyte and ...


8

Using rename find . -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; or with $1 find "$1" -type f -name "* *.xml" -exec rename "s/\s/_/g" {} \; Using mv find . -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \; or with $1 find "$1" -type f -name "* *.xml" -exec bash -c 'mv "$0" "${0// /_}"' {} \;


7

Don't run it. This will find everything (all files, directories, links, sockets etc) under / i.e. everything in the system and then it will try to remove those one at a time with rm. Note that as there is no -r option with rm, only the directory entries will not be removed, everything else will be gone.


6

You can group and use logical operators with find, but you have to escape the parens so you could look for all files and links like find \( -type f -o -type l \) <other filters> so if you wanted all files and links whose name starts with t you could do find \( -type f -o -type l \) -name 't*' You only need the parens if you want to group things ...


6

Here is a portable way: find / -type d -exec test {} = /zones \; -prune -o -type d -print Note that GNU find might be available on an alternate directory depending on the Solaris release you are using (like /usr/sfw/bin/gfind, /usr/gnu/bin/find, ...).


6

find will set its return code to non-zero if it saw an error. So you can do: if ! find ... then echo had an error >&2 fi | while ... (I'm not sure what you want to do with the find output). To collect all the error messages from find on stderr (file descriptor 2) you can redirect 2 to a file. Eg: if ! find ... 2>/tmp/errors then ...


5

POSIXly: find /test/. ! -name . -type d -mtime +0 -exec rm -rf {} \; -prune (we use -prune for the directories that we successfully remove so that find doesn't complain that they're suddenly gone). In any case, note that the modification time (as checked by -mtime above) of a directory file only reflects the last time an entry was added, removed or ...


5

Here is a POSIX way to prune any non readable directory with find : find . \( -exec sh -c ' if [ ! -r "$1" ] ; then { exit 1 ; } ; else for i in "$1"/* ; do if [ -d "$i" -a ! -r "$i" ]; then exit 1; fi; done; fi ' sh {} \; -o -prune \) -a -print Note that if this is a full Solaris installation, GNU grep is available in /usr/sfw/bin/ggrep.


5

The solution that works with any POSIX compatible find is the following: find DIR -type f -perm -0755 ! -perm 0755 ! -perm -04000 ! -perm -02000 -print As previously noted, with GNU find you can collapse the setuid and setgid tests into ! -perm /06000.


4

You're showing us the output of find . -maxdepth 1 -mtime -3 -print0 What's the output of find . -maxdepth 1 -mtime -3 -print0 | grep -z loader ?  I don't see any file names containing the word loader in the output that you did show.  If the output from the grep (which is the input to xargs) is nothing, then, naturally, nothing will be copied. Also, ...


4

The simplest method is to use awk's output redirection. Awk output redirection is very easy to use in simple cases: the file is opened the first time a redirection is used, and subsequent redirections to the same file name use the existing file descriptor. If you wanted to add a suffix to the file name, it would be as easy as find -type f -iname "*.txt" ...


3

You don't need .* with find and the space between . and * is often a mistake, since the * will expand to every entry in the current directory, and tell find to use that as a path to search. That's also why your other find sometimes shows files twice. If the j$(pwd) actually matches a file it will also be matched by *. So your delete one will probably do ...


3

You can run bash inside find with -exec option and run file inside shell, e.g.: find . -type f -execdir bash -c 'file "$0" | grep -q Matroska && rm "$0"' {} \;


3

I like to answer the direct question first, but do not run this before reading to the end of my answer. The command you are asking for (which may not be what you want) is: find /wherever -type f -name '*.log' -size +4096 -print \ | xargs truncate --size 0 Note that the +4096 means files with more than 4096 512-byte sectors. The problem is that if ...


3

I'm not sure I understand what you want, but, based on my best guess, find (starting_directory) -type f -perm -755 ! -perm 755 ! -perm /6000 would seem to do it.  -perm /mode means "Any of the permission bits mode are set for the file."  So -perm /6000 should match only files that are SUID or SGID (or both), and ! -perm /6000 should exclude those ...


3

Simple! This command will remove all files in your server. Don't run it!


3

It should be more like: find /home/backup/VBtest/ -name '*.sql.gz' -mtime +5 # -exec rm {} \; (remove the # from the exec part if this gives the correct results) This will scan the whole directory tree. /home/backup/VBtest/*.sql.gz by itself would get expanded by the shell (almost equivalent to the above find command with -maxdepth 1) as you can learn ...


2

Use this: find -name "* *" -print0 | sort -rz | \ while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f// /_}")"; done find will search for files and folders with a space in the name. This will be printed (-print0) with nullbytes as delimiters to cope with special filenames too. The sort -rz reverses the file order, so that the deepest ...


2

To make grep print only the file name, pass the -l option. To search for a substring rather than a regular expression, pass the -F option. To search recursively for files whose name matches a certain pattern, use find with the -type f and -name PATTERN primaries. Use -exec to invoke grep. find . -name '*.sas' -type f -exec grep -F -l 'Carhart' {} + If ...


2

This should do it. Where the first column (size) exceeds 10gb, output the second column (directory name) du -sk * | awk '$1 > 10485760 { print $2 }' Or as requested, to show in human readable form, as below. The regular expression ensures column 1 ends in a G (gigabytes) and the substr part strips the final letter from column 1 and looks to see if ...


2

As @meuh said in his comment, you could use /test/* instead of /test. Your command could then look similar to this: find /test/* -type d -mmin +1440 | xargs rm -rf In this case only the subfolders of /test would be removed.


2

-exec indeed can be used as a predicate. find(1): Execute command; true if 0 status is returned. So this example would be: find . -type f -exec sh -c 'file "$0" | grep -q Matroska' '{}' ';' -and -delete Obviously, instead of -delete there can be -ls or -print0 or more predicates.


2

You can do this by a find command: for i in $(find . -type f -size +2097152c);do cat /dev/null > $i;done The find command find . -type f -size +2097152c will find all files of size greater than 2MB (2097152 bytes) The for loop will loop into the list of the files it got in the find command and will clean them out with a cat /dev/null ...


2

-mtime +90 should do the trick.


2

for exactly 90 it should be -mtim +89


2

From man find +n for greater than n, -n for less than n, n for exactly n. -mtime n File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. So the correct line to backup files modified more than 90 days ago, will be $ find /path/to/files ...


2

From find's man page: Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n. -mtime n File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. ...


1

Well, the -mmin primary is a GNUism that is most likely not supported on AIX as it is a silly expansion compared to what the BSD people and I used as extension in the 1980s already. Given the fact that sfind compiles fine on AIX, I recommend: sfind . -mindepth 1 -type d -mtime +24h -exec rm -rf {} + The code is in schilytools at: ...


1

Use the -path option for this case: find / -type d -path '*/aaa/bbb' From the man page for find: File name matches shell pattern pattern. The metacharacters do not treat / or . specially; so, for example, find . -path "./sr*sc" will print an entry for a directory called `./src/misc' (if one exists). Cross-Platform Compatibility Edit: I ...



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