How can I sort files without ls or find Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionSort the output of find before piping to opensshWhy are these values not appending correctly when appended to the pipeline?Converting `for file in` to `find` so that my script can apply recursivelygenerate file names in loopwhile iterating over the directory, test to see if the items are files or directoriesExtracting data from files in multiple directoriesAlphabetize words within filenames using sort?Replacing multiple characters across multiple File names in a Unix folderMove files that have the same case-insensitive filenameHow can I run a same command in mac terminal for multiple files in a folder?
Why limits give us the exact value of the slope of the tangent line?
Significance of Cersei's obsession with elephants?
Strange behavior of Object.defineProperty() in JavaScript
One-one communication
Why are vacuum tubes still used in amateur radios?
How to make a Field only accept Numbers in Magento 2
How would a mousetrap for use in space work?
What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?
Is it fair for a professor to grade us on the possession of past papers?
Should I use a zero-interest credit card for a large one-time purchase?
Did any compiler fully use 80-bit floating point?
How to compare two different files line by line in unix?
Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode
What would you call this weird metallic apparatus that allows you to lift people?
How do living politicians protect their readily obtainable signatures from misuse?
What does Turing mean by this statement?
Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?
Is there any word for a place full of confusion?
How does light 'choose' between wave and particle behaviour?
What do you call the main part of a joke?
Why is it faster to reheat something than it is to cook it?
Hangman Game with C++
How to improve on this Stylesheet Manipulation for Message Styling
Do wooden building fires get hotter than 600°C?
How can I sort files without ls or find
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionSort the output of find before piping to opensshWhy are these values not appending correctly when appended to the pipeline?Converting `for file in` to `find` so that my script can apply recursivelygenerate file names in loopwhile iterating over the directory, test to see if the items are files or directoriesExtracting data from files in multiple directoriesAlphabetize words within filenames using sort?Replacing multiple characters across multiple File names in a Unix folderMove files that have the same case-insensitive filenameHow can I run a same command in mac terminal for multiple files in a folder?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need sorted list of files and directories in for-loop, must be files sorted before directories.I need this because i'm trying to copy and sequentially renaming files recursively and i tried with ls but its not worked recursively
My folder
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---abc_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
Expected output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
---1.txt
---2.txt
---3.txt
---4.txt
i got this output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
My code
#!/bin/bash
function traverse()
counter=1
for file in "$2"/*
do
if [ ! -d "$file" ]; then
if [[ $file == $3 ]]; then
extension="$file##*."
filename="$file%.*"
cp "$file" "$2/$counter.$extension"
counter=$(($counter + 1))
fi
elif [ $1 == "-R" ] ; then
traverse "$1" "$file" "$3"
fi
done
traverse "$1" "$PWD" "$2"
bash shell-script
New contributor
|
show 3 more comments
I need sorted list of files and directories in for-loop, must be files sorted before directories.I need this because i'm trying to copy and sequentially renaming files recursively and i tried with ls but its not worked recursively
My folder
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---abc_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
Expected output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
---1.txt
---2.txt
---3.txt
---4.txt
i got this output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
My code
#!/bin/bash
function traverse()
counter=1
for file in "$2"/*
do
if [ ! -d "$file" ]; then
if [[ $file == $3 ]]; then
extension="$file##*."
filename="$file%.*"
cp "$file" "$2/$counter.$extension"
counter=$(($counter + 1))
fi
elif [ $1 == "-R" ] ; then
traverse "$1" "$file" "$3"
fi
done
traverse "$1" "$PWD" "$2"
bash shell-script
New contributor
1
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
$file == $3
implies that you are renaming only files with a given name, in which caseshopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.
– xenoid
Apr 15 at 9:06
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25
|
show 3 more comments
I need sorted list of files and directories in for-loop, must be files sorted before directories.I need this because i'm trying to copy and sequentially renaming files recursively and i tried with ls but its not worked recursively
My folder
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---abc_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
Expected output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
---1.txt
---2.txt
---3.txt
---4.txt
i got this output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
My code
#!/bin/bash
function traverse()
counter=1
for file in "$2"/*
do
if [ ! -d "$file" ]; then
if [[ $file == $3 ]]; then
extension="$file##*."
filename="$file%.*"
cp "$file" "$2/$counter.$extension"
counter=$(($counter + 1))
fi
elif [ $1 == "-R" ] ; then
traverse "$1" "$file" "$3"
fi
done
traverse "$1" "$PWD" "$2"
bash shell-script
New contributor
I need sorted list of files and directories in for-loop, must be files sorted before directories.I need this because i'm trying to copy and sequentially renaming files recursively and i tried with ls but its not worked recursively
My folder
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---abc_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
Expected output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
---1.txt
---2.txt
---3.txt
---4.txt
i got this output
AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt
---dtr_folder
---xyz_folder
---aaa.txt
---bbb.txt
---ccc.txt
---ddd.txt
My code
#!/bin/bash
function traverse()
counter=1
for file in "$2"/*
do
if [ ! -d "$file" ]; then
if [[ $file == $3 ]]; then
extension="$file##*."
filename="$file%.*"
cp "$file" "$2/$counter.$extension"
counter=$(($counter + 1))
fi
elif [ $1 == "-R" ] ; then
traverse "$1" "$file" "$3"
fi
done
traverse "$1" "$PWD" "$2"
bash shell-script
bash shell-script
New contributor
New contributor
edited Apr 15 at 8:50
zblash
New contributor
asked Apr 15 at 0:11
zblashzblash
11
11
New contributor
New contributor
1
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
$file == $3
implies that you are renaming only files with a given name, in which caseshopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.
– xenoid
Apr 15 at 9:06
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25
|
show 3 more comments
1
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
$file == $3
implies that you are renaming only files with a given name, in which caseshopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.
– xenoid
Apr 15 at 9:06
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25
1
1
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
$file == $3
implies that you are renaming only files with a given name, in which case shopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.– xenoid
Apr 15 at 9:06
$file == $3
implies that you are renaming only files with a given name, in which case shopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.– xenoid
Apr 15 at 9:06
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25
|
show 3 more comments
0
active
oldest
votes
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
);
);
zblash is a new contributor. Be nice, and check out our Code of Conduct.
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%2f512462%2fhow-can-i-sort-files-without-ls-or-find%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
zblash is a new contributor. Be nice, and check out our Code of Conduct.
zblash is a new contributor. Be nice, and check out our Code of Conduct.
zblash is a new contributor. Be nice, and check out our Code of Conduct.
zblash is a new contributor. Be nice, and check out our Code of Conduct.
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%2f512462%2fhow-can-i-sort-files-without-ls-or-find%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
Sorted by what? Just file/directory separation?
– Michael Homer
Apr 15 at 0:23
Hi zblash, Do you need help with your script, or just a way to do this?
– Eran Ben-Natan
Apr 15 at 4:38
Edited the post. I need how i do this
– zblash
Apr 15 at 8:51
$file == $3
implies that you are renaming only files with a given name, in which caseshopt -s globstar; for file in **/"$3"
will list all these files, and there is no need for a recursion.– xenoid
Apr 15 at 9:06
but i want to copy all file in directories and rename sequentially
– zblash
Apr 15 at 9:25