Files Since Primer Tutorial

Files Since Primer Tutorial

Files Since Primer Tutorial

A while ago we spoke of the Linux commands find and locate in Linux Find and/or Locate Files/Directories Primer Tutorial as shown below. After that you may have been thinking “That’s it! No more carrying on about directory listings and stuff!” … and we say … but on a practical level how can this knowledge be set to good use?

With that in mind, today, we do a tutorial called “Files Since” (and just concentrate on command line work … there may well be Mac Finder and/or Windows Explorer solutions to this problem, but want to stick to command line, for today), because it is easy to get sidetracted sidetracked these days and forget what you’ve been doing, so today for both Mac and Windows we show a scenario of (finding files that):

  • are HTML
  • have been worked on over the last seven days
  • from all directories and subdirectories off where we are now (in relevant command line environment)

Obviously, if you are asleep now, you’ll continue to be asleep, and you can sleep through the next bit just as well.

But if you are still here, this scenario is a doddle for Mac (via Bash environment find command via Terminal application). However, believe it or not, it is not straightforward in a Windows (DOS command line) environment, depending on how user-friendly you want the information to be … let me explain … DOS command line (out of the box) can do a listing sorted by date (descending) of the last file write date for all the subdirectories, but, without some tailoring it can’t cut off the report and not mention superfluous files to your designated date range of interest … for us, 7 days.

You might ask, “How come?” … and that is a good question … but wasting time … so why don’t we create a hybrid DOS/Linux-find-equivalent-of-mtime-switch scenario. What is meant by this is that Windows/DOS does 99% of what anybody wants, and that is good (thanks), but why not try to add on the bit of Linux find (its -mtime -7d (for our case) … (just the d suboption will be assumed)) cute functionality into our Windows/DOS world … with help from here (get yesterday’s date in DOS batch … thanks) and here (brilliant DOS batch string functionality web page … thanks) this became possible and we would like you to try mydir.bat should you wish to try it out. Where should you place mydir.bat in order to try it out on Windows? Well, if “mydir” as a command line command, means nothing, at present on your system, it would be best of all to place mydir.bat somewhere in the path (the directories of which can be gleaned from echo %PATH%), but you may not want it that public, and so, just place mydir.bat in the root directory of interest you want information about, if this is your case … in either scenario mydir.bat works after you have used cd [blah blah] to get to the root directory of your interest. For our example scenarios today the [blah blah] equated to the root directories for the local Apache web server of interest … for Windows the root directory of EasyPHP ( “c:Program FilesEasyPHP-12.1www” ) and for Mac the root directory of MAMP ( /Applications/MAMP/htdocs ). More on this happens on this blog at Cassini++ WebServer Primer Tutorial.

So, in summary, try this tutorial for ideas about command line environment solutions to the “Files since …” scenario that many of us often face when using computers … our commands ended up:

  • find . -name “*.htm*” -mtime -7 2> /dev/null # Mac (via Linux Bash via Terminal) NB. Some environments would ask for switch -mtime -7d
  • mydir *.htm* /s /t:w /o:-d /m:-7 rem Windows (via DOS command line)

  • Previous relevant Linux Find and/or Locate Files/Directories Primer Tutorial is shown below.

    Linux Find and/or Locate Files/Directories Primer Tutorial

    Linux Find and/or Locate Files/Directories Primer Tutorial

    Linux (or Unix) servers have two really useful commands which help the user find files and/or directories … locate and find. Doubt there are many people out there who have not mislaid a computer file at some time or other. The GUI options are there, such as Windows Explorer and Mac Finder, but you tend to think, with these, of the one area or folder to search (mind you both are capable of better), whereas you often face the dilemma of having no idea where the file is. The GUIs can help here, but find, for myself, that I always jump to the command line for this, with Windows command line DIR C: [filespec] /s or the Linux/Unix commands for today’s tutorial … locate and find.

    So why confuse things with two choices? Well, locate is fast, once set up, because it sets up its own “database” of previous knowledge, and so can pluck out whatever you want really fast from then on, once you use a “sudo” command to set up locate for future use.

    The strength of the Linux/Unix find command are its switches like “-type ?” to define what type of file to find, and the way you can use “exec” in a piped scenario, to add more functionality.

    So some words about the syntax (and for this, found Linux by Steve Oualline and Eric Foster-Johnson (pp 72-73) an excellent source) where you can hover or click for further information:

    • locate gimp | more -y 13
    • find / -name “*gimp*” -type f -print 2> /dev/null | more -y 13
    • find $HOME/Documents -name “*.htm*” -type f -exec fgrep body {} /dev/null ;

    So today we see some actions to find and/or locate files/directories with this tutorial.

    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>