TL;DW

# find with grep
# + concatinates results and runs the command once, faster
find . -name "*.txt" -exec grep -l "somename" '{}' '+'

# run a command for each result individually
find . -name "*.txt" -exec basename '{}' \';' |  column

# case insensitive
find -iname "SoMeNaMe.TxT

# file or dir
find -type f
find -type d

# define file owner
find -user Bob

# define file group
find -group wheel

# by permission
find -perm 777

# find by size
find -size +1G
  • @[email protected]
    link
    fedilink
    546 months ago

    grep -r exists and is even more faster and doesn’t require passing around file names.

    grep -r --include='*.txt' 'somename' .
    
    • fmstrat
      link
      fedilink
      3
      edit-2
      6 months ago

      Or use strings if you want clean binary results. (Grep can probably do this, too)

      Edit: Yes, with -b, also -R follows symlinks unlike -r

  • @[email protected]
    link
    fedilink
    116 months ago

    I kinda prefer xargs to the -exec option — just feels more UNIXy to me (do one one job well).

    But as another comment said, for grep I just use -r and --include. So clearly I’m not very consistent…

    • @[email protected]OP
      link
      fedilink
      26 months ago

      It is important to have backups for when Youtube blocks clients, but I just watch it over a VPN and Freetube or Grayjay. Not leeching any resources when avoidable, just costing big brother money.

      • Fonzie!
        link
        fedilink
        16 months ago

        You’re giving all your data to your VPN company, though

          • Fonzie!
            link
            fedilink
            16 months ago

            And give no personal information? Like Mullvad? That is an improvement.

            • @[email protected]OP
              link
              fedilink
              1
              edit-2
              6 months ago

              Yup. Also their VPN app on Linux is better than what KDE and GNOME have. Poorly. They hook into it very intensely, early boot blocking via a systemd service and all.

  • @[email protected]
    link
    fedilink
    66 months ago

    She’s done such a good job with this channel. I understand most of the content, but I always pick up a nugget of new as well as being able to better explain after a topic she ELI5’d

  • unalivejoy
    link
    fedilink
    English
    6
    edit-2
    6 months ago

    If you have a very large directory, find will check each individual file, even when -path doesn’t match, which makes it take longer to complete. Combine -o and -prune to omit them entirely.

    find . -path '**/node_modules/**' -prune -o -type f -name '*.js' -exec grep 'import' {} +
    
  • Dave
    link
    56 months ago

    Forgive me for only TLDW and not watching, but was ack mentioned?

    I’ve never looked back.

  • @dohpaz42
    link
    English
    46 months ago

    When using both {} and ;, it’s safer to use single quotes to escape the current argument and ending delimiter; eg {} and ;’, respectively.

    • @[email protected]
      link
      fedilink
      36 months ago

      Why? The quotes will be consumed by the shell when you execute the command, unless you do like "'{}'"

      • @dohpaz42
        link
        English
        1
        edit-2
        6 months ago

        Short answer: shell expansion.

        Longer answer:

        Executing a command for each file

        • Run file on every file in or below the current directory.

        $ find . -type f -exec file '{}' \;

        Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also.