List all folders and subfolder with bash
I tried to use PHP to read my folder and the subfolder to create a basic menu for me to use, but I noticed when I did that it took some time because it has to run it every time I go to the page.
Then I was thinking, why not use bash and make it create a text file that PHP can read and make it run every night with crontab? So I searched and tried but it was not so easy.
With this code I can get ONE subfolder
for D in /var/www/html/lib/*; do
if [ -d "${D}" ]; then
echo "${D}"
fi
done
it gave me
/var/www/html/lib/folder1
/var/www/html/lib/folder2
/var/www/html/lib/folder3
...
But the folders all have subfolders like
/var/html/lib/folder1/1990
...
My idea was to make a loop and then use
myfolder= "${D}"
addresstoremove="var/www/html/"
printf '%sn' "${myfolder//$addresstoremove/}" >> textfile.txt
so it remove the address I do not need in my PHP code
command-line bash directory
add a comment |
I tried to use PHP to read my folder and the subfolder to create a basic menu for me to use, but I noticed when I did that it took some time because it has to run it every time I go to the page.
Then I was thinking, why not use bash and make it create a text file that PHP can read and make it run every night with crontab? So I searched and tried but it was not so easy.
With this code I can get ONE subfolder
for D in /var/www/html/lib/*; do
if [ -d "${D}" ]; then
echo "${D}"
fi
done
it gave me
/var/www/html/lib/folder1
/var/www/html/lib/folder2
/var/www/html/lib/folder3
...
But the folders all have subfolders like
/var/html/lib/folder1/1990
...
My idea was to make a loop and then use
myfolder= "${D}"
addresstoremove="var/www/html/"
printf '%sn' "${myfolder//$addresstoremove/}" >> textfile.txt
so it remove the address I do not need in my PHP code
command-line bash directory
Usefind. More on stackoverflow.com/a/1767402/5456794
– mja
Dec 26 '18 at 17:34
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54
add a comment |
I tried to use PHP to read my folder and the subfolder to create a basic menu for me to use, but I noticed when I did that it took some time because it has to run it every time I go to the page.
Then I was thinking, why not use bash and make it create a text file that PHP can read and make it run every night with crontab? So I searched and tried but it was not so easy.
With this code I can get ONE subfolder
for D in /var/www/html/lib/*; do
if [ -d "${D}" ]; then
echo "${D}"
fi
done
it gave me
/var/www/html/lib/folder1
/var/www/html/lib/folder2
/var/www/html/lib/folder3
...
But the folders all have subfolders like
/var/html/lib/folder1/1990
...
My idea was to make a loop and then use
myfolder= "${D}"
addresstoremove="var/www/html/"
printf '%sn' "${myfolder//$addresstoremove/}" >> textfile.txt
so it remove the address I do not need in my PHP code
command-line bash directory
I tried to use PHP to read my folder and the subfolder to create a basic menu for me to use, but I noticed when I did that it took some time because it has to run it every time I go to the page.
Then I was thinking, why not use bash and make it create a text file that PHP can read and make it run every night with crontab? So I searched and tried but it was not so easy.
With this code I can get ONE subfolder
for D in /var/www/html/lib/*; do
if [ -d "${D}" ]; then
echo "${D}"
fi
done
it gave me
/var/www/html/lib/folder1
/var/www/html/lib/folder2
/var/www/html/lib/folder3
...
But the folders all have subfolders like
/var/html/lib/folder1/1990
...
My idea was to make a loop and then use
myfolder= "${D}"
addresstoremove="var/www/html/"
printf '%sn' "${myfolder//$addresstoremove/}" >> textfile.txt
so it remove the address I do not need in my PHP code
command-line bash directory
command-line bash directory
edited Dec 26 '18 at 18:10
wjandrea
8,47842259
8,47842259
asked Dec 26 '18 at 16:57
CazzCazz
233
233
Usefind. More on stackoverflow.com/a/1767402/5456794
– mja
Dec 26 '18 at 17:34
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54
add a comment |
Usefind. More on stackoverflow.com/a/1767402/5456794
– mja
Dec 26 '18 at 17:34
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54
Use
find. More on stackoverflow.com/a/1767402/5456794– mja
Dec 26 '18 at 17:34
Use
find. More on stackoverflow.com/a/1767402/5456794– mja
Dec 26 '18 at 17:34
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54
add a comment |
1 Answer
1
active
oldest
votes
find /var/www/html/lib/ -type d
or
find /var/www/html/lib/ -type d >> file.txt
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
@Cazz search on piping output tosortcommand.
– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1104695%2flist-all-folders-and-subfolder-with-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
find /var/www/html/lib/ -type d
or
find /var/www/html/lib/ -type d >> file.txt
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
@Cazz search on piping output tosortcommand.
– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
add a comment |
find /var/www/html/lib/ -type d
or
find /var/www/html/lib/ -type d >> file.txt
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
@Cazz search on piping output tosortcommand.
– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
add a comment |
find /var/www/html/lib/ -type d
or
find /var/www/html/lib/ -type d >> file.txt
find /var/www/html/lib/ -type d
or
find /var/www/html/lib/ -type d >> file.txt
edited Dec 26 '18 at 17:38
answered Dec 26 '18 at 17:35
VijayVijay
1,463618
1,463618
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
@Cazz search on piping output tosortcommand.
– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
add a comment |
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
@Cazz search on piping output tosortcommand.
– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
Dec 26 '18 at 18:57
2
2
@Cazz search on piping output to
sort command.– WinEunuuchs2Unix
Dec 26 '18 at 19:17
@Cazz search on piping output to
sort command.– WinEunuuchs2Unix
Dec 26 '18 at 19:17
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
find /var/www/html/lib/ -type d | sort >> file.txt
– user1330614
Dec 27 '18 at 2:56
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1104695%2flist-all-folders-and-subfolder-with-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use
find. More on stackoverflow.com/a/1767402/5456794– mja
Dec 26 '18 at 17:34
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
Dec 27 '18 at 0:54