script that create a blank file in all sub-directories.
Hi All,
Can some body write me a script (shell script) which can create a blank test file in all sub-directories upto 5-6 levels? thanks |
Code:
for name in $(find path_to_base_dir -type d); do |
No need for a script or a loop...
Code:
find . -maxdepth 5 -type d -exec touch {}/testfile \; |
Moin,
no need for a bunch of processes ;-) Code:
find . -maxdepth 5 -type d -printf ">'%p/testfile'\n" | sh |
Quote:
I'm impressed Jan. That's some excellent efficiency going on there. However... ...sooner or later, some nasty git would come along and do something evil like... Code:
mkdir evildir\'\;rm\ something_important\;\# |
Jan,
That is impressive, never thought about it. But how comes you say you don't create additional processes? I think for each line 'find' produces, one shell process is started and killed again. jlinkels |
Moin,
no, the -exec creates a new process for each line, not the -printf. The shell behind the pipe is one process, it gets a list of output redirects, no external programs. It's the same as you would write the lines on a shell prompt. Jan |
Moin,
Quote:
IMHO there is no 100% protection - may be, the -print0 find option together with xargs -0 is safe - at least it's more difficult to trick, but also more difficult to use in this case :-) Jan |
Quote:
Hans |
All times are GMT -5. The time now is 09:19 PM. |