Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:28:01+00:00 2026-06-02T18:28:01+00:00

Bash is really annoying me with the way that it sorts it’s files with

  • 0

Bash is really annoying me with the way that it sorts it’s files with the sort command and can’t seem to find a way around this. When I sort the files with GNOME though by name, it shows it exactly how I want. I’m trying to sort by real order but the 10’s and 1’s mess everything up when sorting in bash. Here’s how bash sorts a sample of my files:

HeadsetBatteryBG_10@2x.png
HeadsetBatteryBG_11@2x.png
HeadsetBatteryBG_12@2x.png
HeadsetBatteryBG_1@2x.png
HeadsetBatteryBG_13@2x.png
HeadsetBatteryBG_14@2x.png
HeadsetBatteryBG_15@2x.png
HeadsetBatteryBG_16@2x.png
HeadsetBatteryBG_17@2x.png
HeadsetBatteryBG_2@2x.png
HeadsetBatteryBG_3@2x.png
HeadsetBatteryBG_4@2x.png
HeadsetBatteryBG_5@2x.png
HeadsetBatteryBG_6@2x.png
HeadsetBatteryBG_7@2x.png
HeadsetBatteryBG_8@2x.png
HeadsetBatteryBG_9@2x.png

I see what it’s doing here, but is there anywhere to sort a list like this in bash how it SHOULD be sorted? With the numbers in real numerical order instead of this strange thing that it’s doing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:28:05+00:00Added an answer on June 2, 2026 at 6:28 pm

    Try

    sort -k2 -t_ -n [file]
    

    That will sort numerically (-n) on the 2nd field (-k2) using _ as the field separator (-t_).

    (Shamelessly stolen from SuperUser)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not too familiar with Linux/Bash, so I can't really find the right terms
In bash one can escape arguments that contain whitespace. foo a string This also
It is really annoying that each programming language has its own vocabulary. For example,
I have a really weird problem with /bin/bash and a script that uses printf
I don't really know that much about bash scripts OR imagemagick, but I am
I have a series of commands (calls to bash shell functions really) that compute
In bash when I run a command like wc & or cat & that
I have a bash script that looks like the following: #!/bin/bash FILES=public_html/*.php # */
I have this bash script on the server that runs every hour, via cron.
I really dont understand why this is happening, bash seems to remove commands while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.