1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need a shell command to show last modified files and create a .txt

Discussion in 'General Scripting Chat' started by subster, Nov 29, 2012.

  1. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Hi there,

    I'd need a shell command to show of the last modified and new files on the whole server (recursive) and echoing them into a txt file in the root.

    Has anybody something like this?

    Would be so awesome (Rep + Thanks will be given).
     
  2. talktoroot

    talktoroot Newbie

    Joined:
    Jun 18, 2012
    Messages:
    43
    Likes Received:
    14
    if you are using a Linux system you can use the following command:

    Code:
    find / - mmin 60  -printf "%AD %Ar - %p\n" 2> /dev/null | head -300 | sort -r > /lastmodified.txt
    the parameter 60 will show the files modified on the last 60 minutes, you can modify it.
    the parameter -300 will show only the first 300 results, you can also modify it. if you want all the results use only:

    Code:
    find / - mmin 60  -printf "%AD %Ar - %p\n" 2> /dev/null | sort -r > /lastmodified.txt
    the results will be written on the file /lastmodified.txt

    PS: you have to be root to write on /
    if you are not root redirect the results to another file, for example /tmp/lastmodified.txt
     
    • Thanks Thanks x 1
  3. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Thank you so much!

    Worked flawless!
     
  4. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Something was wrong - this has shown me everything from the server files, but not from the directories with the website files in.
     
  5. talktoroot

    talktoroot Newbie

    Joined:
    Jun 18, 2012
    Messages:
    43
    Likes Received:
    14
    execute the command without the "2> /dev/null" part and see if you get error messages
     
    • Thanks Thanks x 1
  6. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    still only folders like /var / proc/ and so on...
     
  7. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Now I got it:
    Exchanged file / to file . and removed the "2> /dev/null"