script to navigate thrugh directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to navigate thrugh directories
# 1  
Old 01-03-2009
Error script to navigate thrugh directories

Hi,

I have a requiremnet where i need to apply logic on directories and sub-direcotories.

Example:

base="/a/b/c"
base1="/a/b/c/d/e"

subfolders in both base and base1 are same : es, ig, os
var1=es
var2=ig
var3=os

Now i have used the follwoing lines in my code and these are creating problem

for dir in "($base | $base1)/$var1" "($base | $base1)/$var2" "($base | $base1)/$var3"

do
(
echo "The current directory is:"`pwd` >> ${LogFile}
cd "$dir" || continue
for i in *.*
do
(
touch "$i" && printf 'Success: %s\n' "$i" || printf 'Failed: %s\n' "$i" >> ${LogFile}
)

done
)
done



Please suggest on the above code .
while executing for loop it is not working.
# 2  
Old 01-03-2009
Hi,

Code:
for dir in a/b/c/{es,ig,os,d/e/{es,ig,os}}/*
do 
  echo $dir
done

should do it.

HTH Chris
# 3  
Old 01-05-2009
Thank you Christoph.

I have used it in script as below. But it did not work for me.

Please suggest.

for dir in "$base"/{"$var1","var2","$var3",d/e/{"$var1","var2","$var3"}/*

touchfiles1.sh[37]: /a/b/c/{es,ig,os,/d/e/{es,ig,os}/*: not found.
# 4  
Old 01-05-2009
There is a closing brace missing.

What my snippet does it iterates through all of your
directories and will print out the files and directories
in them. You should be able to adjust this to your needs.

Perhaps you should describe in greater detail what
you want to achieve. What is your input, what shall
your output be.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to Navigate to Windows Desktop?

I want to use my Desktop for saving files of my codes. Looking for Desktop in my OS (C : ) and couldn't find it anywhere. Is it possible to navigate to your desktop? If so how? By the way, I am using Cygwin. (6 Replies)
Discussion started by: DyslexicChciken
6 Replies

2. UNIX for Dummies Questions & Answers

Need to navigate to HOME directory when I log in

Hi, Currently i'm logging as a user say atgdev. When I login it takes me to directory /. I see the home directory set as /home/atgdev/ I want that when i log in it shud directly go to my home directory i.e /home/atgdev/. I thought .profile in /home/atgdev/ will be invoked first when i log... (9 Replies)
Discussion started by: Gangadhar Reddy
9 Replies

3. Red Hat

Fast yet simple way to navigate directories

If you are like me, typing CD command again and again would quickly get tiresome and wonder there must be a better way to do it. I have done some searching on Google and this forum. The results I get (using alias, CDPATH or PUSHD) do not satisfy me completely, so I decide to do it my way.... (10 Replies)
Discussion started by: IKE0000
10 Replies

4. Shell Programming and Scripting

Script That Can navigate to 3 differents directory & remove files under them

Hi I am Trying to Write a script that can goto 4 different directorys on the server & remove the Files older then 30 days ?? /logs logs1 logs2 logs3 Now I need to remove files under logs1 logs2 logs3 which are older then 30 days whose name stat 'sit' , 'mig','bld' . in... (3 Replies)
Discussion started by: Beginner123
3 Replies

5. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

6. UNIX for Dummies Questions & Answers

How to navigate previous files one by one.

Hi can you tell me if i have opened no of files using vi editior then how can i navigate previous files one by one. Suppose i have opened five files using vi editor as below vi file1 file2 file3 file4 file5 and nom i am in the last file file5 then if i want to go to previous file file 4 and... (5 Replies)
Discussion started by: ajayshukla
5 Replies

7. UNIX for Dummies Questions & Answers

Viewing Directory Content as You Navigate Directories in UNIX

Hi, Can someone help me figure out how to view directory content while I navigate directories (without having to go to the actual directory and "ls-ing" it)? Is there some keyboard shortcut for this? For instance, it would be useful if I could see the content of a directory when I'm copying... (2 Replies)
Discussion started by: shelata
2 Replies

8. Shell Programming and Scripting

How Do I Navigate To A Directory???

I am trying to install some applications, on my linux OS and all the instructions are tell me that ill have to navigate to the directories and type the link that they provide, but i try typing 'dir' which shows me the directories but to access a particular one i can't remember how??? can anyone... (2 Replies)
Discussion started by: kprescod4158
2 Replies

9. UNIX for Dummies Questions & Answers

Can you navigate ABOVE the home directory?

Hello, How do I navigate to the level ABOVE the home directory? I have the following structure on my drive, bearing in my I'm using a cygwin port on Windows. C:\ C:\cygwin C:\cygwin\bin C:\cygwin\otherfolders C:\cygwin\home (the home directory) C:\cygwin\home\H (my user directory) ... (4 Replies)
Discussion started by: patwa
4 Replies

10. UNIX for Dummies Questions & Answers

need to acces unix box thrugh the internet

I have my own PC with linux mandrake 8.2 at home but the problem is that I cant effort the internet connection right now. but at work I had W2k. so if there is any program that allow me to log in unix box and use that program as a terminal for that box. I want to practice the linux code and the... (4 Replies)
Discussion started by: RuDe_BuT_CoOoL
4 Replies
Login or Register to Ask a Question