|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All I have two scripts which i used to try and list all the directories one using 'function', which only lists the first directory and does not show directories within directories.
function ListDir () { for arg in $(ls $HOME) do if [ -d $1/$arg ] then echo $arg ListDir $arg fi done } Result home/<username>/ backup bin computer unix oracal There are driectories within 'computer' and 'unix' (prob with loop i think) The other lists, as i want it, but also includes the complete path name which i dont want. i tried using 'for' for arg in `find $HOME -type d -exec ls -d {} \;` do echo $arg >> outputfile done rm outputfile Result /home/<username>/ /home/<username>/backups /home/<username>/bin /home/<usermane>/computer /home/<username>/computer/dept /home/<username/unix /home/<username>/unix/accounts /home/<username>/oracal This goes through a funny loop repeating its self and addidn the new found dir to the end As you can see i just need the last directory I know you can do it so come on help me out thank you Chassis |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
for arg in `find $HOME -type d -exec ls -d {} \;`
do
echo ${arg##/*/}
done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Your the dude
Thanks Andu23, it worked so well my script couldn't even belive it.
Your a star Cheers Chassis |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| List directories and sub directories recursively excluding files | pointers | UNIX for Dummies Questions & Answers | 3 | 02-23-2011 08:39 PM |
| How to list all the directories, sub directories in a mount along with size in ascending order? | nmakkena | Shell Programming and Scripting | 4 | 10-27-2010 02:56 AM |
| Backup script: Copying and removing directories based on list | dotancohen | Shell Programming and Scripting | 4 | 02-04-2010 04:30 PM |
| a remove script taken in input a file which contain a list of directories | yeclota | Shell Programming and Scripting | 2 | 09-09-2008 10:56 AM |
| Script to list changes in Directories | aojmoj | Shell Programming and Scripting | 2 | 11-22-2003 09:51 PM |
|
|