How to list directory and subdirectory?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to list directory and subdirectory?
# 1  
Old 02-20-2010
How to list directory and subdirectory?

Hi,

I want to list all the directory and subdirectories under any directory.

For eg. i am in a directory called A and want to check all directories under A.
Output should be as below.
/A
/A/a1
/A/a1/a2
/A/b1
/A/c1/c2

A,a1,a2,b1,c1 and c2 all are directories.Just for Eg.

Please can any one help me to find me the O/P.
# 2  
Old 02-20-2010
Code:
find ./ -type d

# 3  
Old 02-20-2010
I used the following line of code in Ubuntu ksh, but it should also work on Solaris ksh:

Code:
find <your starting directory> -ls |  grep " d" | tr -s [:space:] | cut -d " " -f11

# 4  
Old 02-20-2010
I don't think any thing but the 'find' command is needed here.
# 5  
Old 02-21-2010
Wow ..!! Thanks ..it worked ...
find ./ -type d --> exactly gave me the O/P what I wanted ..
second command gave me list of files also ...

if i want this through a script ...what will be my shell script..?any guidance. ..!!?
# 6  
Old 02-21-2010
find is program, so you can call it almost from every interpreters like shells, perl, php, ... What you need ?
# 7  
Old 02-21-2010
hey ..thanks ..!!
I have created one script.. Actually I am new in scripting.
below is my script

Code:
#!/bin/ksh
first_argument="$1"
second_argument="$2"
third_argument="$3"
find $1 -type d >> $2
scp -p -r $2 anshu@server1:/tmp/anshu/

Suppose .. $1 is my home directory and $2 is an O/P file.
$1= /home/anshu $2= /tmp/anshu.out
Now this script is working well and it is creating anshu.out on remote machine server1.
But now actually I want to create same directory structure om remote machine under path /tmp/anshu/ from script.

Could you please assist me.... what will be my I/P?

Last edited by Scott; 02-21-2010 at 08:46 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching File in Directory and all Subdirectory and Delete

Hi All, My directory structure is like Directory1 SubDirectory1 SubDirectory2 SubDirectory3 I have main directories and subdirectories underneath. I want to write a shell script where I will be passing file name as a parameter, Now I want to find all the files in Directory1... (19 Replies)
Discussion started by: John William
19 Replies

2. UNIX for Advanced & Expert Users

Make a subdirectory the root directory

I have a series of configuration files to deliver to multiple unix environments (dev, test, bench, prod etc). However I don't to modify them for each environment. The files are text which currently contain this type of directory information IN=/DVT/ms/sas/reception/PIL_QPA_SID/GSPIN001... (5 Replies)
Discussion started by: clarcombe
5 Replies

3. Shell Programming and Scripting

Remove all files except the subdirectory(without pattern) in a directory

I used rm * and it deleted the files in the directory but gives and error message for unsuccessful subdirectory deletion. "rm: cannot remove 'DirectoryName': Is a directory" I dont want to explicitly get the above error. What are the modifications I have to do in the rm command? (3 Replies)
Discussion started by: duplicate
3 Replies

4. Shell Programming and Scripting

Globbling files in the direct subdirectory of the current directory

I want to list files that end with .c in the direct subdirectory of the current directory. I have tried the following command: find ./ -mindepth 2 -maxdepth 2 -name "*.c" Is that right? Or is there any easier way to handle that problem? Another problem is that I want to grep in a file to find... (5 Replies)
Discussion started by: Ray Sun
5 Replies

5. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46 Any ideas how can we do this? :wall: (1 Reply)
Discussion started by: jakerock
1 Replies

6. UNIX for Dummies Questions & Answers

How to move all files in a directory and subdirectory?

I'm trying to organize my MB Pro by moving all my jpeg files to a single folder from the desktop. There are some on the desktop that are not in any folder. I was at the command line and typed mv *.jpg "Jpeg files" but it only moved the files that were on the desktop, not any of the ones that... (3 Replies)
Discussion started by: Straitsfan
3 Replies

7. Shell Programming and Scripting

Sum of file size in directory / subdirectory

Hi , I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level .. #!/bin/ksh FNAME='.pdf' S_PATH=/abc/def/xyz find $S_PATH -exec ls -lad... (4 Replies)
Discussion started by: Vaddadi
4 Replies

8. Shell Programming and Scripting

Find command, -name by directory and subdirectory?

Hi All, I'm trying to use the find command to return matches for a directory and file. For example, given the following directories: /one/two/three/file1.txt /one/three/two/file1.txt /one/four/two/three/file1.txt I'm expecting the following to be returned: ... (16 Replies)
Discussion started by: makodarear
16 Replies

9. Shell Programming and Scripting

Find files in directory and its subdirectory

I am writing a script which reads a file line by line and then assigns it to a variable like this 1090373422_4028715212.jpg. I have images with file name of this format in some other directory. In my script I want to assign variable with this file name and then find this filename in some other... (11 Replies)
Discussion started by: jyotib
11 Replies

10. Shell Programming and Scripting

How to calculate file's size in directory and subdirectory

Hi, I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine. Now, I've been trying to calculate all files which includes files in any subdirectories. I use recursive function to do this, but it can work only if there is only one... (4 Replies)
Discussion started by: KLL
4 Replies
Login or Register to Ask a Question