find

Linux removing folders older than 1 year and more than 3 files

▼魔方 西西 提交于 2019-12-17 10:00:50
问题 I'm writing an ant script to clean up an archive folder Here's how I need to clean it up: I need to delete folders old than a certain amount of days AND has more than 3 files in it. So for example if a folder is 300 days old but only has 3 files than it will NOT be deleted. I know I can ssh into the archive and do find -mtime +365 -exec rm -rf {} ;\ to delete files older than 1 year but I don't know how to account for the minimum of 3 files I also know that find -type f | wc -l will list the

git find fat commit

天涯浪子 提交于 2019-12-17 08:56:31
问题 Is it possible to get info about how much space is wasted by changes in every commit — so I can find commits which added big files or a lot of files. This is all to try to reduce git repo size (rebasing and maybe filtering commits) 回答1: You could do this: git ls-tree -r -t -l --full-name HEAD | sort -n -k 4 This will show the largest files at the bottom (fourth column is the file (blob) size. If you need to look at different branches you'll want to change HEAD to those branch names. Or, put

find filenames NOT ending in specific extensions on Unix?

∥☆過路亽.° 提交于 2019-12-17 08:03:39
问题 Is there a simple way to recursively find all files in a directory hierarchy, that do not end in a list of extensions? E.g. all files that are not *.dll or *.exe UNIX/GNU find, powerful as it is, doesn't seem to have an exclude mode (or I'm missing it), and I've always found it hard to use regular expressions to find things that don't match a particular expression. I'm in a Windows environment (using the GnuWin32 port of most GNU tools), so I'm equally open for Windows-only solutions. 回答1: Or

Make xargs handle filenames that contain spaces

最后都变了- 提交于 2019-12-17 07:59:43
问题 $ ls *mp3 | xargs mplayer Playing Lemon. File not found: 'Lemon' Playing Tree.mp3. File not found: 'Tree.mp3' Exiting... (End of file) My command fails because the file "Lemon Tree.mp3" contains spaces and so xargs thinks it's two files. Can I make find + xargs work with filenames like this? 回答1: The xargs command takes white space characters (tabs, spaces, new lines) as delimiters. You can narrow it down only for the new line characters ('\n') with -d option like this: ls *.mp3 | xargs -d '

In java under Windows, how do I find a redirected Desktop folder?

好久不见. 提交于 2019-12-17 06:53:31
问题 I know using .NET languages such as C#, one can do something like Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) to find the redirected location of the Desktop. However, under Java, I cannot think of a good way to do this. What is the most appropriate way to find a redirected user Desktop directory from Java, without using JNI? The specific purpose here is for the purposes of managing a desktop shortcut, if the user wants one, for a Java Web Start application. This

find files older than X days in bash and delete

試著忘記壹切 提交于 2019-12-17 06:13:10
问题 I have a directory with a few TB of files. I'd like to delete every file in it that is older than 14 days. I thought I would use find . -mtime +13 -delete . To make sure the command works as expected I ran find . -mtime +13 -exec /bin/ls -lh '{}' \; | grep '<today>' . The latter should return nothing, since files that were created/modified today should not be found by find using -mtime +13 . To my surprise, however, find just spew out a list of all the files modified/created today! 回答1: find

How to query MongoDB to test if an item exists?

一世执手 提交于 2019-12-17 05:01:26
问题 Does MongoDB offer a find or query method to test if an item exists based on any field value? We just want check existence, not return the full contents of the item. 回答1: I dont believe that there is a straight way of checking the existence of the item by its value. But you could do that by just retrieving only id (with field selection) db.your_collection.find({..criteria..}, {"_id" : 1}); 回答2: Since you don't need the count, you should make sure the query will return after it found the first

How to query MongoDB to test if an item exists?

谁都会走 提交于 2019-12-17 05:00:53
问题 Does MongoDB offer a find or query method to test if an item exists based on any field value? We just want check existence, not return the full contents of the item. 回答1: I dont believe that there is a straight way of checking the existence of the item by its value. But you could do that by just retrieving only id (with field selection) db.your_collection.find({..criteria..}, {"_id" : 1}); 回答2: Since you don't need the count, you should make sure the query will return after it found the first

How to check if character in string is a letter? Python

谁说我不能喝 提交于 2019-12-17 04:21:21
问题 So I know about islower and isupper, but i can't seem to find out if you can check whether or not that character is a letter? Example: s = 'abcdefg' s2 = '123abcd' s3 = 'abcDEFG' s[0].islower() = True s2[0].islower()= False s3[0].islower()=True is there any way to just ask if it is a character besides doing .islower() or .isupper() ? 回答1: You can use isalpha() , see the docs at http://docs.python.org/2/library/stdtypes.html An example: >>> s = "a123b" >>> for char in s: ... print char, char

Find and copy files

老子叫甜甜 提交于 2019-12-17 04:10:48
问题 Why does the following does not copy the files to the destination folder? # find /home/shantanu/processed/ -name '*2011*.xml' -exec cp /home/shantanu/tosend {} \; cp: omitting directory `/home/shantanu/tosend' cp: omitting directory `/home/shantanu/tosend' cp: omitting directory `/home/shantanu/tosend' 回答1: If your intent is to copy the found files into /home/shantanu/tosend you have the order of the arguments to cp reversed: find /home/shantanu/processed/ -name '*2011*.xml' -exec cp "{}"