List directoties down one level, excluding some named directories and files
I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
Imagine a folder structure like this. CAPS are folders.
FOLDER 1
.hidden
TEMP
somefile
=========
=========
FOLDER 2
.hidden
TEMP
DATA1
DATA2
somefile
========
========
FOLDER 3
.hidden
TEMP
DATA1
somefile
I would like to run "insert magic command here" and end up with an output that looks like below
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
bash shell-script
add a comment |
I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
Imagine a folder structure like this. CAPS are folders.
FOLDER 1
.hidden
TEMP
somefile
=========
=========
FOLDER 2
.hidden
TEMP
DATA1
DATA2
somefile
========
========
FOLDER 3
.hidden
TEMP
DATA1
somefile
I would like to run "insert magic command here" and end up with an output that looks like below
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
bash shell-script
add a comment |
I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
Imagine a folder structure like this. CAPS are folders.
FOLDER 1
.hidden
TEMP
somefile
=========
=========
FOLDER 2
.hidden
TEMP
DATA1
DATA2
somefile
========
========
FOLDER 3
.hidden
TEMP
DATA1
somefile
I would like to run "insert magic command here" and end up with an output that looks like below
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
bash shell-script
I want to send a list of all folders including one level down to a txt file. Excluding some named folders and no files.
Imagine a folder structure like this. CAPS are folders.
FOLDER 1
.hidden
TEMP
somefile
=========
=========
FOLDER 2
.hidden
TEMP
DATA1
DATA2
somefile
========
========
FOLDER 3
.hidden
TEMP
DATA1
somefile
I would like to run "insert magic command here" and end up with an output that looks like below
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
bash shell-script
bash shell-script
edited Dec 16 at 4:15
Rui F Ribeiro
38.9k1479129
38.9k1479129
asked Oct 11 '15 at 22:01
GTM
184
184
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I did this to create your folder structure:
for f in FOLDER 1 FOLDER 2 FOLDER 3
do mkdir -p "$f/TEMP"
touch "$f/.hidden" "$f/somefile"
case "$f" in
(*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
(*3) mkdir -p "$f/DATA1/TEMP"
esac
done
That created a tree like:
find .
.
./FOLDER 1
./FOLDER 1/TEMP
./FOLDER 1/.hidden
./FOLDER 1/somefile
./FOLDER 2
./FOLDER 2/TEMP
./FOLDER 2/.hidden
./FOLDER 2/somefile
./FOLDER 2/DATA1
./FOLDER 2/DATA1/TEMP
./FOLDER 2/DATA2
./FOLDER 2/DATA2/TEMP
./FOLDER 3
./FOLDER 3/TEMP
./FOLDER 3/.hidden
./FOLDER 3/somefile
./FOLDER 3/DATA1
./FOLDER 3/DATA1/TEMP
And last I did...
find . ! -path './*/*/*' ! -name TEMP -type d
.
./FOLDER 1
./FOLDER 2
./FOLDER 2/DATA1
./FOLDER 2/DATA2
./FOLDER 3
./FOLDER 3/DATA1
add a comment |
Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt
Cleaned up the result a bit with
sed -n -e 's;^.*/;;p'
So it lists as
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
Finally ended up with this beast of a line
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt
Might be messy but hey I'm no expert. Thanks for all the help.
If you only want the file names without path, pass-printf "%fn"
to find. No need to use sed.
– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f235465%2flist-directoties-down-one-level-excluding-some-named-directories-and-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I did this to create your folder structure:
for f in FOLDER 1 FOLDER 2 FOLDER 3
do mkdir -p "$f/TEMP"
touch "$f/.hidden" "$f/somefile"
case "$f" in
(*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
(*3) mkdir -p "$f/DATA1/TEMP"
esac
done
That created a tree like:
find .
.
./FOLDER 1
./FOLDER 1/TEMP
./FOLDER 1/.hidden
./FOLDER 1/somefile
./FOLDER 2
./FOLDER 2/TEMP
./FOLDER 2/.hidden
./FOLDER 2/somefile
./FOLDER 2/DATA1
./FOLDER 2/DATA1/TEMP
./FOLDER 2/DATA2
./FOLDER 2/DATA2/TEMP
./FOLDER 3
./FOLDER 3/TEMP
./FOLDER 3/.hidden
./FOLDER 3/somefile
./FOLDER 3/DATA1
./FOLDER 3/DATA1/TEMP
And last I did...
find . ! -path './*/*/*' ! -name TEMP -type d
.
./FOLDER 1
./FOLDER 2
./FOLDER 2/DATA1
./FOLDER 2/DATA2
./FOLDER 3
./FOLDER 3/DATA1
add a comment |
I did this to create your folder structure:
for f in FOLDER 1 FOLDER 2 FOLDER 3
do mkdir -p "$f/TEMP"
touch "$f/.hidden" "$f/somefile"
case "$f" in
(*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
(*3) mkdir -p "$f/DATA1/TEMP"
esac
done
That created a tree like:
find .
.
./FOLDER 1
./FOLDER 1/TEMP
./FOLDER 1/.hidden
./FOLDER 1/somefile
./FOLDER 2
./FOLDER 2/TEMP
./FOLDER 2/.hidden
./FOLDER 2/somefile
./FOLDER 2/DATA1
./FOLDER 2/DATA1/TEMP
./FOLDER 2/DATA2
./FOLDER 2/DATA2/TEMP
./FOLDER 3
./FOLDER 3/TEMP
./FOLDER 3/.hidden
./FOLDER 3/somefile
./FOLDER 3/DATA1
./FOLDER 3/DATA1/TEMP
And last I did...
find . ! -path './*/*/*' ! -name TEMP -type d
.
./FOLDER 1
./FOLDER 2
./FOLDER 2/DATA1
./FOLDER 2/DATA2
./FOLDER 3
./FOLDER 3/DATA1
add a comment |
I did this to create your folder structure:
for f in FOLDER 1 FOLDER 2 FOLDER 3
do mkdir -p "$f/TEMP"
touch "$f/.hidden" "$f/somefile"
case "$f" in
(*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
(*3) mkdir -p "$f/DATA1/TEMP"
esac
done
That created a tree like:
find .
.
./FOLDER 1
./FOLDER 1/TEMP
./FOLDER 1/.hidden
./FOLDER 1/somefile
./FOLDER 2
./FOLDER 2/TEMP
./FOLDER 2/.hidden
./FOLDER 2/somefile
./FOLDER 2/DATA1
./FOLDER 2/DATA1/TEMP
./FOLDER 2/DATA2
./FOLDER 2/DATA2/TEMP
./FOLDER 3
./FOLDER 3/TEMP
./FOLDER 3/.hidden
./FOLDER 3/somefile
./FOLDER 3/DATA1
./FOLDER 3/DATA1/TEMP
And last I did...
find . ! -path './*/*/*' ! -name TEMP -type d
.
./FOLDER 1
./FOLDER 2
./FOLDER 2/DATA1
./FOLDER 2/DATA2
./FOLDER 3
./FOLDER 3/DATA1
I did this to create your folder structure:
for f in FOLDER 1 FOLDER 2 FOLDER 3
do mkdir -p "$f/TEMP"
touch "$f/.hidden" "$f/somefile"
case "$f" in
(*2) mkdir -p "$f/DATA1/TEMP" "$f/DATA2/TEMP";;
(*3) mkdir -p "$f/DATA1/TEMP"
esac
done
That created a tree like:
find .
.
./FOLDER 1
./FOLDER 1/TEMP
./FOLDER 1/.hidden
./FOLDER 1/somefile
./FOLDER 2
./FOLDER 2/TEMP
./FOLDER 2/.hidden
./FOLDER 2/somefile
./FOLDER 2/DATA1
./FOLDER 2/DATA1/TEMP
./FOLDER 2/DATA2
./FOLDER 2/DATA2/TEMP
./FOLDER 3
./FOLDER 3/TEMP
./FOLDER 3/.hidden
./FOLDER 3/somefile
./FOLDER 3/DATA1
./FOLDER 3/DATA1/TEMP
And last I did...
find . ! -path './*/*/*' ! -name TEMP -type d
.
./FOLDER 1
./FOLDER 2
./FOLDER 2/DATA1
./FOLDER 2/DATA2
./FOLDER 3
./FOLDER 3/DATA1
answered Oct 12 '15 at 1:37
mikeserv
45.3k567153
45.3k567153
add a comment |
add a comment |
Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt
Cleaned up the result a bit with
sed -n -e 's;^.*/;;p'
So it lists as
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
Finally ended up with this beast of a line
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt
Might be messy but hey I'm no expert. Thanks for all the help.
If you only want the file names without path, pass-printf "%fn"
to find. No need to use sed.
– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
add a comment |
Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt
Cleaned up the result a bit with
sed -n -e 's;^.*/;;p'
So it lists as
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
Finally ended up with this beast of a line
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt
Might be messy but hey I'm no expert. Thanks for all the help.
If you only want the file names without path, pass-printf "%fn"
to find. No need to use sed.
– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
add a comment |
Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt
Cleaned up the result a bit with
sed -n -e 's;^.*/;;p'
So it lists as
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
Finally ended up with this beast of a line
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt
Might be messy but hey I'm no expert. Thanks for all the help.
Thanks that worked great I forgot that .hidden was a folder as well so added that into the find command. Find was outputting the folders in the order they were added so used the sort command to sort back into alphabetical order. So I ended up with
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort > folderlist.txt
Cleaned up the result a bit with
sed -n -e 's;^.*/;;p'
So it lists as
FOLDER 1
FOLDER 2
DATA1
DATA2
FOLDER 3
DATA1
Finally ended up with this beast of a line
find . ! -path './*/*/*' ! -name TEMP ! -name .hidden -type d | sort | sed -n -e 's;^.*/;;p' > folderlist.txt
Might be messy but hey I'm no expert. Thanks for all the help.
answered Oct 12 '15 at 12:00
GTM
184
184
If you only want the file names without path, pass-printf "%fn"
to find. No need to use sed.
– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
add a comment |
If you only want the file names without path, pass-printf "%fn"
to find. No need to use sed.
– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
If you only want the file names without path, pass
-printf "%fn"
to find. No need to use sed.– daniel kullmann
Oct 12 '15 at 13:29
If you only want the file names without path, pass
-printf "%fn"
to find. No need to use sed.– daniel kullmann
Oct 12 '15 at 13:29
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
I did try that but couldn't get it to sort right, probably me being thick.
– GTM
Oct 12 '15 at 14:05
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f235465%2flist-directoties-down-one-level-excluding-some-named-directories-and-files%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