Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Listing directories and sub directories Post 302340318 by qasim on Monday 3rd of August 2009 07:58:47 AM
Old 08-03-2009
Listing directories and sub directories

Hi,
I am trying to get the following output:
-(0)
/home/<user-name>-(1)
..........a-(2)
....................codetest-(3)
..............................oracle-(4)
..............................unix-(5)
........................................dir1-(6)
....................meum-(7)
....................oracle-(8)
..............................plcourse-(9)
..............................sqlcourse-(10)
........................................exercises-(11)
..................................................chapter10-(12)
..................................................chapter11-(13)
..................................................chapter12-(14)

The example above shows that directly under the home directory, there is a single directory ‘a’ which contains ‘codetest’, ‘meum’ and ‘oracle’. Under ‘codetest’ there is ‘oracle’ and ‘unix’.
and I am using the following code:
Code:
#!/bin/bash

function subDirect ()
{
        s=$1
        found=($(ls $s))
        arraySiz=${#found[@]}
        a=0
        count=0
        while [ $a -lt $arraySiz ]
        do
                if [ $arraySiz -eq 1 ]
                then
                        echo $s
                else
                        echo $s
                        cd $s
                        subDirect ${found[a]}

                        cd ..
                fi
        let a=a+1
        done
}

i=0
BOpen="-("
BClose=")"
user=$(whoami)
echo $BOpen $i $BClose
let i=i+1
echo "/home/"$user $BOpen $i $BClose
let i=i+1
dir=$(ls ~)
subDir=($dir)
arraySize=${#subDir[@]}
x=0
while [ $x -lt $arraySize ]
do
 subDirect "${subDir[x]}"
let x=x+1
done

################
When the recursion takes place in function subDir, it doesn't restore the previous values after coming out.e.g
if it has found and displayed the dir1-(6) from the desired output, it will not regain the values of unix(5) or codetest(3)..
Can anybody help please.
Regards,
Qasim

Last edited by qasim; 08-04-2009 at 06:23 AM.. Reason: indent
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

files and directories listing

Hello: I need to list some files into some directories ordered by size. i need help! BEst regards Alberto (1 Reply)
Discussion started by: bbolson
1 Replies

2. UNIX for Dummies Questions & Answers

Listing directories and ${1:+$1/}*

Hi I have 2 questions: Q1 - What does ${1:+$1/}* mean? I guess it lists all files in current directory - Could any one explain how this expression works? Q2 - I am trying to list directories only in current path - I know that ls could be used but I thought I'd give find a try. I need to... (5 Replies)
Discussion started by: GMMike
5 Replies

3. UNIX for Dummies Questions & Answers

Listing Unique directories.

Hi, Simple question. If i could find a file been listed in many dirctories, how to get the unique list of directories. find / -name "abc*" --> will give me list of directories. /home/abc.txt /home/ddd/abcd.txt /home/ddd/abcde/txt So how to get /home /home/ddd Thanks in... (2 Replies)
Discussion started by: deepakwins
2 Replies

4. UNIX for Advanced & Expert Users

Listing directories and sub directories

Hey there, i am trying to list all the directories and sub directories of a file system, but am having a bit of trouble. ls -lR|grep \/|grep '^\.' >> input.dat i used this statement to list all the directories and sub directories and output them to a file when i try to print them out on... (3 Replies)
Discussion started by: jinxor
3 Replies

5. UNIX for Advanced & Expert Users

listing of directories with / ...not to use ls -F

Hi When im listing (ls -al ) its listing directories without / at the end of directories dir1 dir2 dir3 and i need to list directories with dir1/ dir2/ dir3/ and this should not be made by command ls -F / should be embedded at the last since one of the scripts reads directories... (1 Reply)
Discussion started by: vasanthan
1 Replies

6. UNIX for Dummies Questions & Answers

listing of directories with / at end...without ls -F

Hi When im listing (ls -al ) its listing directories without / at the end of directories dir1 dir2 dir3 and i need to list directories with dir1/ dir2/ dir3/ and this should not be made by command ls -F / should be embedded at the last since one of the scripts reads... (10 Replies)
Discussion started by: vasanthan
10 Replies

7. Shell Programming and Scripting

listing directories alone

ls lists all files and sub directories in the current directory but how to list only the sub directories and not the files? (2 Replies)
Discussion started by: bbala
2 Replies

8. Shell Programming and Scripting

Listing non empty directories

Hi Gurus, How to list directories that are non-empty and non-hidden Thanks in advance (2 Replies)
Discussion started by: kinny
2 Replies

9. Shell Programming and Scripting

listing directories and sub directories with time and name options

Hello all! I'm looking to list directories and sub-directories of a path, on this forum I found this command: find $path -type d -exec ls -ld {} \; The issue I have is that with a simple ls, the list is listed by name, and using -t I get it by time. How could I list directories and sub... (5 Replies)
Discussion started by: nomadvisuals
5 Replies

10. Shell Programming and Scripting

listing directories with more than x files

How can I find and print the directories on a server that have more than 5,000 files? There's some spam emails and I'm trying to find all directories that have a lot of spam The file count should just be the files directly under that directory, not like the total from all nested directories ... (1 Reply)
Discussion started by: vanessafan99
1 Replies
check-permissions(1M)					  System Administration Commands				     check-permissions(1M)

NAME
check-permissions - check permissions on mail rerouting files SYNOPSIS
/usr/sbin/check-permissions [login] DESCRIPTION
The check-permissions script is intended as a migration aid for sendmail(1M). It checks the /etc/mail/sendmail.cf file for all configured alias files, and checks the alias files for :include: files. It also checks for certain .forward files. For each file that check-permis- sions checks, it verifies that none of the parent directories are group- or world-writable. If any directories are overly permissive, it is reported. Otherwise it reports that no unsafe directories were found. As to which .forward files are checked, it depends on the arguments included on the command line. If no argument is given, the current user's home directory is checked for the presence of a .forward file. If any arguments are given, they are assumed to be valid logins, and the home directory of each one is checked. If the special argument ALL is given, the passwd entry in the /etc/nsswitch.conf file is checked, and all password entries that can be obtained through the switch file are checked. In large domains, this can be time-consuming. OPERANDS
The following operands are supported: login Where login is a valid user name, checks the home directory for login. ALL Checks the home directory of all users. FILES
/etc/mail/sendmail.cf Defines environment for sendmail /etc/mail/aliases Ascii mail aliases file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsndmu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
getent(1M), sendmail(1M), aliases(4), attributes(5) SunOS 5.11 10 Nov 2003 check-permissions(1M)
All times are GMT -4. The time now is 06:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy