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
New contributor
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
New contributor
Usefind
. More on stackoverflow.com/a/1767402/5456794
– mja
7 hours ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago
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
New contributor
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
New contributor
New contributor
edited 6 hours ago
wjandrea
8,26842259
8,26842259
New contributor
asked 7 hours ago
Cazz
232
232
New contributor
New contributor
Usefind
. More on stackoverflow.com/a/1767402/5456794
– mja
7 hours ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago
add a comment |
Usefind
. More on stackoverflow.com/a/1767402/5456794
– mja
7 hours ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago
Use
find
. More on stackoverflow.com/a/1767402/5456794– mja
7 hours ago
Use
find
. More on stackoverflow.com/a/1767402/5456794– mja
7 hours ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago
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
6 hours ago
1
@Cazz search on piping output tosort
command.
– WinEunuuchs2Unix
5 hours ago
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
});
}
});
Cazz is a new contributor. Be nice, and check out our Code of Conduct.
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
6 hours ago
1
@Cazz search on piping output tosort
command.
– WinEunuuchs2Unix
5 hours ago
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
6 hours ago
1
@Cazz search on piping output tosort
command.
– WinEunuuchs2Unix
5 hours ago
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 7 hours ago
answered 7 hours ago
Vijay
1,335617
1,335617
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
6 hours ago
1
@Cazz search on piping output tosort
command.
– WinEunuuchs2Unix
5 hours ago
add a comment |
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
6 hours ago
1
@Cazz search on piping output tosort
command.
– WinEunuuchs2Unix
5 hours ago
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
6 hours ago
Hmm nice easy code, like that alot but have the problem that it does not list in alphabetical order
– Cazz
6 hours ago
1
1
@Cazz search on piping output to
sort
command.– WinEunuuchs2Unix
5 hours ago
@Cazz search on piping output to
sort
command.– WinEunuuchs2Unix
5 hours ago
add a comment |
Cazz is a new contributor. Be nice, and check out our Code of Conduct.
Cazz is a new contributor. Be nice, and check out our Code of Conduct.
Cazz is a new contributor. Be nice, and check out our Code of Conduct.
Cazz is a new contributor. Be nice, and check out our Code of Conduct.
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
7 hours ago
Possible duplicate askubuntu.com/q/307876/295286
– Sergiy Kolodyazhnyy
3 mins ago