Sort the list of file names using ls command

To list only the file names using ls command we can pass -a option to it.

Use this command:

anand@hpfolio:/Minposts/Music$ ls -a
Output:
. 
..
Get_up_hustle_repeat.mp4
Instant Crush - Corbyn Kites.mp3
Orient - SefChol.mp3
'Icelandic Arpeggios - DivKid.mp3'
'minposts_playlists (1).png'
'Wind Riders - Asher Fulero.mp3'

You can sort the file names by passing | sort to the ls -a command.

Use this command:

anand@hpfolio:/Minposts/Music$ ls -a | sort

Output:
.
..
Deliberate Thought - Kevin MacLeod.mp3
Float - Emily A. Sprague.mp3
Get_up_hustle_repeat.mp3
Grass - Silent Partner.mp3
Hello 6am - Mylar Melodies.mp3
Icelandic Arpeggios - DivKid.mp3
Instant Crush - Corbyn Kites.mp3
Jay Sweeps - Geographer.mp3
Wind Riders - Asher Fulero.mp3

You can remove -a option if you don’t want hidden files to be included.

Leave a Comment