How to fix all files in a directory?

Why is this not working?

find . -maxdepth 1 -type f -print0 | xargs -0 . 

All I get is xargs: .: Permission denied .

+7
source share
2 answers

At startup . file . file you invoke the inline shell . . Your xargs variant is trying to execute the current directory.
Even if it caused an inline, this command is run in a subshell, so all the "sources" will be useless.

Use shell globbing and a loop for this:

 for file in * ; do if [ -f "$file" ] ; then . "$file" fi done 
+13
source

@Mat's solution is the cleanest, but in case you're interested in some bash-fu for fun, this also works based on the original find :

 eval $(find . -maxdepth 1 -type f -exec echo . \'{}\'';' \;) 
  • find used with -exec to create a search command for each file found, for example. . './foo'; . Pay attention to escaped single quotes to ensure that file names with special characters. handled properly.
  • find will return a list of source search commands separated by a newline; using command substitution ( $() ) without the double quote, the shell discards these lines on a single line, using a space as a separator.
  • Finally, eval executes a complete list of search commands in the context of the current shell (tested on OS X 10.8.1).

NOTE. One possible problem with this solution is that the command line can become large - perhaps too large - with many files and / or long file names.

+1
source

All Articles