I did one of these threads several months ago, when the site was new, and thought now was a good time to do another.

Message me if you

  • Want to try installing Linux for the first time
  • Want to try Linux but don't want to install it
  • Have some Linux-related problem you want another pair of eyeballs on
  • Want to learn a programming language
  • Want to build a computer
  • Want tutoring in any of the above
  • Need help with any old technical problem

(also play Arma with me)

  • Bloodshot [he/him,any]
    hexagon
    ·
    4 years ago

    Sorry if this is too technical.

    lol this is my wheelhouse.

    chmod, as well as a lot of other commands, support recursively operating on a path themselves; chmod -R.

    More generally, I'd recommend using find -exec (man find), which you can pass flags to filter what you want (e.g. -type f for only files).

    While most commands expect a list of files to operate on as their arguments and not in stdin, xargs transforms lines from stdin to command line arguments.

    In simple cases, you can use a shell for loop as follows:

    for file in directory/* ; do
      echo "$file"
      do_something "$file"
    done
    

    I wouldn't recommend ever using ls in scripts; it's made to output human-readable text and not something that a script can reliably parse (think of edge cases like a filename with embedded newlines).