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;








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"









share|improve this question









New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















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

















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"









share|improve this question









New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















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













0












0








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"









share|improve this question









New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Apr 15 at 8:50







zblash













New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Apr 15 at 0:11









zblashzblash

11




11




New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







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












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







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










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.









draft saved

draft discarded


















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.









draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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

Helsingborg Esperantistoj el Helsingborg | Vidu ankaŭ | Navigada menuo1 ŝanĝostabila versiopatrolita1 ŝanĝostabila versiopatrolita56°03′N 12°42′O  /  56.05°N, 12.7°O / 56.05; 12.7 (Helsingborg)56°03′N 12°42′O  /  56.05°N, 12.7°O / 56.05; 12.7 (Helsingborg)Helsingborg en la Vikimedia KomunejoKategorio Helsingborg en la Vikimedia KomunejoHelsingborg en la Vikimedia KomunejoKategorio Helsingborg en la Vikimedia Komunejo

Linux Checkpoint SNX tool configuration issuesgetting Checkpoint VPN SSL Network Extender working in the command lineL2TP IPsec VPN client configurationOpenvpn stops respondingIssues with getting a tun0 connection to route any and all connections from eth0 to be made to this interface and if not working dropHow to setup port forwarding properly in FreeBsd 11?Getting certificate verify failed error in a Python applicationssh is unable to connect to server in VPNVPN SSL Network Extender in Firefoxgetting Checkpoint VPN SSL Network Extender working in the command lineisc-dhcp-server configurationUsing Checkpoint VPN SSL Network Extender CLI with certificate

NetworkManager fails with “Could not find source connection”Trouble connecting to VPN using network-manager, while command line worksHow can I be notified about state changes to a VPN adapterBacktrack 5 R3 - Refuses to connect to VPNFeed all traffic through OpenVPN for a specific network namespace onlyRun daemon on startup in Debian once openvpn connection establishedpfsense tcp connection between openvpn and lan is brokenInternet connection problem with web browsers onlyWhy does NetworkManager explicitly support tun/tap devices?Browser issues with VPNTwo IP addresses assigned to the same network card - OpenVPN issues?Cannot connect to WiFi with nmcli, although secrets are provided