Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my question: How to sort files by file extensions through the command line?

share|improve this question
up vote 3 down vote accepted

This is what you are looking for:

ls -Xl

From the man file:

 -X                         sort alphabetically by entry extension

This is an example of how you could move .txt files into a test forlder:

mv *.txt test/
share|improve this answer
Thanks, that is useful. Yet, it is not exactly what I wanted. I guess my question isn't that clear now that I read it again. What I would want is to move files from one folder into a specific folder by using the file extension. Turns out I managed by using the mv command. – Ederico Nov 19 '11 at 15:26
I've added a mv command to move files based on extension. Cheers – bioShark Nov 19 '11 at 19:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.