Dumb Q

  • What's the proper way to make a C/ObjC program (Foundation tool)
    be used with the pipe operator? I want to make a simple filter that
    takes the output of "ls -la" and reformats it to appear more like the
    MS-DOS directory listing. So, I would do something like "ls -la |
    mydosfilter" and get a directory listing with the filename first, the
    # bytes second, then the timestamp (leaving out everything from the
    UNIX permissions bits to the group, and rearranging the rest.)
      Also, what's the proper place to put the resulting executable so
    all users can use it in Terminal.App without having to do "ls -la |
    <path to mydosfilter>" every time. Can I put this in the deployment
    target once the linker is done? Do I need "sudo" to copy there? I
    know just enough tcsh stuff to be dangerous... :)
      Finally, what's the number just after the UNIX permissions bits?
    the PID?
  • On 6 Aug 2008, at 15:57, William Squires wrote:

    > What's the proper way to make a C/ObjC program (Foundation tool) be
    > used with the pipe operator? I want to make a simple filter that
    > takes the output of "ls -la" and reformats it to appear more like
    > the MS-DOS directory listing. So, I would do something like "ls -la
    > | mydosfilter" and get a directory listing with the filename first,
    > the # bytes second, then the timestamp (leaving out everything from
    > the UNIX permissions bits to the group, and rearranging the rest.)

    Just read input from standard in, and write output to stardard out.

    > Also, what's the proper place to put the resulting executable so
    > all users can use it in Terminal.App without having to do "ls -la |
    > <path to mydosfilter>" every time. Can I put this in the deployment
    > target once the linker is done? Do I need "sudo" to copy there? I
    > know just enough tcsh stuff to be dangerous... :)

    Anywhere on your $PATH variable.  Usually /usr/local/bin or /usr/bin

    > Finally, what's the number just after the UNIX permissions bits?
    > the PID?

    From man ls...
          If the -l option is given, the following information is
    displayed for
          each file: file mode, number of links, owner name, group name,
    number of
          bytes in the file, abbreviated month, day-of-month file was last
    modi-
          fied, hour file last modified, minute file last modified, and
    the path-
          name.  In addition, for each directory whose contents are
    displayed, the
          total number of 512-byte blocks used by the files in the
    directory is
          displayed on a line by itself, immediately before the
    information for the
          files in the directory.  If the file or directory has extended
          attributes, the permissions field printed by the -l option is
    followed by
          a '@' character.  Otherwise, if the file or directory has
    extended secu-
          rity information, the permissions field printed by the -l option
    is fol-
          lowed by a '+' character.
  • Am Mi,06.08.2008 um 15:57 schrieb William Squires:

    > What's the proper way to make a C/ObjC program (Foundation tool) be
    > used with the pipe operator? I want to make a simple filter that
    > takes the output of "ls -la" and reformats it to appear more like
    > the MS-DOS directory listing. So, I would do something like "ls -la
    > | mydosfilter" and get a directory listing with the filename first,
    > the # bytes second, then the timestamp (leaving out everything from
    > the UNIX permissions bits to the group, and rearranging the rest.)
    On UNIX the pipe-in is the stdin., the pipe-out the stdout. So you can
    just read from stdin to get the data piped and write it to stdout.
    (TAKE CARE ABOUT THE SIZE OF CHAR-ARRAYS! *g*)

    I think, that this is c-standard …

    > Also, what's the proper place to put the resulting executable so
    > all users can use it in Terminal.App without having to do "ls -la |
    > <path to mydosfilter>" every time. Can I put this in the deployment
    > target once the linker is done? Do I need "sudo" to copy there? I
    > know just enough tcsh stuff to be dangerous... :)
    > Finally, what's the number just after the UNIX permissions bits?
    > the PID?
    A file does not have a PID!?!

    man ls:
      The Long Format
          If the -l option is given, the following information is
    displayed for each file: file mode, number of
          links, owner name, group name, number of bytes in the file,
    abbreviated month, day-of-month file was
          last modified, hour file last modified, minute file last
    modified, and the pathname.  In addition, for
          each directory whose contents are displayed, the total number of
    512-byte blocks used by the files in
          the directory is displayed on a line by itself immediately
    before the information for the files in the
          directory.  If the file or directory has extended security
    information, the permissions field printed
          by the -l option is followed by a '+' character.

    Amin



    Amin Negm-Awad
    <negm-awad...>
  • > I want to make a simple filter that takes the output of "ls -la" and
    > reformats it to appear more like the MS-DOS directory listing. So, I
    > would do something like "ls -la | mydosfilter" and get a directory
    > listing with the filename first, the # bytes second, then the
    > timestamp (leaving out everything from the UNIX permissions bits to
    > the group, and rearranging the rest.)

    Why don't you simply add an alias named "dir" to a global bashrc file
    that translates to something like this: ls -la | awk '{ print $9"\t
    \t"$5"\t"$6,$7,$8 }'
    This simply outputs the file name, two tabs, the size in bytes, a tab
    and then the date & time. I'm no awk expert, maybe this could be done
    prettier.

    Marco
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today