shell script for finding recently accessed file in linux [on hold]How to know who accessed a file or if a...

confused about grep and the * wildcard

Why is 日本 read as "nihon" but not "nitsuhon"?

How to persuade recruiters to send me the Job Description?

If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?

How to refer to a regex group in awk regex?

System to validate run time complexity requirements

Why would the US President need briefings on UFOs?

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

How would one country purchase another?

Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?

A list of proofs of "Coherent topoi have enough points"

Can pay be witheld for hours cleaning up after closing time?

Justifying the use of directed energy weapons

Three Singles in Three Clubs

Why aren't RCS openings an issue for spacecraft heat shields?

What can I do to keep a threaded bolt from falling out of its slot?

How is "sein" conjugated in this sub-sentence?

Why didn’t Doctor Strange stay in the original winning timeline?

In an emergency, how do I find and share my position?

Sleeping solo in a double sleeping bag

Co-author responds to email by mistake cc'ing the EiC

Why is my Earth simulation slower than the reality?

Why don't electrons take the shorter path in coils

Check in to 2 hotels at same location



shell script for finding recently accessed file in linux [on hold]


How to know who accessed a file or if a file has 'access' monitor in linuxWhen saving INTO OUTFILE from mysql on a systemd based system, the output file is grabbed by systemd — why?Cron job not logging?rsyslog7 filter to hostname if no match to regexFind a file matching with certain pattern and giving that file name as value to a variable in shell script?grep doesn't print matchesLogrotate: Run postrotate script with rotated file






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-3















