How do I count the files in the current directory whose names are at least 5 characters long?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to use ls
and grep
. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.
How can I achieve this?
files grep ls
 |Â
show 3 more comments
up vote
0
down vote
favorite
I am trying to use ls
and grep
. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.
How can I achieve this?
files grep ls
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
1
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
2
@2310, note, this filenamea.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
â RomanPerekhrest
Oct 29 '17 at 5:50
 |Â
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use ls
and grep
. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.
How can I achieve this?
files grep ls
I am trying to use ls
and grep
. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.
How can I achieve this?
files grep ls
edited Oct 29 '17 at 6:27
Satà  Katsura
10.7k11533
10.7k11533
asked Oct 29 '17 at 5:45
2310
6
6
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
1
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
2
@2310, note, this filenamea.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
â RomanPerekhrest
Oct 29 '17 at 5:50
 |Â
show 3 more comments
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
1
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
2
@2310, note, this filenamea.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
â RomanPerekhrest
Oct 29 '17 at 5:50
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
1
1
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
2
2
@2310, note, this filename
a.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!â RomanPerekhrest
Oct 29 '17 at 5:50
@2310, note, this filename
a.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!â RomanPerekhrest
Oct 29 '17 at 5:50
 |Â
show 3 more comments
2 Answers
2
active
oldest
votes
up vote
2
down vote
Simple find
+ wc
commands solution:
find . -maxdepth 1 -type f -name "?????*" | wc -l
add a comment |Â
up vote
0
down vote
If this is homework, the assignment may be looking for something like:
ls | grep ..... | wc -l
Though I would do:
set -- ?????*
echo $#
or
files=(?????*)
echo $#files[@]
Here the important work is done by the shell glob .
which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.
The counting is then done by the $#
shell parameter in the set
solution, or by counting the elements in the array.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Simple find
+ wc
commands solution:
find . -maxdepth 1 -type f -name "?????*" | wc -l
add a comment |Â
up vote
2
down vote
Simple find
+ wc
commands solution:
find . -maxdepth 1 -type f -name "?????*" | wc -l
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Simple find
+ wc
commands solution:
find . -maxdepth 1 -type f -name "?????*" | wc -l
Simple find
+ wc
commands solution:
find . -maxdepth 1 -type f -name "?????*" | wc -l
answered Oct 29 '17 at 5:54
RomanPerekhrest
22.5k12145
22.5k12145
add a comment |Â
add a comment |Â
up vote
0
down vote
If this is homework, the assignment may be looking for something like:
ls | grep ..... | wc -l
Though I would do:
set -- ?????*
echo $#
or
files=(?????*)
echo $#files[@]
Here the important work is done by the shell glob .
which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.
The counting is then done by the $#
shell parameter in the set
solution, or by counting the elements in the array.
add a comment |Â
up vote
0
down vote
If this is homework, the assignment may be looking for something like:
ls | grep ..... | wc -l
Though I would do:
set -- ?????*
echo $#
or
files=(?????*)
echo $#files[@]
Here the important work is done by the shell glob .
which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.
The counting is then done by the $#
shell parameter in the set
solution, or by counting the elements in the array.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If this is homework, the assignment may be looking for something like:
ls | grep ..... | wc -l
Though I would do:
set -- ?????*
echo $#
or
files=(?????*)
echo $#files[@]
Here the important work is done by the shell glob .
which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.
The counting is then done by the $#
shell parameter in the set
solution, or by counting the elements in the array.
If this is homework, the assignment may be looking for something like:
ls | grep ..... | wc -l
Though I would do:
set -- ?????*
echo $#
or
files=(?????*)
echo $#files[@]
Here the important work is done by the shell glob .
which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.
The counting is then done by the $#
shell parameter in the set
solution, or by counting the elements in the array.
answered Oct 29 '17 at 13:10
Jeff Schaller
32.1k849109
32.1k849109
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401158%2fhow-do-i-count-the-files-in-the-current-directory-whose-names-are-at-least-5-cha%23new-answer', 'question_page');
);
Post as a guest
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
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
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
should files in subfolders be considered?
â RomanPerekhrest
Oct 29 '17 at 5:46
No just the current directory, not recursive
â 2310
Oct 29 '17 at 5:47
1
What have you tried so far? How would you grep for lines with at least five characters?
â Mikel
Oct 29 '17 at 5:47
and directory names should be skipped, only files?
â RomanPerekhrest
Oct 29 '17 at 5:48
2
@2310, note, this filename
a.txt
has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!â RomanPerekhrest
Oct 29 '17 at 5:50