Find the answer to your Linux question:
Results 1 to 4 of 4
I have to questions if anyone can answer me that will be great. 1) how can I find the oldest file on my system (I mean searching file by the ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    10

    finding files

    I have to questions if anyone can answer me that will be great.
    1) how can I find the oldest file on my system (I mean searching file by the reported date) and display the file name and its date.
    2) what is the command(s) that will tell me the percentage of files under /var directory are under 2000 bytes?


    Thanaks,

  2. #2
    Content Team _madman_'s Avatar
    Join Date
    Jun 2006
    Posts
    53
    I usually use "Find Files/Folders" under the "K" menu in KDE. It's very user friendly compared with the powerful "find" command.

    The console command for it is "kfind %f" . It is available in the "kfind" package for Debian, and only requires some basic kde core packages for dependencies (not a full-on kde install).

    Otherwise you have some serious homework to do on the "find" command.

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    10
    what options that i can use with find command to do this, if I want to use the 'find' command OR do I have to use a script to do this (to find the oldest file on the system by its date)?


    Quote Originally Posted by _madman_ View Post
    I usually use "Find Files/Folders" under the "K" menu in KDE. It's very user friendly compared with the powerful "find" command.

    The console command for it is "kfind %f" . It is available in the "kfind" package for Debian, and only requires some basic kde core packages for dependencies (not a full-on kde install).

    Otherwise you have some serious homework to do on the "find" command.

  4. #4
    Content Team _madman_'s Avatar
    Join Date
    Jun 2006
    Posts
    53
    The two major things the kinda bug me when people post questions are those looking for quick-fix solutions, who sometimes find them and don't post their solutions, and continue asking for further help. And people who ask for someone else to do their homework for them.

    There are many well written HowTo's and man pages for almost anything related to Unix-like operating systems. However I find this particular question about the " find " command to be unique; So I will provide a possible solution as an example for further investigation and understanding. I think it would be fair to ask that initial postings like this one to at least include some attempt at any solution(s) to the problem.

    The " find " command is very powerful and somewhat complex, as mentioned above. It is a great tool to learn about the power of "pipes" in GNU/Linux. This is why Unix-like operating systems are sometimes refered to as a tool-box OS. You have many small commands that are written to do only one thing, and do it well. Pipes connect these commands together in a seemingly infinite manner. This is far from the DOS/Windows approach and is a primary reason the command-line (terminal/console/etc) is still very much alive in GNU/Linux. Many commands in these Unicies are more or less 30 years old; older than even MSDOS itself. They are powerful and have stood the test of time (some evolving with modification).

    An example to locate the oldest files on you system with the " find " command:

    Code:
    find / -xdev -noleaf -printf '%T+\t%p\n' |sort -n - |head -n 20 -
    The above command(s) will search, starting in the root directory : /
    Without going into other mounted drives : -xdev
    Without processing . and .. : -noleaf
    Printing the date and time : %T+
    Printing a tab space, file name, and newline : \t%p\n
    Pipes the output to sort with the pipe operator : | sort
    Sort command then sorts into numerical order : -n
    Using the output of the previous command as input : -
    The output is then piped further, into head : | head
    Which then displays the first 20 lines of its input : -n 20 -

    When the output of a command is "piped", it is place into what can be thought of as a temporary file in memory (buffer). Stdin and Stdout (standard input and output) are special files (in memory that are trying to go somewhere) that allow for easy redirection. So even though the " sort " command expects a file, we can use " - " instead, and the same with " head ".

    I encourage you to at least skim through the man pages for these particular commands. I hope this example will help you to put it all together and create your own powerful command lines like a real GNU/Linux pro!

    Code:
    man find
    man sort
    man head
    man tail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •