I have written a shell script to delete a set of video files (.0 format) which are 81 or more days older in putty using the following:
find /data/local_0/ -type f -name "*.0" -mtime +80 -exec rm {}\;
When I execute this command, I'm getting the following exception.
[root#server /]# find /data/local_0/ -type f -name "*.0" -mtime +50
find: /data/local_0/: Value too large for defined data type
I also tried to delete forcefully but same exception popped up. How to resolve this exception?
i have added a screen shot as evidence, too.
Related
I am trying to use find command to delete some old file from backup folder but the find command return nothing, and so nothing is being removed! this is the code (find part), my system is ubuntu 18.04 LTS
find -name "*.sql" -type f -mtime +30
the result of find command
and the output of ls -l command is :
the result of ls -l command
I googled and searched the web but did find nothing to solve the problem. any help appreciated.
You are missing the starting point for your find command, in this case . because you already execute the command in the target directory:
find . -name "*.sql" -type f -mtime +30
the rest can stay the same.
First make sure it gives you the correct result and afterwards you can tack on the -exec to execute a command for each line of the result.
find . -name "*.sql" -type f -mtime +30 -exec rm '{}' ';'
You can usually find such answers on the UNIX stackexchange: How to execute ln on find results
Please see the comment from David in this particular case it might be a misunderstanding of the mtime parameter.
I have tested exactly the commands that were listed here, below you see
my preparation and some multiple usage, you can see how the files show up as expected, every time the mtime value decreases:
VIRTUAL BOX UBUNTU LTS 18.04
which is no surprise, given the man page of the find command:
FIND MAN PAGE / -mtime PARAMETER
please check for any typos... this should work.
I know the way to delete older files using the find command is:
find /mydir/typ* -type f -mtime + 5 -delete
However if it doesn't find a file, it returns an error saying no matches found. Is there a way to just fail silently, i.e. not to throw an error if it can't find the file. If it does, delete it.
find /mydir/typ* -type f -mtime + 5 -delete 2> /dev/null
So, from your comment on another answer, your full error is zsh: no matches found. The error is coming from your shell, not find.
/mydir/typ* is a shell glob, and zsh by default gives you an error if no files match the glob. More info on that here.
It's not clear what your directory structure and intended use are, but if you want to find files matching typ* in /mydir, you want find /mydir -name 'typ*' -type f -mtime +5 -delete. Otherwise, you'll have to be more specific about your situation.
I need to write a bash-script which will find all files with name string.h on the computer and copy them to some folder. My code is here:
#!/bin/bash
sudo find / -type f -name "string.h" -exec cp {} $HOME/MyDocuments \;
But during the execution of the script, I get error-messages on my console terminal "permission denied". How I can avoid getting this message? Console terminal must be clear.
Suppress the error messages from stderr(2) to the NULL stream designated by /dev/null
sudo find / -type f -name "string.h" -exec cp "{}" $HOME/MyDocuments \; 2 > /dev/null
where the 2 in the above line stands for file descriptor.
I would personally recommend you to investigate the actual cause of the issue rather than suppressing it. Do the above only if you are absolutely sure that the errors are trivial.
Will you be able to help me to write a script, I just want to find log files over 2GB and copy them to archive folder in same directory.I just write a find command it is not working, appreciate if someone could help me.
ex - main log folders - /vsapp/logs/
- app1,app2,app3
there are lot of logs in the app1, app2 and app3 folders.
so i want to find the logs in the logs folder which is over 2GB, and copy them to archive folder with the different name with today's date.
ex - abcd.log -----copy to -----> abcd.log-08-22-2016
My command at the moment which is not working
find $i/* -type f -size +2G -exec cp '{}' $i/$arc/{}-$date
You can do:
find /src -type f -name '*.log' -size +2G -exec cp {} /dest/{}-$(date -I) \;
Additions/Modifications i made:
-name '*.log' searches only for log files, as we are only interested in those. You can look for files with any names too if unsure, just omit -name '*.log in that case
$(date -I) is command substitution the output will be today's date in format YYYY-mm-dd, you can also define a custom format, check man date
End the -exec action of find with \;
I would like to find all the pdf files in a folder. It contains pdf files inside and more directories that contain more as well. The folder is located on a remote server I have ssh access to. I am using the mac terminal but I believe the server I am connecting to is Centos.
I need to find all the pdfs and copy them all to one directory on the remote server. I've tried about 10 variations with no luck. Both mine and the remote systems do not seem to recognise -exec as a command though exec is fine so thats a problem.
Im not sure what the problem is here but the command does not fail it just sits there and stalls forever so I do not have any useful errors to post.
cp $(find -name "*.pdf" -type f; exec ./pdfsfolder {} \; | sed 1q)
find: ./tcs/u25: Permission denied
find: ./tcs/u68: Permission denied
-bash: /var/www/html/tcs_dev/sites/default/files/pdfsfolder: is a directory
-bash: exec: /var/www/html/tcs_dev/sites/default/files/pdfsfolder: cannot execute: Success
cp: target `./runaways_parents_guide_2013_final.pdf' is not a directory
This is the last one I tried, I think I can ignore the permission denied errors for now but im not sure about the rest.
Try this:
find . -name "*.pdf" -type f -exec cp {} ./pdfsfolder \;
Paul Dardeau answer is perfect, the only thing is, what if all the files inside those folders are not PDF files and you want to grab it all no matter the extension. Well just change it to
find . -name "*.*" -type f -exec cp {} ./pdfsfolder \;
Just to sum up!
Something like this should work.
ssh user#ip.addr 'find -type f -name "*.pdf" -exec cp {} ./pdfsfolder \;'