Subject: Can't make a list of Directories since some names contain spaces.
I would like to make a list of all directories in a parent directory.
Code:
mkdir -p ee/{"unit 1","unit 2","unit 3","unit 4"} So I now attempt to make a list of these directories whose names contain spaces. Attempt01: Code:
$ DIRList=$(find ee/* -type d) Attempt02: Code:
ls -1a ee Attempt03: Code:
$ ls -d ee/* Attempt04: Code:
ls -l ee/ | grep ^d Is there anyway of making a list of all DIR, including ones whose DIR names include spaces? |
Lots of options
1) Don't store the output of ls in an intermediate variable, just pipe it straight to wc 2) Use the "-1" flag in ls 3) Use the print0 flag in find to print out the names with null terminators, then use the files0-from flag in wc to read it properly I'm sure there are many more |
You know wc -w is times 2 because of split dir names so just do the math ;)
Code:
userx%voider ⚡ testDIR ⚡> echo $(($(ls ./ee | wc -w ) / 2)) Code:
userx%voider ⚡ testDIR ⚡> dirlist=$(($(find ./ee -type d | wc -w) / 2 )) Code:
userx%voider ⚡ testDIR ⚡> dirlist=$(find ./ee -type d) Code:
good morning userx Code:
$ DIRList=$(find ee/* -type d) |
@OP: What do you actually want to accomplish? What is your real goal?
|
If you want an answer in Perl, I'll write one. But I'm not going to waste time to make one if you're just going to say you don't like Perl or something (like so many have to me in the past).
|
Quote:
Code:
$ find . -type d |
Quote:
Code:
mkdir -pv ee/{"unit 1","unit 2","unit 3","unit 4"} Code:
find `pwd` -type d -name "unit [1234]" Code:
/home/jj/ee/unit 4 Code:
dirlist=$(find `pwd` -type d -name "unit [1234]") Code:
echo "$dirlist" 4 here. See also http://mywiki.wooledge.org/BashPitfalls. |
Quote:
Code:
find parentdir -type d | wc -l I get the feeling he may end up wanting more done though... |
TO Expand on @Habitual line of thought,
if you do not know the names of the said dir. Code:
userx%slackwhere ⚡ testDIR ⚡> DL=$(find `pwd` -type d -name "[A-Za-z]* [0-9]") |
Purpose
Quote:
|
previously attempted
Quote:
|
thanks!!
Quote:
|
actually the spaces do effect something else
Quote:
Unfortunately, when making a "list", the spaces for this purpose, the spaces end up breaking the list up. |
It's a lot easier just to let the find command do the work an not have to worry about how the shell will parse the resulting list.
Code:
find AC -type d -exec chmod 700 {} \; |
Quote:
use find(1): http://www.linuxquestions.org/questi...0/#post5707388 |
All times are GMT -5. The time now is 11:59 PM. |