OmarKN
November 19, 2017, 2:40pm
1
Hi and good day,
This string lets me find the html files:
ls -R /Volumes/LC3/Sites/chu | grep "html"
But how to list the files with their parent dir 'attached' to them:
For example:
n/fofo.html
n/siso.html
m/�
/
Any assistance would be greatly appreciated!
With best regards,
Omar KN
Scott
November 19, 2017, 3:09pm
2
Your question is a little vague. Do you mean only to report the direct parent of the .html file?
Like:
$ find . -name "*.html" | awk -F/ '{print $(NF-1)"/"$NF}'
e.g. a test:
$ mkdir /Volumes/LC3/Sites/chu/a /Volumes/LC3/Sites/chu/a/b /Volumes/LC3/Sites/chu/b
$ touch /Volumes/LC3/Sites/chu/a/a.html \
/Volumes/LC3/Sites/chu/a/b/ab.html \
/Volumes/LC3/Sites/chu/b/b.html
$ find /Volumes/LC3/Sites/chu -name *.html
/Volumes/LC3/Sites/chu/a/a.html
/Volumes/LC3/Sites/chu/a/b/ab.html
/Volumes/LC3/Sites/chu/b/b.html
$ find /Volumes/LC3/Sites/chu -name "*.html" | awk -F/ '{print $(NF-1)"/"$NF}'
a/a.html
b/ab.html
b/b.html
If one wanted to use ls
instead of find
, one might try something like:
BaseDir=/Volumes/LC3/Sites/chu
{ printf '%s:\n' "$BaseDir"
ls -R "$BaseDir"
} | awk -F/ '
/:$/ { Parent = substr($NF, 1, length($NF) - 1) "/"
next
}
/\.html$/ {
print Parent $NF
}'
If you want to try this (or Scott's suggestion) on a Solaris/SunOS system, change awk
to /usr/xpg4/bin/awk
or nawk
.
rbatte1
November 20, 2017, 6:08am
4
I might be missing the point, but would this do?:-
cd /Volumes/LC3/Sites/chu
ls -1 */*.html
There might be an issue of either there are many many files or if the files you seek are not just one directory down.
If this doesn't suit, how about this?:-
cd /Volumes/LC3/Sites/chufind . -name "*.html" | sort # the list from find will be in a seemingly random order
The second option is not perfect because it would show a leading ./
on every line but does that get you near your need?
Robin
Scott
November 20, 2017, 2:58pm
5
Hey, Robin.
My understanding was to find all the .html files under some tree, regardless of where they are within that structure, and show all of them with their parent directory.
Neither of your solutions does quite that (the second one I presume to be a 'cut-and-paste' error, as there's no find in that :)).
rbatte1
November 21, 2017, 4:50am
6
Oh yes, what a mess. The suggestion should have been:-
cd /Volumes/LC3/Sites/chu
find . -name "*.html" | sort # the list from find will be in a seemingly random order
Of course, this may list several directories depth, I'm not sure if that is too much detail or not.