Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name begins with 'ABC_DEFGH_'.
Here is the command that I'm running.
but when I run the following code it shows the list of all files:
Can you list a few files that it does find without the modification time restriction? I suspect that they are all modified (contents edited) more recently than 20 days. Have you got the search backwards perhaps? What is the requirement?
You also have an odd search pattern which doesn't match your requirements, so you are rather getting-away-with-it. Would your search pattern not be just 'ABC_DEFGH_*'?
How to debug problems like this
steps:
Also note: mtime does this:
filetimes are stored as seconds since Jan 1 1970, which is usually a large number:
mtime gets that number for right now, then mutiplies the number of seconds, 86400, times the number of days: 20 * 86400 = 1728000.
Next, it subtracts that smaller number of seconds from right now: 1507899718 - 1728000 = 1506171718
So find is really looking for files that have filetimes of 1506171718 or less. Nowhere did I mention anything about calendars. This does not exactly match what your calendar tells you.
You could have a file that is 20 calendar days old but find still would not see it because the calculation is not based on calendars.
Last edited by jim mcnamara; 10-13-2017 at 10:10 AM..
These 3 Users Gave Thanks to jim mcnamara For This Post:
Thank you all ;-) The issue is resolved. Now I can see the list of files when I run the command.
But I have another question. In this directory i have some other subdirectories that contains files with similar name(begins with ABC_DEFGH). How can I remove/delete these files only in the current directory and not in other subdirectories?
Thank you all ;-) The issue is resolved. Now I can see the list of files when I run the command.
But I have another question. In this directory i have some other subdirectories that contains files with similar name(begins with ABC_DEFGH). How can I remove/delete these files only in the current directory and not in other subdirectories?
if I read this correct,
folder A has say 100 files, say 30 of which is ABC_DEFGH*
and also has folder B nad has 20ish files that has ABC_DEFGH*
if so, you can remove all from folder a and NOT folder B.
or
notice the lack of -r
will recursively remove the files including in subfolders.
Hello.
From a script, a command for a test is use :
find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'
Tha command... (3 Replies)
Hi Gurus.
This is driving me a bit batty. I now if must be a simple matter but I cant find anything that references it.
I have a housekeeping script that searches for some huge dump directories then removes them using rm -rf.
find ./ -name 'ab' -exec rm -rf {} \;
This works but always... (7 Replies)
I am trying to find pictures which contains a specific word in the file name.
For example any .JPG files that contains "lm" at the beginning or at the middle or at the end of the file name.
find / -iname "*.jpg" | ...what should go after the pipe?
regards,
Moaathe (2 Replies)
Hi all!
I've faced with very unintelligible error using find/grep like this:
root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but:
root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc
$db_name = 'u28507';... (2 Replies)
Hi,
How do you echo something once when a find statement returns null results?
This is when using mutiple locations and mutiple arguments.
The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations.
find... (2 Replies)
Hi, I want to write a script that runs a command (at -l) and writes the output to a file. If the command (at -l) command returns no value (is empty/null) then write a message to the file in place of the command output.
My problem is around trapping the empty returned command value and replacing... (2 Replies)
Hi,
I've got an issue with a shell script that FTP's a file from one Linux server to another Linux server.
My script runs on a Linux server and creates an output file (from a database call), and then FTP's this file to another Linux server.
The problem is that, even though the output file... (0 Replies)
Hi guys.
I am trying, to move files found with the find command...
Script runs fine, until it reaches a file that contains spaces...
Here is what i wrote up quickly.
ROOTDIR=/apps/data
SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-)
for i... (1 Reply)
When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file.
Once I get this command to work, I will add the "delete" part to the... (6 Replies)
This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions.
!/bin/sh
sed -e 's/*//g' \ #replace * with nothing
-e s/ /X/g' \ #replacing empty space with X
-e... (2 Replies)