How can one stat an entire directory using a single command line starting with bash -c?
Clash Royale CLAN TAG#URR8PPP
How can one stat an entire directory using a single command line starting with bash -c?
This returns all files except for those prefixed with .
bash -c "stat /path/todir/**"
This returns all files starting with . including . & .. which should be excluded.
bash -c "stat /path/todir/.*"
This works but not under bash -c and requires two lines
shopt -s dotglob
stat /path/todir/**
This too
stat /path/todir/!(.|..)
bash shell-script shell wildcards
add a comment |
How can one stat an entire directory using a single command line starting with bash -c?
This returns all files except for those prefixed with .
bash -c "stat /path/todir/**"
This returns all files starting with . including . & .. which should be excluded.
bash -c "stat /path/todir/.*"
This works but not under bash -c and requires two lines
shopt -s dotglob
stat /path/todir/**
This too
stat /path/todir/!(.|..)
bash shell-script shell wildcards
stat /path/**
would be identical tostat /path/*
if theextglob
shell option was not set. You don't set this for yourbash -c
shell, so I don't know how.
and..
could be stat'ed.
– Kusalananda♦
Mar 4 at 7:53
I meantglobstar
in my previous comment... notextglob
– Kusalananda♦
Mar 4 at 8:00
add a comment |
How can one stat an entire directory using a single command line starting with bash -c?
This returns all files except for those prefixed with .
bash -c "stat /path/todir/**"
This returns all files starting with . including . & .. which should be excluded.
bash -c "stat /path/todir/.*"
This works but not under bash -c and requires two lines
shopt -s dotglob
stat /path/todir/**
This too
stat /path/todir/!(.|..)
bash shell-script shell wildcards
How can one stat an entire directory using a single command line starting with bash -c?
This returns all files except for those prefixed with .
bash -c "stat /path/todir/**"
This returns all files starting with . including . & .. which should be excluded.
bash -c "stat /path/todir/.*"
This works but not under bash -c and requires two lines
shopt -s dotglob
stat /path/todir/**
This too
stat /path/todir/!(.|..)
bash shell-script shell wildcards
bash shell-script shell wildcards
asked Mar 4 at 7:42
TrevTheDevTrevTheDev
1134
1134
stat /path/**
would be identical tostat /path/*
if theextglob
shell option was not set. You don't set this for yourbash -c
shell, so I don't know how.
and..
could be stat'ed.
– Kusalananda♦
Mar 4 at 7:53
I meantglobstar
in my previous comment... notextglob
– Kusalananda♦
Mar 4 at 8:00
add a comment |
stat /path/**
would be identical tostat /path/*
if theextglob
shell option was not set. You don't set this for yourbash -c
shell, so I don't know how.
and..
could be stat'ed.
– Kusalananda♦
Mar 4 at 7:53
I meantglobstar
in my previous comment... notextglob
– Kusalananda♦
Mar 4 at 8:00
stat /path/**
would be identical to stat /path/*
if the extglob
shell option was not set. You don't set this for your bash -c
shell, so I don't know how .
and ..
could be stat'ed.– Kusalananda♦
Mar 4 at 7:53
stat /path/**
would be identical to stat /path/*
if the extglob
shell option was not set. You don't set this for your bash -c
shell, so I don't know how .
and ..
could be stat'ed.– Kusalananda♦
Mar 4 at 7:53
I meant
globstar
in my previous comment... not extglob
– Kusalananda♦
Mar 4 at 8:00
I meant
globstar
in my previous comment... not extglob
– Kusalananda♦
Mar 4 at 8:00
add a comment |
2 Answers
2
active
oldest
votes
The extended glob options are visible only to the current shell and not to the sub-shells launched. You need to set them inside the sub-shell also for the glob option to be available. Also **
does a recursive descent only if another extended option globstar
is set. For your requirement of the current directory alone, you can just use *
bash -c 'shopt -s dotglob; stat /path/todir/*'
Notice the use of single quotes around the entire shell shell command list. It is much more safe in a way you can avoid unnecessary variable expansion (passing a literal string) and use quoted strings with much ease.
If you have control over the part outside the '..'
you can set the extended shell option in the invocation itself as
bash -O dotglob -c 'stat /path/todir/*'
That said, if an option to use external utilities like find
is available, you could just do below which just excludes the .
(current directory name) and includes all the files in the current directory and passes it stat
in one shot.
find . ! -path . -exec stat +
add a comment |
bash -c -O extglob 'stat /path/todir/!(.|..)'
-O extglob
enables additional pattern matching operators, including !(pattern-list)
for negation.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the shopt builtin (see
SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the
value of that option; +O unsets it.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
operators are recognized. In the following description, a pattern-list is a list of one or more
patterns separated by a |. Composite patterns may be formed using one or more of the following
sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
add a comment |
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%2f504211%2fhow-can-one-stat-an-entire-directory-using-a-single-command-line-starting-with-b%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
The extended glob options are visible only to the current shell and not to the sub-shells launched. You need to set them inside the sub-shell also for the glob option to be available. Also **
does a recursive descent only if another extended option globstar
is set. For your requirement of the current directory alone, you can just use *
bash -c 'shopt -s dotglob; stat /path/todir/*'
Notice the use of single quotes around the entire shell shell command list. It is much more safe in a way you can avoid unnecessary variable expansion (passing a literal string) and use quoted strings with much ease.
If you have control over the part outside the '..'
you can set the extended shell option in the invocation itself as
bash -O dotglob -c 'stat /path/todir/*'
That said, if an option to use external utilities like find
is available, you could just do below which just excludes the .
(current directory name) and includes all the files in the current directory and passes it stat
in one shot.
find . ! -path . -exec stat +
add a comment |
The extended glob options are visible only to the current shell and not to the sub-shells launched. You need to set them inside the sub-shell also for the glob option to be available. Also **
does a recursive descent only if another extended option globstar
is set. For your requirement of the current directory alone, you can just use *
bash -c 'shopt -s dotglob; stat /path/todir/*'
Notice the use of single quotes around the entire shell shell command list. It is much more safe in a way you can avoid unnecessary variable expansion (passing a literal string) and use quoted strings with much ease.
If you have control over the part outside the '..'
you can set the extended shell option in the invocation itself as
bash -O dotglob -c 'stat /path/todir/*'
That said, if an option to use external utilities like find
is available, you could just do below which just excludes the .
(current directory name) and includes all the files in the current directory and passes it stat
in one shot.
find . ! -path . -exec stat +
add a comment |
The extended glob options are visible only to the current shell and not to the sub-shells launched. You need to set them inside the sub-shell also for the glob option to be available. Also **
does a recursive descent only if another extended option globstar
is set. For your requirement of the current directory alone, you can just use *
bash -c 'shopt -s dotglob; stat /path/todir/*'
Notice the use of single quotes around the entire shell shell command list. It is much more safe in a way you can avoid unnecessary variable expansion (passing a literal string) and use quoted strings with much ease.
If you have control over the part outside the '..'
you can set the extended shell option in the invocation itself as
bash -O dotglob -c 'stat /path/todir/*'
That said, if an option to use external utilities like find
is available, you could just do below which just excludes the .
(current directory name) and includes all the files in the current directory and passes it stat
in one shot.
find . ! -path . -exec stat +
The extended glob options are visible only to the current shell and not to the sub-shells launched. You need to set them inside the sub-shell also for the glob option to be available. Also **
does a recursive descent only if another extended option globstar
is set. For your requirement of the current directory alone, you can just use *
bash -c 'shopt -s dotglob; stat /path/todir/*'
Notice the use of single quotes around the entire shell shell command list. It is much more safe in a way you can avoid unnecessary variable expansion (passing a literal string) and use quoted strings with much ease.
If you have control over the part outside the '..'
you can set the extended shell option in the invocation itself as
bash -O dotglob -c 'stat /path/todir/*'
That said, if an option to use external utilities like find
is available, you could just do below which just excludes the .
(current directory name) and includes all the files in the current directory and passes it stat
in one shot.
find . ! -path . -exec stat +
edited Mar 4 at 8:43
Kusalananda♦
139k17259429
139k17259429
answered Mar 4 at 7:48
InianInian
5,2051529
5,2051529
add a comment |
add a comment |
bash -c -O extglob 'stat /path/todir/!(.|..)'
-O extglob
enables additional pattern matching operators, including !(pattern-list)
for negation.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the shopt builtin (see
SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the
value of that option; +O unsets it.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
operators are recognized. In the following description, a pattern-list is a list of one or more
patterns separated by a |. Composite patterns may be formed using one or more of the following
sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
add a comment |
bash -c -O extglob 'stat /path/todir/!(.|..)'
-O extglob
enables additional pattern matching operators, including !(pattern-list)
for negation.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the shopt builtin (see
SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the
value of that option; +O unsets it.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
operators are recognized. In the following description, a pattern-list is a list of one or more
patterns separated by a |. Composite patterns may be formed using one or more of the following
sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
add a comment |
bash -c -O extglob 'stat /path/todir/!(.|..)'
-O extglob
enables additional pattern matching operators, including !(pattern-list)
for negation.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the shopt builtin (see
SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the
value of that option; +O unsets it.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
operators are recognized. In the following description, a pattern-list is a list of one or more
patterns separated by a |. Composite patterns may be formed using one or more of the following
sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
bash -c -O extglob 'stat /path/todir/!(.|..)'
-O extglob
enables additional pattern matching operators, including !(pattern-list)
for negation.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the shopt builtin (see
SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the
value of that option; +O unsets it.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching
operators are recognized. In the following description, a pattern-list is a list of one or more
patterns separated by a |. Composite patterns may be formed using one or more of the following
sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
answered Mar 4 at 8:25
FreddyFreddy
1,444210
1,444210
add a comment |
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.
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%2f504211%2fhow-can-one-stat-an-entire-directory-using-a-single-command-line-starting-with-b%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
stat /path/**
would be identical tostat /path/*
if theextglob
shell option was not set. You don't set this for yourbash -c
shell, so I don't know how.
and..
could be stat'ed.– Kusalananda♦
Mar 4 at 7:53
I meant
globstar
in my previous comment... notextglob
– Kusalananda♦
Mar 4 at 8:00