linux pipe argument list too long [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I use the following bash script to remove files older than $days.
find /home/xxx/conf_* -maxdepth 0 -mindepth 0 -type d -ctime +5 -exec rm -rf {} \;
However if the files are more than 32000+, I get
/usr/bin/find: Argument list too long
how do I trim the list down to like 20000 only?

From comment to answer:
Your problem is the glob expansion but you are already using a tool that can perfectly well handle an arbitrary number of found results, namely find. As such you should use a glob at all. Instead you should let find do all the work.
Something like:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \;
Also if your find has -exec \+ you should probably use this instead:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \+
For such a large number of matching directories I imagine the significantly reduced amount of executions of rm might be significantly more efficient.

Related

Gzip or tars logs that are older than 7 days [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
Need to create a single script that would Gzip or tars logs that are older than 7 days in multiple (3) paths /home/temp, home/logs, then confirm this one is over 50% capacity home/var/lib/mongo. This is what I got so far but I can't think of how to combine these:
find . -mtime +7 -print -exec gzip {} \; for all 3 but them
find /tmp/log/ -mtime +7 -type f -exec sh -c \
'tar -czvPf /tmp/older_log_$(basename $0)_$(date +%F).tar.gz $0' {} ;
# create a single tar file for each archive +7 days old on one mount
If I understand you correclty, you would like to archive multiple old logs in one tar files:
find /tmp/log /home/temp /home/logs -mtime +7 -type f \
| xargs tar -czf /tmp/older_log_$(date +%F).tar.gz --remove-files
For easy reading I put it on two lines.
It searches for all files you want to archive
Pass the found files as arguments to the tar archive (using xargs)
tar will make the new archive and add all the files
additionally tar will remove the original files with the last oiption (from GNU tar)

Use find command with -perm and -maxdepth [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
When I Enter this command:
$ find . -perm 777 -maxdepth 1
The following error occures:
find: warning: you have specified the -maxdepth option after a non-option argument -perm, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
What does that mean?
The order of find arguments is very important, because they are evaluated as a boolean expression left-to-right with short circuiting:
# Deletes *.tmp files
find . -name '*.tmp' -delete
# Deletes ALL file, because -delete is performed before -name
find . -delete -name '*.tmp'
However, -maxdepth does not behave like this. -maxdepth is an option that changes how find works, so it applies the same no matter where it's placed:
# Deletes all '*.tmp' files, but only in the current dir, not subdirs
find . -maxdepth 1 -name '*.tmp' -delete
# Deletes all '*.tmp' files, still only in the current dir
find . -name '*.tmp' -delete -maxdepth 1
Since you put the -maxdepth 1 after a -perm 777, it looks like you are trying to make -maxdepth only apply to certain files. Since this is not possible, find prints this warning.
It suggests that you rewrite it into find . -maxdepth 1 -perm 777 to make it clear that you intended -maxdepth to apply to everything.

No such file or directory find command on linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I've created script which delete old backup file from directory but this command was worked fine before 1 week and Nothing change on script or packages but still getting below error:
root#:# find /var/backups/abc/* -type d -mtime +6
/var/backups/abc/2016-03-09_0321
root#:~# find /var/backups/abc/* -type d -mtime +6 -exec rm -rf {} \;
find: `/var/backups/abc/2016-03-08_0321': No such file or directory
Problem is that, this script run every day on cron, I getting a mail like " find: `/var/backups/abc/2016-03-08_0321': No such file or directory". files are deleted but such a mails are getting from root.
find /var/backups/abc/* -type d -mtime +6 -prune -exec rm -rf {} \;
Here, we useĀ -pruneĀ on the directories that we're about to delete, so find will then not try to read their contents.
This is because of after having returned your directory, find will try to look in it (to continue his recursive search), and will fail because of you just removed it.

How to remove zero byte files [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have the following directory structure:-
foo/dir1/
foo/dir2/
foo/dir3/
foo/dir1/a.rb
foo/dir1/b.rb
foo/dir1/c.rb
foo/dir1/d.rb
foo/dir2/e.rb
foo/dir2/f.rb
foo/dir2/g.rb
foo/dir2/h.rb
How to remove zero byte files from a certain folder (some of the files under dir1, dir2 are zero bytes). How do I find and remove such files?
Assuming you have a version of find compliant enough with POSIX 2008 to support the + notation:
find foo -size 0 -exec rm -f {} +
If you don't, there are variants you can use:
find foo -size 0 -print0 | xargs -0 rm -f # But you probably have + anyway
find foo -size 0 -exec rm -f {} \; # Slow but reliable
find foo -size 0 -print | xargs rm -f # Fails with spaces etc in file names
And the accepted answer to the duplicate question suggests -delete, which is good when it is supported by the find you are using (because it avoids the overhead of executing the rm command by doing the unlink() call inside find):
find foo -size 0 -delete # Not POSIX standard

Setting file permission for Files and Directories [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I need to apply below permission policies to my files under www folder
664 to all files in www recursively,
755 to all directories under www recursively
I tried
find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
But always getting error
find: missing argument to `-exec'
What is the solution?
Backslash before semi-colon (or quotes around it):
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
The shell sees the semi-colon you typed as the end of the command and does not pass it to find, which then complains that it is missing.
Use backslash before ';'
find . -type f -exec chmod 644 {} \;

Resources