LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   checking files buy date (https://www.linuxquestions.org/questions/linux-newbie-8/checking-files-buy-date-4175548512/)

apss_evaluator 07-21-2015 03:49 AM

checking files buy date
 
Hi Linux Guru's
can you guide me on which command to use? I'm trying to check on the files that are dated 2015-07-16 to latest but I'm having a different results

I've tried these but gives me a wrong echo

Code:

[pog@gwapo file]$ ls grep file.log.2015-07-{16..21}
ls: grep: No such file or directory
ls: file.log.2015-07-16: No such file or directory
ls: file.log.2015-07-17: No such file or directory
ls: file.log.2015-07-18: No such file or directory
ls: file.log.2015-07-19: No such file or directory
ls: file.log.2015-07-20: No such file or directory
ls: file.log.2015-07-21: No such file or directory


The files to check is this:
Code:

-rw-r--r-- 1 pogi pogi 9.3K Jun  7 05:46 file.log.2015-06-07-054449
-rw-r--r-- 1 pogi pogi  229 Jun  7 05:46 file.log.2015-06-07-054624
-rw-r--r-- 1 pogi pogi 4.6K Jun  7 05:48 file.log.2015-06-07-054849
-rw-r--r-- 1 pogi pogi 4.6K Jun  8 08:23 file.log.2015-06-08-082320
-rw-r--r-- 1 pogi pogi 4.6K Jun 11 22:31 file.log.2015-06-11-223157
-rw-r--r-- 1 pogi pogi 5.2K Jun 12 02:04 file.log.2015-06-12-020426
-rw-r--r-- 1 pogi pogi 5.2K Jun 21 10:48 file.log.2015-06-21-104818
-rw-r--r-- 1 pogi pogi 5.2K Jun 21 11:54 file.log.2015-06-21-115433
-rw-r----- 1 pogi pogi 5.0K Jul 11 09:21 file.log.2015-07-11-092139
-rw-r----- 1 pogi pogi 5.0K Jul 11 12:49 file.log.2015-07-11-124941
-rw-r----- 1 pogi pogi 4.8K Jul 12 09:08 file.log.2015-07-12-090817
-rw-r----- 1 pogi pogi 5.2K Jul 14 05:01 file.log.2015-07-14-050145
-rw-r----- 1 pogi pogi 4.8K Jul 14 05:23 file.log.2015-07-14-052306
-rw------- 1 pogi pogi 5.2K Jul 14 12:07 file.log.2015-07-14-120720
-rw------- 1 pogi pogi 5.0K Jul 14 14:38 file.log.2015-07-14-143853
-rw------- 1 pogi pogi 5.0K Jul 15 04:54 file.log.2015-07-15-045414
-rw------- 1 pogi pogi 5.0K Jul 16 06:15 file.log.2015-07-16-061511
-rw------- 1 pogi pogi 4.8K Jul 16 08:58 file.log.2015-07-16-085855
-rw------- 1 pogi pogi 5.0K Jul 18 06:28 file.log.2015-07-18-062857
-rw------- 1 pogi pogi 4.8K Jul 18 12:48 file.log.2015-07-18-124846
-rw------- 1 pogi pogi 4.8K Jul 18 22:12 file.log.2015-07-18-221207
-rw------- 1 pogi pogi 4.8K Jul 19 03:27 file.log.2015-07-19-032802
-rw------- 1 pogi pogi 5.0K Jul 19 07:29 file.log.2015-07-19-073000
-rw------- 1 pogi pogi 5.0K Jul 19 09:02 file.log.2015-07-19-090209
-rw------- 1 pogi pogi 5.0K Jul 19 12:04 file.log.2015-07-19-120408
-rw------- 1 pogi pogi 5.0K Jul 19 22:53 file.log.2015-07-19-225348
-rw------- 1 pogi pogi 4.8K Jul 20 01:59 file.log.2015-07-20-015915
-rw------- 1 pogi pogi 4.8K Jul 20 04:00 file.log.2015-07-20-040022
-rw------- 1 pogi pogi 4.8K Jul 20 04:05 file.log.2015-07-20-040558
-rw------- 1 pogi pogi 4.8K Jul 20 06:52 file.log.2015-07-20-065230
-rw------- 1 pogi pogi 4.8K Jul 20 11:49 file.log.2015-07-20-114939
-rw------- 1 pogi pogi 5.0K Jul 20 18:54 file.log.2015-07-20-185427
-rw------- 1 pogi pogi 4.8K Jul 20 19:29 file.log.2015-07-20-192927
-rw------- 1 pogi pogi 5.0K Jul 21 00:08 file.log.2015-07-21-000825


berndbausch 07-21-2015 03:56 AM

You are very close. Remove the "grep" (why did you put it there in the first place?). Then add an asterisk to the file name pattern.

However, this only works if "latest" is the 21st.

apss_evaluator 07-21-2015 04:04 AM

Quote:

Originally Posted by berndbausch (Post 5394213)
You are very close. Remove the "grep" (why did you put it there in the first place?). Then add an asterisk to the file name pattern.

However, this only works if "latest" is the 21st.

I've tried removing the grep but I throws me a "ls: grep: No such file or directory" may I know what parameter does eliminate that?


Code:

[pogi@gwapo file]$ ls -ltrh file.log.2015-07-{16..21}*
ls: file.log.2015-07-17*: No such file or directory
-rw------- 1 pogi pogi 5.0K Jul 16 06:15 file.log.2015-07-16-061511
-rw------- 1 pogi pogi 4.8K Jul 16 08:58 file.log.2015-07-16-085855
-rw------- 1 pogi pogi 5.0K Jul 18 06:28 file.log.2015-07-18-062857
-rw------- 1 pogi pogi 4.8K Jul 18 12:48 file.log.2015-07-18-124846
-rw------- 1 pogi pogi 4.8K Jul 18 22:12 file.log.2015-07-18-221207
-rw------- 1 pogi pogi 4.8K Jul 19 03:27 file.log.2015-07-19-032802
-rw------- 1 pogi pogi 5.0K Jul 19 07:29 file.log.2015-07-19-073000
-rw------- 1 pogi pogi 5.0K Jul 19 09:02 file.log.2015-07-19-090209
-rw------- 1 pogi pogi 5.0K Jul 19 12:04 file.log.2015-07-19-120408
-rw------- 1 pogi pogi 5.0K Jul 19 22:53 file.log.2015-07-19-225348
-rw------- 1 pogi pogi 4.8K Jul 20 01:59 file.log.2015-07-20-015915
-rw------- 1 pogi pogi 4.8K Jul 20 04:00 file.log.2015-07-20-040022
-rw------- 1 pogi pogi 4.8K Jul 20 04:05 file.log.2015-07-20-040558
-rw------- 1 pogi pogi 4.8K Jul 20 06:52 file.log.2015-07-20-065230
-rw------- 1 pogi pogi 4.8K Jul 20 11:49 file.log.2015-07-20-114939
-rw------- 1 pogi pogi 5.0K Jul 20 18:54 file.log.2015-07-20-185427
-rw------- 1 pogi pogi 4.8K Jul 20 19:29 file.log.2015-07-20-192927
-rw------- 1 pogi pogi 5.0K Jul 21 00:08 file.log.2015-07-21-000825


millgates 07-21-2015 05:00 AM

Quote:

Originally Posted by apss_evaluator (Post 5394218)
Code:

[pogi@gwapo file]$ ls -ltrh file.log.2015-07-{16..21}*
ls: file.log.2015-07-17*: No such file or directory


You're using brace expansion in your command. Brace expansion is performed before pathname expansion, and doesn't require the filename to exist, so the first thing that happens is that your command gets expanded to

Code:

ls -ltrh file.log.2015-07-16* file.log.2015-07-17* file.log.2015-07-18* file.log.2015-07-19* file.log.2015-07-20* file.log.2015-07-21*
Then, the pathname expansion occurs and each of the expressions will be replaced by lists of matching filenames. Because there is no file matching the glob

Code:

file.log.2015-07-17*
this one will remain unchanged. And because the file with such a name does not exist, ls will of course complain about that.
Apart from giving you an ugly error message, it is harmless and you can just send the message to /dev/null.
Also, you can change the default shell behaviour regarding unmatched globs with
Code:

shopt -s nullglob

berndbausch 07-21-2015 05:25 AM

Quote:

Originally Posted by apss_evaluator (Post 5394218)
I've tried removing the grep but I throws me a "ls: grep: No such file or directory" may I know what parameter does eliminate that?

You remove grep from your command by not typing it.

Or more precisely: When you type "ls grep", the "ls" command will look up a file named grep. Since it doesn't find this file, it complains. So, leave the "grep" out of your command and you are half-way there.

In addition, your original command looked for files that end in 16, 17, ..., 21. However the filenames in your directory don't end with this number. So, add an asterisk, which stands for "any string".

apss_evaluator 07-21-2015 05:48 AM

Quote:

Originally Posted by berndbausch (Post 5394235)
You remove grep from your command by not typing it.

Or more precisely: When you type "ls grep", the "ls" command will look up a file named grep. Since it doesn't find this file, it complains. So, leave the "grep" out of your command and you are half-way there.

In addition, your original command looked for files that end in 16, 17, ..., 21. However the filenames in your directory don't end with this number. So, add an asterisk, which stands for "any string".

I was able to check it via find

Code:

find . -maxdepth 1 -mtime -6 | sort


All times are GMT -5. The time now is 12:14 AM.