Bash script to find the specific files in the folder and show the sizes
I have an array of file names like below, I want to find and learn the sizes in the folder. I wrote the bash script below but it is finding all the files in the folder recursively.
files=( a/ddd/dd ddd/b dfgf/fgdfg/c dfgdfg/dfgdfg/d dsf/e rret/ertert/erter/f)
for u in "${files[@]}"
do
find . "[^/]+$" $u".js" -exec du -sh {} ;
done
command-line bash scripts
add a comment |
I have an array of file names like below, I want to find and learn the sizes in the folder. I wrote the bash script below but it is finding all the files in the folder recursively.
files=( a/ddd/dd ddd/b dfgf/fgdfg/c dfgdfg/dfgdfg/d dsf/e rret/ertert/erter/f)
for u in "${files[@]}"
do
find . "[^/]+$" $u".js" -exec du -sh {} ;
done
command-line bash scripts
3
Can you please edit your question to clarify what you are trying to do? Isdfgf/fgdfg/c.js
a file whose size you want to know, or isdfgf/fgdfg/c
a directory that contains*.js
files whose size you want to know?
– steeldriver
Jan 31 at 13:24
add a comment |
I have an array of file names like below, I want to find and learn the sizes in the folder. I wrote the bash script below but it is finding all the files in the folder recursively.
files=( a/ddd/dd ddd/b dfgf/fgdfg/c dfgdfg/dfgdfg/d dsf/e rret/ertert/erter/f)
for u in "${files[@]}"
do
find . "[^/]+$" $u".js" -exec du -sh {} ;
done
command-line bash scripts
I have an array of file names like below, I want to find and learn the sizes in the folder. I wrote the bash script below but it is finding all the files in the folder recursively.
files=( a/ddd/dd ddd/b dfgf/fgdfg/c dfgdfg/dfgdfg/d dsf/e rret/ertert/erter/f)
for u in "${files[@]}"
do
find . "[^/]+$" $u".js" -exec du -sh {} ;
done
command-line bash scripts
command-line bash scripts
asked Jan 31 at 11:16
mkltknmkltkn
1
1
3
Can you please edit your question to clarify what you are trying to do? Isdfgf/fgdfg/c.js
a file whose size you want to know, or isdfgf/fgdfg/c
a directory that contains*.js
files whose size you want to know?
– steeldriver
Jan 31 at 13:24
add a comment |
3
Can you please edit your question to clarify what you are trying to do? Isdfgf/fgdfg/c.js
a file whose size you want to know, or isdfgf/fgdfg/c
a directory that contains*.js
files whose size you want to know?
– steeldriver
Jan 31 at 13:24
3
3
Can you please edit your question to clarify what you are trying to do? Is
dfgf/fgdfg/c.js
a file whose size you want to know, or is dfgf/fgdfg/c
a directory that contains *.js
files whose size you want to know?– steeldriver
Jan 31 at 13:24
Can you please edit your question to clarify what you are trying to do? Is
dfgf/fgdfg/c.js
a file whose size you want to know, or is dfgf/fgdfg/c
a directory that contains *.js
files whose size you want to know?– steeldriver
Jan 31 at 13:24
add a comment |
1 Answer
1
active
oldest
votes
From man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.
Try
find . -maxdepth 0 -name "[^/]+$" $u".js" -exec du -sh {} ;
I rarely use find with -exec (because I always forget about it) so I apologize if this is wrong
1
Please finish your answer by including the entirefind
command. Even though the question is unclear, you can re-edit your answer if the question is edited.
– karel
Jan 31 at 13:44
The-exec
part look fine to me, but I'm having a hard time understanding what-name "[^/]+$" $u".js"
is intended to do here. AFAIK-name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a-name
pattern can't contain slashes)
– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
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%2f1114367%2fbash-script-to-find-the-specific-files-in-the-folder-and-show-the-sizes%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
From man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.
Try
find . -maxdepth 0 -name "[^/]+$" $u".js" -exec du -sh {} ;
I rarely use find with -exec (because I always forget about it) so I apologize if this is wrong
1
Please finish your answer by including the entirefind
command. Even though the question is unclear, you can re-edit your answer if the question is edited.
– karel
Jan 31 at 13:44
The-exec
part look fine to me, but I'm having a hard time understanding what-name "[^/]+$" $u".js"
is intended to do here. AFAIK-name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a-name
pattern can't contain slashes)
– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
add a comment |
From man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.
Try
find . -maxdepth 0 -name "[^/]+$" $u".js" -exec du -sh {} ;
I rarely use find with -exec (because I always forget about it) so I apologize if this is wrong
1
Please finish your answer by including the entirefind
command. Even though the question is unclear, you can re-edit your answer if the question is edited.
– karel
Jan 31 at 13:44
The-exec
part look fine to me, but I'm having a hard time understanding what-name "[^/]+$" $u".js"
is intended to do here. AFAIK-name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a-name
pattern can't contain slashes)
– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
add a comment |
From man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.
Try
find . -maxdepth 0 -name "[^/]+$" $u".js" -exec du -sh {} ;
I rarely use find with -exec (because I always forget about it) so I apologize if this is wrong
From man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-maxdepth 0
means only apply the tests and actions to the starting-points themselves.
Try
find . -maxdepth 0 -name "[^/]+$" $u".js" -exec du -sh {} ;
I rarely use find with -exec (because I always forget about it) so I apologize if this is wrong
edited Jan 31 at 14:23
answered Jan 31 at 11:57
j-moneyj-money
1,093416
1,093416
1
Please finish your answer by including the entirefind
command. Even though the question is unclear, you can re-edit your answer if the question is edited.
– karel
Jan 31 at 13:44
The-exec
part look fine to me, but I'm having a hard time understanding what-name "[^/]+$" $u".js"
is intended to do here. AFAIK-name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a-name
pattern can't contain slashes)
– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
add a comment |
1
Please finish your answer by including the entirefind
command. Even though the question is unclear, you can re-edit your answer if the question is edited.
– karel
Jan 31 at 13:44
The-exec
part look fine to me, but I'm having a hard time understanding what-name "[^/]+$" $u".js"
is intended to do here. AFAIK-name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a-name
pattern can't contain slashes)
– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
1
1
Please finish your answer by including the entire
find
command. Even though the question is unclear, you can re-edit your answer if the question is edited.– karel
Jan 31 at 13:44
Please finish your answer by including the entire
find
command. Even though the question is unclear, you can re-edit your answer if the question is edited.– karel
Jan 31 at 13:44
The
-exec
part look fine to me, but I'm having a hard time understanding what -name "[^/]+$" $u".js"
is intended to do here. AFAIK -name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a -name
pattern can't contain slashes)– steeldriver
Jan 31 at 15:30
The
-exec
part look fine to me, but I'm having a hard time understanding what -name "[^/]+$" $u".js"
is intended to do here. AFAIK -name
takes a single simple shell glob (not a regex) as argument, and matches against only the filename portion (so a -name
pattern can't contain slashes)– steeldriver
Jan 31 at 15:30
it might be the I interpreted the man page wrong :/
The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
it might be the I interpreted the man page wrong :/
The metacharacters (``*', ``?', and ``') match a ``.' at the start of the base name
– j-money
Jan 31 at 15:33
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.
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%2f1114367%2fbash-script-to-find-the-specific-files-in-the-folder-and-show-the-sizes%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
3
Can you please edit your question to clarify what you are trying to do? Is
dfgf/fgdfg/c.js
a file whose size you want to know, or isdfgf/fgdfg/c
a directory that contains*.js
files whose size you want to know?– steeldriver
Jan 31 at 13:24