How to get the list of files in a directoryRecursively list files with file names, folder names and...
How to evaluate sum with one million summands?
Is this state of Earth possible, after humans left for a million years?
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
Why should password hash verification be time constant?
Why is PerfectForwardSecrecy considered OK, when it has same defects as salt-less password hashing?
Is a vertical stabiliser needed for straight line flight in a glider?
What was the notion of limit that Newton used?
Detect the first rising edge of 3 input signals
Watching the game, having a puzzle
What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?
Why does the Earth follow an elliptical trajectory rather than a parabolic one?
Why does it take longer to fly from London to Xi'an than to Beijing
Improving Sati-Sampajañña (situative wisdom)
Extending Kan fibrations, without using minimal fibrations
Why can't I prove summation identities without guessing?
Is ‘despite that’ right?
Why do unstable nuclei form?
Has magnetic core memory been used beyond the Moon?
Windows OS quantum vs. SQL OS Quantum
No such column 'DeveloperName' on entity 'RecordType' after Summer '19 release on sandbox
How to efficiently lower your karma
My perfect evil overlord plan... or is it?
How to get a ellipse shaped node in Tikz Network?
How can I avoid subordinates and coworkers leaving work until the last minute, then having no time for revisions?
How to get the list of files in a directory
Recursively list files with file names, folder names and permissionHow to calculate the size of a file list (not a directory)?Reversing 1-D arrayHow to split a filename list in 5GB sets?Create directories from a list of files with spaces in nameHow do I add an associative array to a variable from an external ini file?Find the files between two folder dates in linux?List files recursively in Linux CLI with path relative to the current directory, max 250 charRead data from unknown file name into an array?How to get the file's name and content in the terminal, for all files in a directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I try to create an array/list which stores file names inside a folder. The below command creates for unknown reasons a :
. How is possible to remove :
?
> a=$(ls split*)
> echo $a
split_sam.o4433568 split_sam.o4433616 split_sam.o4441795 split-data-1:
bash files array
add a comment |
I try to create an array/list which stores file names inside a folder. The below command creates for unknown reasons a :
. How is possible to remove :
?
> a=$(ls split*)
> echo $a
split_sam.o4433568 split_sam.o4433616 split_sam.o4441795 split-data-1:
bash files array
1
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by usingecho ${a/:/}
to output the names.
– danieldeveloper001
2 hours ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago
add a comment |
I try to create an array/list which stores file names inside a folder. The below command creates for unknown reasons a :
. How is possible to remove :
?
> a=$(ls split*)
> echo $a
split_sam.o4433568 split_sam.o4433616 split_sam.o4441795 split-data-1:
bash files array
I try to create an array/list which stores file names inside a folder. The below command creates for unknown reasons a :
. How is possible to remove :
?
> a=$(ls split*)
> echo $a
split_sam.o4433568 split_sam.o4433616 split_sam.o4441795 split-data-1:
bash files array
bash files array
edited 2 hours ago
user977828
asked 3 hours ago
user977828user977828
3561617
3561617
1
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by usingecho ${a/:/}
to output the names.
– danieldeveloper001
2 hours ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago
add a comment |
1
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by usingecho ${a/:/}
to output the names.
– danieldeveloper001
2 hours ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago
1
1
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by using
echo ${a/:/}
to output the names.– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by using
echo ${a/:/}
to output the names.– danieldeveloper001
2 hours ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago
add a comment |
1 Answer
1
active
oldest
votes
The $(ls split*
) command didn't create any filenames -- luckily! It also didn't create an array. What it did do was call ls
with the split*
wildcard, then paste all of the resulting output together (removing newlines that ls
added between each filename and at the very end) and assign that conglomerate to your variable. When you then called echo $a
, an extra bit of processing happened that you don't want: the contents of your variable were further subjected to splitting on whitespace ($IFS) and wildcard expansions. You lucked out by not having any files named, for example, split space file
or split more*
!
The root of your confusion is that you do, indeed, have a file named split-data-1:
in that directory, and ls
is happily handing it back to you.
What you want to do, instead, is to find a wildcard that suits the files that you really want, and use a simple array assignment:
a=(split_sam*)
or
a=(split*)
as you originally wrote, which will still include that split-data-1:
file.
You can then iterate over the files or operate on them as a whole:
for file in "${a[@]}"
do
ls -d -- "$file"
done
or
ls -d -- "${a[@]}"
I trieda=(split_sam*)
but I got only one file instead of 3. What did I miss?
– user977828
26 mins ago
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%2f518106%2fhow-to-get-the-list-of-files-in-a-directory%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
The $(ls split*
) command didn't create any filenames -- luckily! It also didn't create an array. What it did do was call ls
with the split*
wildcard, then paste all of the resulting output together (removing newlines that ls
added between each filename and at the very end) and assign that conglomerate to your variable. When you then called echo $a
, an extra bit of processing happened that you don't want: the contents of your variable were further subjected to splitting on whitespace ($IFS) and wildcard expansions. You lucked out by not having any files named, for example, split space file
or split more*
!
The root of your confusion is that you do, indeed, have a file named split-data-1:
in that directory, and ls
is happily handing it back to you.
What you want to do, instead, is to find a wildcard that suits the files that you really want, and use a simple array assignment:
a=(split_sam*)
or
a=(split*)
as you originally wrote, which will still include that split-data-1:
file.
You can then iterate over the files or operate on them as a whole:
for file in "${a[@]}"
do
ls -d -- "$file"
done
or
ls -d -- "${a[@]}"
I trieda=(split_sam*)
but I got only one file instead of 3. What did I miss?
– user977828
26 mins ago
add a comment |
The $(ls split*
) command didn't create any filenames -- luckily! It also didn't create an array. What it did do was call ls
with the split*
wildcard, then paste all of the resulting output together (removing newlines that ls
added between each filename and at the very end) and assign that conglomerate to your variable. When you then called echo $a
, an extra bit of processing happened that you don't want: the contents of your variable were further subjected to splitting on whitespace ($IFS) and wildcard expansions. You lucked out by not having any files named, for example, split space file
or split more*
!
The root of your confusion is that you do, indeed, have a file named split-data-1:
in that directory, and ls
is happily handing it back to you.
What you want to do, instead, is to find a wildcard that suits the files that you really want, and use a simple array assignment:
a=(split_sam*)
or
a=(split*)
as you originally wrote, which will still include that split-data-1:
file.
You can then iterate over the files or operate on them as a whole:
for file in "${a[@]}"
do
ls -d -- "$file"
done
or
ls -d -- "${a[@]}"
I trieda=(split_sam*)
but I got only one file instead of 3. What did I miss?
– user977828
26 mins ago
add a comment |
The $(ls split*
) command didn't create any filenames -- luckily! It also didn't create an array. What it did do was call ls
with the split*
wildcard, then paste all of the resulting output together (removing newlines that ls
added between each filename and at the very end) and assign that conglomerate to your variable. When you then called echo $a
, an extra bit of processing happened that you don't want: the contents of your variable were further subjected to splitting on whitespace ($IFS) and wildcard expansions. You lucked out by not having any files named, for example, split space file
or split more*
!
The root of your confusion is that you do, indeed, have a file named split-data-1:
in that directory, and ls
is happily handing it back to you.
What you want to do, instead, is to find a wildcard that suits the files that you really want, and use a simple array assignment:
a=(split_sam*)
or
a=(split*)
as you originally wrote, which will still include that split-data-1:
file.
You can then iterate over the files or operate on them as a whole:
for file in "${a[@]}"
do
ls -d -- "$file"
done
or
ls -d -- "${a[@]}"
The $(ls split*
) command didn't create any filenames -- luckily! It also didn't create an array. What it did do was call ls
with the split*
wildcard, then paste all of the resulting output together (removing newlines that ls
added between each filename and at the very end) and assign that conglomerate to your variable. When you then called echo $a
, an extra bit of processing happened that you don't want: the contents of your variable were further subjected to splitting on whitespace ($IFS) and wildcard expansions. You lucked out by not having any files named, for example, split space file
or split more*
!
The root of your confusion is that you do, indeed, have a file named split-data-1:
in that directory, and ls
is happily handing it back to you.
What you want to do, instead, is to find a wildcard that suits the files that you really want, and use a simple array assignment:
a=(split_sam*)
or
a=(split*)
as you originally wrote, which will still include that split-data-1:
file.
You can then iterate over the files or operate on them as a whole:
for file in "${a[@]}"
do
ls -d -- "$file"
done
or
ls -d -- "${a[@]}"
answered 2 hours ago
Jeff Schaller♦Jeff Schaller
45.6k1165149
45.6k1165149
I trieda=(split_sam*)
but I got only one file instead of 3. What did I miss?
– user977828
26 mins ago
add a comment |
I trieda=(split_sam*)
but I got only one file instead of 3. What did I miss?
– user977828
26 mins ago
I tried
a=(split_sam*)
but I got only one file instead of 3. What did I miss?– user977828
26 mins ago
I tried
a=(split_sam*)
but I got only one file instead of 3. What did I miss?– user977828
26 mins ago
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%2f518106%2fhow-to-get-the-list-of-files-in-a-directory%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
1
What operating system and terminal are you running? I've tried your snippet both in Fedora (bash) and Alpine (ash) and it works properly. Isn't it actually a part of the file name?
– danieldeveloper001
2 hours ago
If that is the case, you could replace the colon by using
echo ${a/:/}
to output the names.– danieldeveloper001
2 hours ago
We are using SUSE Linux Enterprise Server 12 SP2 and I use bash.
– user977828
24 mins ago