nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell script that create a blank file in all sub-directories.

This is a discussion on Shell script that create a blank file in all sub-directories. within the Shell scripting forums, part of the Development/Scripting category; Hi All, Can some body write me a script (shell script) which can create a blank test file in all ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2009, 05:04 PM
Junior Member
User
 
Join Date: Sep 2008
OS: RHEL
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
samengr is on a distinguished road
Default Shell 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?

I am using RHEL.

thanks
Reply With Quote
  #2 (permalink)  
Old 02-17-2009, 05:25 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,693
Thanks: 11
Thanked 242 Times in 182 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

No need to write a shell script, simply use the following:
Code:
 find . -maxdepth 5 -empty  -type d | xargs -I currentDir -t touch  currentDir/empty.txt
Above will take dir level upto 5 and xarges command will process each empty directory and will create a file called empty.txt.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 02-17-2009, 07:45 PM
Junior Member
User
 
Join Date: Sep 2008
OS: RHEL
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
samengr is on a distinguished road
Default

Quote:
Originally Posted by nixcraft View Post
No need to write a shell script, simply use the following:
Code:
 find . -maxdepth 5 -empty  -type d | xargs -I currentDir -t touch  currentDir/empty.txt
Above will take dir level upto 5 and xarges command will process each empty directory and will create a file called empty.txt.

============

Thanks for your response. First of I dont know the depth level, it can be 1 and can be 6 or 9/10.

I can get the list of the dirs with the following command

find / -type d -exec ls -d {} \;

$ find test-drs/ -type d -exec ls -d {} \;
test-drs/
test-drs/test
test-drs/test/jami
test-drs/test/vijay
test-drs/dev
test-drs/dev/ben
test-drs/dev/alex/one
test-drs/dev/simon/ian/scott
test-drs/sys
test-drs/sys/din
test-drs/sys/din/khan
test-drs/sys/anu

All i want to create the file in all these subdirectories but the depth level should be dinamic.

I run that commmand you mentioned

[admin@example test-drs]$ find . -maxdepth 5 -empty -type d | xargs -I currentDir -t touch currentDir/empty.txt
xargs: invalid option -- I
Usage: xargs [-0prtx] [-E eof-str] [-e[eof-str]] [-I replace-str]
[-i[replace-str]] [-L max-lines] [-l[max-lines]] [-n max-args]
[-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
[--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
[--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
[--max-args=max-args] [--no-run-if-empty] [--version] [--help]
[command [initial-arguments]]

Report bugs to <bug-findutils@gnu.org>.


[admin@example test-drs]$ find . -maxdepth 5 -empty -type d | xargs -i currentDir -t touch currentDir/empty.txt
xargs: currentDir: No such file or directory

any help?
Reply With Quote
  #4 (permalink)  
Old 02-17-2009, 08:35 PM
Junior Member
User
 
Join Date: Sep 2008
OS: RHEL
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
samengr is on a distinguished road
Default

Well, i got it

find test-dre/ -type d -exec touch {}/test-file \;
Reply With Quote
Reply

Tags
find , find empty directory , linux , pipes , shell pipes , shell scripting , unix , xargs


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
[Solved] Shell script for ftp the file vishal_titre Shell scripting 4 08-21-2009 03:50 PM
Shell Script To Create Network Configuration Murray Shell scripting 4 02-17-2009 05:40 PM
Shell Script To Outputs File Permissions of Most Recently Modified File glen_4455 Shell scripting 1 08-25-2008 02:39 PM
shell script to search specific file from txt file inside zip file and extract it aasif.shaikh Shell scripting 2 05-31-2008 06:44 PM
error shell script no such file or directory /bin/sh Linux software 1 01-08-2006 08:34 PM


All times are GMT +5.5. The time now is 05:34 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38