How to read a subfolder one by one in parent folder?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read a subfolder one by one in parent folder?
# 1  
Old 01-08-2009
How to read a subfolder one by one in parent folder?

Hi friends,

I am getting some trubles in folder reading. I am having 10 subfolders inside server7 folder. i wanna to read a subfolder name first and check if the foldername gets started with "http". if so , i need to read a file inside that folder. This willl continue for that 10 folders and quit after read the all subfolders. for the abov e requirement i wrote code like this

for file in /x/y/server/* ;
do
start=`echo $file | cut -d "-" -f 1`
if [ $start == "http" ]
then
cd /x/y/server/$file/config
if [ -f filename ]
then
size=`ls -ltr filename awk '{print $5}' `
if [ $size == 0]
then
echo " The size of $filename is $size . "


here i gave only the fubctionality.

But i am to read very first folder only. I am not able to read rest of the folder.

can anyone help me for this...
Thanks in advance..
# 2  
Old 01-08-2009
1. Use 'find' utility (that seems to be the answer for your question)
2. Imagine a file with name some tricky $name$ with
newline characters

and think how your code would work like... In fact how it would NOT work Smilie
3. Try using high level shell (you have not specified whether this is a HTML document or shell code or whatever) like ksh,bash,zsh,etc. Then provide "magic number" in the first line.
4. If using a high level shell - use [[ ]] instead of [ ]
5. I tend to use ksh with $() in place of `` - think about `ls `cat pattern_file`` (you can do $(ls $(cat pattern_file)) )
6. If using ksh - try using print instead of echo
7. Avoid nested code (someone told me that writing a lot of if's is not a bad thing... but some other man told me to avoid if's whenever possible - the second one gave me a good advice while the first one wasted my time)
8. If you are using a high level shell then try using "${var}",'${var}' instead of what you wrote
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Need help in finishing a bash script for listing subfolder by size in a large folder

Greetings everyone. I have seen that you do wonders here. I have a large folder on a Ubuntu linux. Organization main folder, inside 20 000 subfolders, and inside those subolders many other like 5-6 folders and files. I am interested to create an output to a txt file under the bash... (2 Replies)
Discussion started by: ultimo
2 Replies

3. UNIX for Dummies Questions & Answers

[SOLVED] Copy subfolder to another directory preserving parent name

Hi, I have the following folder structure: Folder6100/Data Folder6100/Data Folder6120/Data Folder6120/Data Folder6140/Data Folder6140/Data Folder6160/Data Folder6160/Data Folder6180/Data Folder6180/Data Folder6200/Data Folder6220/Data Folder6240/Data Folder6260/Data... (2 Replies)
Discussion started by: alex2005
2 Replies

4. Shell Programming and Scripting

List of files in a folder inclusive subfolder

Hi, I need to list the names of existing files in a specific folder. I have written a script for that, but the problem is, it is also picking up name of a subfolder that is there in that folder. I need only the list of files and not that subfolder. How to go about that ? Can anyone plz help... (2 Replies)
Discussion started by: Subhasis
2 Replies

5. UNIX for Dummies Questions & Answers

Grep with parent folder

Hi, When I do ls -l | grep -h STRING I need not only to get those files, but also the parent folder of those files, no idea how do that. BTW the names of those parent folders are never longer than 3 digits, if that helps. Any assistance most welcome, /bw, OmarKN Please... (9 Replies)
Discussion started by: OmarKN
9 Replies

6. Shell Programming and Scripting

Create subfolder within folder in one command

suppose if i am checking folder g as shown below path a/b/c/d/e/f/g ,and some directory c,d,e,f,g not present then is there anyway to create directory in one command or i need to use mkdir for everyfolder (3 Replies)
Discussion started by: lalitpct
3 Replies

7. Shell Programming and Scripting

Link multiple files from different subfolder to a new subfolder

Hi, I have the following subfolder with files: /data/a/1/xxx.txt /data/b/2/yyy.txt /data/c/3/zzz.txt And i have a set of new folders which have exactly the same structure as above but different disk without the files: /data_02/a/1/ /data_02/b/2/ /data_02/c/3/ Now i would like to... (6 Replies)
Discussion started by: total_ysf
6 Replies

8. UNIX and Linux Applications

Samba read only subfolder.

Hi, I need to make a folder read only under a fileshare that has full permissions granted to it. The fileshare with full permissions is /u02/prodfileshare. The folder I need to make read only for everyone except the owner of the folder is called /u02/prodfileshare/EFT/purchases. ... (0 Replies)
Discussion started by: sparcman
0 Replies

9. Solaris

Samba: share subfolder as read only.

Hi, Currently I have a Samba shared configured as follows: comment = Public fileshare path = /u02/pub guest ok = Yes writeable = Yes There is a subfolder under /u02/pub called /u02/pub/expenses/hardware that I need to make read only. How do I do this? I am new to using Samba. ... (2 Replies)
Discussion started by: sparcman
2 Replies

10. Shell Programming and Scripting

Command to view folder subfolder and its capacity

Can any one tell how to view folder and subfolder with its capacity df -k will cannot be used it shows only the parent folder while du -k will show all subfolder and files but not show the capacity and also i dont want view any files Thank you!!!! (1 Reply)
Discussion started by: shivu
1 Replies
Login or Register to Ask a Question