Results 1 to 4 of 4

Thread: How can I run multiple commands at once to restrict results?

  1. #1
    Join Date
    Jul 2014
    Location
    Somewhere in Portugal
    Beans
    48
    Distro
    Xubuntu

    How can I run multiple commands at once to restrict results?

    Sorry if this a stupid question, but I'm trying to find a file that is human readable, not an executable and 1033 bytes in size. The file is inside a directory with sub directories, and I don't know in which sub directory it is. I was thinking about using du for file size, and file for file type but after lots of googling couldn't find how to do it with them together and the correct options. Any ideas?

  2. #2
    Join Date
    Nov 2008
    Location
    S.H.I.E.L.D. 6-1-6
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: How can I run multiple commands at once to restrict results?

    Code:
    find -type f -size 1033c -exec grep -Il . {} \;
    Breakdown:
    -type f only search files
    -size 1033c set size (c for bytes, k for kilobytes, M for megabytes, G for gigabytes)
    -exec grep -Il only non-binaries
    . search using current directory as top level
    Last edited by sandyd; May 17th, 2015 at 11:17 PM.
    Don't waste your energy trying to change opinions ... Do your thing, and don't care if they like it.

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: How can I run multiple commands at once to restrict results?

    It depends a bit what you mean by "human readable" - you could use a combination of the `find` and `mimetype` commands

    Code:
    find path/to/dir -type f -size 1033c -exec sh -c 'mimetype "$1" | grep -q text' _ {} \; -print

  4. #4
    Join Date
    Jul 2014
    Location
    Somewhere in Portugal
    Beans
    48
    Distro
    Xubuntu

    Re: How can I run multiple commands at once to restrict results?

    Thanks I got it now!

Tags for this Thread

Bookmarks

Posting Permissions

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