Find by -name and -mtime, returns nothing - linux

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.

Related

Usage of "find" linux command

My question is about linux commands. I need to find all ".sh" files and I need to delete all the files which end with ".sh" extension automatically. Could anyone please help me out by giving suitable linux command for it?
find . -type f -name '*.sh' -exec rm {} \;

How to avoid find command in Linux from throwing errors

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.

Unable to delete set of video files using shell script

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.

Why does find . -name foo* fail?

OK, probably a stupid question, but why doesn't this work?
find . -name Orna* -ls
It seems that "find" should be able to handle this simple request... Am I missing something here? This should be a basic execution of the "find" command, but linux is being stupid, or maybe I am.
correct way of using Find Command are the following phrases
find . -type f -name "filename" # this command used to find files from the curent dir
find . -type d -name "dir name" # this command used to find dirs from the curent dir
find /. -type f -name "filename" # this command used to find files from the system
find /. -type d -name "dir name" # this command used to find dirs from the system
I wish it be a helpful for you
You need to quote the name parameter so the shell doesn't expand the wildcard, e.g.
find . -name "Orna*" -ls
To explain the "why" a little more than existing answers do -- wildcards are expanded by the shell before the command being invoked is run. Thus, let's say your current directory contains files Orna1 and Orna2.
In that case, when you run
find . -name Orna* -ls
...what's actually invoked by the shell is:
find . -name Orna1 Orna2 -ls
...thus, find never sees the wildcard expression at all!
Quoting the expansion, as in:
find . -name 'Orna*' -ls
...prevents the shell from trying to expand the wildcard before running your command, thus preventing this issue.

Using `find -perm` to find when a permission is not set

I want to find the non-readable files in my directory (eg the files with g-r). So I tried this:
find . -perm -g-r
It shows me all of the files?? So I tried this:
find . -perm -g+r
And it showed me only the readable files. It appears that -perm -g-r matches all files. I'm using CentOS 5.5. Am I doing something wrong? It doesn't look like -perm -g-r does anything useful.
Try:
find . ! -perm -g+r
If you want to find files that are non-readable by you, you could use
find . ! -readable
on my Debian I need to escape the negation "exclamation mark"
so in your case it would be
find . \! -perm -g+r -ls
using numbers is also an option. This was my quest:
find . \! -perm /444
to see what really happens use:
find . \! -perm /444 -exec ls -la {} \;
You were able to see all files when you executed the below instruction, because you were executing it as root.
find . -perm -g-r
Try executing as a normal user.

Resources