print the name of the most recently accessed file in the directory /var/run/log/ whose name is of the form access-<DDD>.log (here <DDD> represents exactly 3 digits; thus the filename consists of access- followed by exactly 3 digits, followed by .log










share|improve this question









New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Christopher, roaima, Jeff Schaller 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.




















  • What is your issue with this assignment?

    – Kusalananda
    2 days ago











  • I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

    – roaima
    2 days ago




















-3















print the name of the most recently accessed file in the directory /var/run/log/ whose name is of the form access-<DDD>.log (here <DDD> represents exactly 3 digits; thus the filename consists of access- followed by exactly 3 digits, followed by .log










share|improve this question









New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Christopher, roaima, Jeff Schaller 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.




















  • What is your issue with this assignment?

    – Kusalananda
    2 days ago











  • I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

    – roaima
    2 days ago
















-3












-3








-3








print the name of the most recently accessed file in the directory /var/run/log/ whose name is of the form access-<DDD>.log (here <DDD> represents exactly 3 digits; thus the filename consists of access- followed by exactly 3 digits, followed by .log










share|improve this question









New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











print the name of the most recently accessed file in the directory /var/run/log/ whose name is of the form access-<DDD>.log (here <DDD> represents exactly 3 digits; thus the filename consists of access- followed by exactly 3 digits, followed by .log







linux






share|improve this question









New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 2 days ago









Kusalananda

160k18 gold badges317 silver badges504 bronze badges




160k18 gold badges317 silver badges504 bronze badges






New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 2 days ago









ANKIT PAHARIYAANKIT PAHARIYA

2




2




New contributor



ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




ANKIT PAHARIYA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







put on hold as unclear what you're asking by Christopher, roaima, Jeff Schaller 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











put on hold as unclear what you're asking by Christopher, roaima, Jeff Schaller 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









put on hold as unclear what you're asking by Christopher, roaima, Jeff Schaller 2 days ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • What is your issue with this assignment?

    – Kusalananda
    2 days ago











  • I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

    – roaima
    2 days ago





















  • What is your issue with this assignment?

    – Kusalananda
    2 days ago











  • I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

    – roaima
    2 days ago



















What is your issue with this assignment?

– Kusalananda
2 days ago





What is your issue with this assignment?

– Kusalananda
2 days ago













I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

– roaima
2 days ago







I'm voting to close this question as off-topic because you're demanding we do your assignment for you without any visible attempt by yourself.

– roaima
2 days ago












2 Answers
2






active

oldest

votes


















1













Using the zsh shell:



setopt EXTENDED_GLOB
print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])


Here, [[:digit:]](#c3) will match exactly three digit characters. After that, the string .log must occur in the name. The dot in (.oa[1]) qualifies the globbing pattern so that only regular files are matched and the oa sorts them in decreasing atime order. The [1] returns only the first matching name (the most recently accessed one). The print utility will print the resulting pathname.



Change print to basename to only output the filename, without the path.





If this is a homework assignment and you're supposed to write a bash script:



#!/bin/bash

zsh -o extended_glob -c 'print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])'





share|improve this answer



































    0













    Try this:



    ls -tu | grep -e '^access-[0-9]{3}.log$' | awk '{print $NF}'





    share|improve this answer




























    • Fixed again. I think that should do it. <:)

      – pgoetz
      yesterday











    • @Kusalananda Now awk seems unnecessary (without the -l option to ls).

      – fra-san
      yesterday











    • The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

      – Kusalananda
      yesterday






















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1













    Using the zsh shell:



    setopt EXTENDED_GLOB
    print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])


    Here, [[:digit:]](#c3) will match exactly three digit characters. After that, the string .log must occur in the name. The dot in (.oa[1]) qualifies the globbing pattern so that only regular files are matched and the oa sorts them in decreasing atime order. The [1] returns only the first matching name (the most recently accessed one). The print utility will print the resulting pathname.



    Change print to basename to only output the filename, without the path.





    If this is a homework assignment and you're supposed to write a bash script:



    #!/bin/bash

    zsh -o extended_glob -c 'print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])'





    share|improve this answer
































      1













      Using the zsh shell:



      setopt EXTENDED_GLOB
      print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])


      Here, [[:digit:]](#c3) will match exactly three digit characters. After that, the string .log must occur in the name. The dot in (.oa[1]) qualifies the globbing pattern so that only regular files are matched and the oa sorts them in decreasing atime order. The [1] returns only the first matching name (the most recently accessed one). The print utility will print the resulting pathname.



      Change print to basename to only output the filename, without the path.





      If this is a homework assignment and you're supposed to write a bash script:



      #!/bin/bash

      zsh -o extended_glob -c 'print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])'





      share|improve this answer






























        1












        1








        1







        Using the zsh shell:



        setopt EXTENDED_GLOB
        print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])


        Here, [[:digit:]](#c3) will match exactly three digit characters. After that, the string .log must occur in the name. The dot in (.oa[1]) qualifies the globbing pattern so that only regular files are matched and the oa sorts them in decreasing atime order. The [1] returns only the first matching name (the most recently accessed one). The print utility will print the resulting pathname.



        Change print to basename to only output the filename, without the path.





        If this is a homework assignment and you're supposed to write a bash script:



        #!/bin/bash

        zsh -o extended_glob -c 'print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])'





        share|improve this answer















        Using the zsh shell:



        setopt EXTENDED_GLOB
        print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])


        Here, [[:digit:]](#c3) will match exactly three digit characters. After that, the string .log must occur in the name. The dot in (.oa[1]) qualifies the globbing pattern so that only regular files are matched and the oa sorts them in decreasing atime order. The [1] returns only the first matching name (the most recently accessed one). The print utility will print the resulting pathname.



        Change print to basename to only output the filename, without the path.





        If this is a homework assignment and you're supposed to write a bash script:



        #!/bin/bash

        zsh -o extended_glob -c 'print /var/run/log/access-[[:digit:]](#c3).log(.oa[1])'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        KusalanandaKusalananda

        160k18 gold badges317 silver badges504 bronze badges




        160k18 gold badges317 silver badges504 bronze badges




























            0













            Try this:



            ls -tu | grep -e '^access-[0-9]{3}.log$' | awk '{print $NF}'





            share|improve this answer




























            • Fixed again. I think that should do it. <:)

              – pgoetz
              yesterday











            • @Kusalananda Now awk seems unnecessary (without the -l option to ls).

              – fra-san
              yesterday











            • The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

              – Kusalananda
              yesterday


















            0













            Try this:



            ls -tu | grep -e '^access-[0-9]{3}.log$' | awk '{print $NF}'





            share|improve this answer




























            • Fixed again. I think that should do it. <:)

              – pgoetz
              yesterday











            • @Kusalananda Now awk seems unnecessary (without the -l option to ls).

              – fra-san
              yesterday











            • The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

              – Kusalananda
              yesterday
















            0












            0








            0







            Try this:



            ls -tu | grep -e '^access-[0-9]{3}.log$' | awk '{print $NF}'





            share|improve this answer















            Try this:



            ls -tu | grep -e '^access-[0-9]{3}.log$' | awk '{print $NF}'






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday









            Kusalananda

            160k18 gold badges317 silver badges504 bronze badges




            160k18 gold badges317 silver badges504 bronze badges










            answered 2 days ago









            pgoetzpgoetz

            4545 silver badges11 bronze badges




            4545 silver badges11 bronze badges
















            • Fixed again. I think that should do it. <:)

              – pgoetz
              yesterday











            • @Kusalananda Now awk seems unnecessary (without the -l option to ls).

              – fra-san
              yesterday











            • The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

              – Kusalananda
              yesterday





















            • Fixed again. I think that should do it. <:)

              – pgoetz
              yesterday











            • @Kusalananda Now awk seems unnecessary (without the -l option to ls).

              – fra-san
              yesterday











            • The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

              – Kusalananda
              yesterday



















            Fixed again. I think that should do it. <:)

            – pgoetz
            yesterday





            Fixed again. I think that should do it. <:)

            – pgoetz
            yesterday













            @Kusalananda Now awk seems unnecessary (without the -l option to ls).

            – fra-san
            yesterday





            @Kusalananda Now awk seems unnecessary (without the -l option to ls).

            – fra-san
            yesterday













            The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

            – Kusalananda
            yesterday







            The ^ anchor would make the expression never match with ls -l as you have more data on the line before the filename. If you really want to use ls -l, then swap places on awk and grep, or use awk '$NF ~ /^expression$/ { print $NF }' to combine them. With ls -l and print $NF in awk, you lose the ability handle filenames with spaces though. Consider doing some testing.

            – Kusalananda
            yesterday





            Popular posts from this blog

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...