help with bash script
I need to write a script that would take in a path to the folder and list all the subdirectories of that folder.
However, it should not list folders named private. So far I have come up with this code Code:
#!/bin/bash The another issue is that at the moment it works only if i enter the full path to the folder. I would prefer it it worked with relative paths also. I would appreciate your help. |
Hints:
pwd gets you the path to the current directory - relative paths do not have the leading / A subdirectory and a sub-folder are the same thing. folder == directory. |
hi,
If u just want to list the directories under one folder just try the below command... It ahould help u.. find ./* -type d ! -name private | awk -F'/' '{ print $2 }' | uniq -c | grep -v private |
Works for me:
Code:
~$ ./test.sh xpmnt Edit: Maybe I misunderstood what you were asking. Do you only want the immediate subdirectories of the one you're looking at? If so use -maxdepth 1 as an option to find. |
The "find" commands shown above don't print a directory called "private", but descend into it. I think that's why vjayraghavan post-processes the output through "grep -v private".
But :study: man find -- "To ignore a directory and the files under it, use -prune". |
exactly quigi...
The find command will just not find private directory but it prints all the files and directories under it... |
All times are GMT -5. The time now is 02:43 AM. |