Bash script to find the specific files in the folder and show the sizes












0















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









share|improve this question


















  • 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
















0















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









share|improve this question


















  • 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














0












0








0








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









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 31 at 11:16









mkltknmkltkn

1




1








  • 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














  • 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








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










1 Answer
1






active

oldest

votes


















0














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






share|improve this answer





















  • 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













  • 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













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
});


}
});














draft saved

draft discarded


















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









0














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






share|improve this answer





















  • 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













  • 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


















0














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






share|improve this answer





















  • 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













  • 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
















0












0








0







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








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 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













  • 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





    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













  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

19世紀