Discussion:
ls > somefile.txt made to go to read sub-folder contents?
Add Reply
azigni
2024-04-30 01:43:53 UTC
Reply
Permalink
Hello,

I know this command ls > somefile.txt reads the contents of a folder and
outputs it to somefile.txt.

I have so far, 6.x folders of ripped mp3's from my music collection and I
would like to print out the contents of each folder under the main
folders.

The folder tree is something like this: Music1/EasyListening/several
directories of albums/the songs they each contain.

What do I need to modify the ls output command to to to have it read sub-
folders, sub-sub folders and print out those file names?

Thanks in advance!
Paul
2024-04-30 02:02:41 UTC
Reply
Permalink
Post by azigni
Hello,
I know this command ls > somefile.txt reads the contents of a folder and
outputs it to somefile.txt.
I have so far, 6.x folders of ripped mp3's from my music collection and I
would like to print out the contents of each folder under the main
folders.
The folder tree is something like this: Music1/EasyListening/several
directories of albums/the songs they each contain.
What do I need to modify the ls output command to to to have it read sub-
folders, sub-sub folders and print out those file names?
Thanks in advance!
You are looking for a "Recursive" option.

ls -R

That will list items below the current working directory.

If I include "1", that lists one item per line.

cd /mnt/d/easy

ls -1R
.:
FirstAlbum
SecondAlbum
ThirdAlbum

./FirstAlbum:
'01 Prime Time.m4a'
"02 Let's Talk About Me.m4a"
'03 Standing On Higher Ground.m4a'

./SecondAlbum:
'04 Stereotomy.m4a'
"05 Don't Answer Me.m4a"
'06 Limelight.m4a'

./ThirdAlbum:
'07 I Robot.m4a'
'08 What Goes Up.m4a'
SideTwo

./ThirdAlbum/SideTwo:
'09 Days Are Numbers (The Traveller).m4a'
'10 Ammonia Avenue.m4a'
'11 The Turn Of A Friendly Card (Pt. II).m4a'

You can also use commands such as Tree.

$ tree -a
.
├── FirstAlbum
│   ├── 01 Prime Time.m4a
│   ├── 02 Let's Talk About Me.m4a
│   └── 03 Standing On Higher Ground.m4a
├── SecondAlbum
│   ├── 04 Stereotomy.m4a
│   ├── 05 Don't Answer Me.m4a
│   └── 06 Limelight.m4a
└── ThirdAlbum
├── 07 I Robot.m4a
├── 08 What Goes Up.m4a
└── SideTwo
├── 09 Days Are Numbers (The Traveller).m4a
├── 10 Ammonia Avenue.m4a
└── 11 The Turn Of A Friendly Card (Pt. II).m4a

4 directories, 11 files

The listdir command is a little more ugly, because it
likes to refer to "." and ".." directories when it lists,
and this can deface the output.

Paul
Big Al
2024-04-30 02:56:53 UTC
Reply
Permalink
Post by azigni
Hello,
I know this command ls > somefile.txt reads the contents of a folder and
outputs it to somefile.txt.
I have so far, 6.x folders of ripped mp3's from my music collection and I
would like to print out the contents of each folder under the main
folders.
The folder tree is something like this: Music1/EasyListening/several
directories of albums/the songs they each contain.
What do I need to modify the ls output command to to to have it read sub-
folders, sub-sub folders and print out those file names?
Thanks in advance!
If you have nemo actions installed, there is a right-click action to 'print tree'. Does a great
output to a html file if you can use that to print.
Directory Tree

[4.1k] /home/alan/Music
├── [3.1M] Formula 1 Theme.m4a
├── [2.8M] Prelude_Day_the_Earth_Stood_Still_1951.mp3
├── [ 29k] Playlist usr-share-sounds.xspf
├── [4.1k] Bedtime
│ ├── [8.3M] 224-Star Wars - Return of the Jedi, Victory Celebration-End Title.mp3
│ ├── [7.3M] 116-Crimson Tide Theme.mp3
│ ├── [7.1M] 196-Stars On 45 Oldies Collage 1.mp3
│ ├── [5.8M] 152-Queen Bohemian Rhapsody.mp3
│ ├── [5.7M] 184-Ringo Starr Oh My My.mp3
│ ├── [5.6M] 216-Star Wars - Duel of the Fates Suite.mp3
│ ├── [5.4M] 112-You've Got Mail Suite.mp3
│ ├── [5.4M] 220-Star Wars IV-A New Hope Ending Theme.mp3
│ ├── [4.9M] 124-Glenn Miller Orchestra Sing Sing Sing.mp3
│ ├── [4.6M] 156-Dirty Dancing I've Had The Time Of My Life.mp3
│ ├── [4.3M] 168-Irene Cara Flashdance What A Feeling.mp3
│ ├── [4.1M] 132-Francis Goya Song Of The Volga Boatman.mp3
│ ├── [3.9M] 128-Oak Ridge Boys Elvira.mp3
│ ├── [3.9M] 200-Ray Stevens Convoy.mp3
│ ├── [3.9M] 164-Christopher Cross Arthur's Theme (Best That You Can Do).mp3
│ ├── [3.8M] 148-Nobody Does It Better.mp3
│ ├── [3.8M] 172-Irene Cara Fame.mp3
│ ├── [3.6M] 136-Todd Rundgren Bang On The Drum All Day.mp3
│ ├── [3.5M] 236-Ray Stevens Everything Is Beautiful.mp3
│ ├── [3.5M] 144-Enrique Iglesias Rythm Divine.mp3
│ ├── [3.4M] 120-Paul Simon Kodachrome.mp3
│ ├── [3.2M] 208-Daniel Boone Beautiful Sunday.mp3
│ ├── [3.1M] 176-John Denver Thank God I'm A Country Boy.mp3
│ ├── [3.0M] 204-Trini Lopez If I Had A Hammer.mp3

ETC.
--
Linux Mint 21.3 Cinnamon 6.0.4 Kernel 5.15.0-105-generic
Al
Gordon
2024-04-30 04:04:47 UTC
Reply
Permalink
Post by Big Al
Post by azigni
Hello,
I know this command ls > somefile.txt reads the contents of a folder and
outputs it to somefile.txt.
I have so far, 6.x folders of ripped mp3's from my music collection and I
would like to print out the contents of each folder under the main
folders.
The folder tree is something like this: Music1/EasyListening/several
directories of albums/the songs they each contain.
What do I need to modify the ls output command to to to have it read sub-
folders, sub-sub folders and print out those file names?
Thanks in advance!
If you have nemo actions installed, there is a right-click action to 'print tree'. Does a great
output to a html file if you can use that to print.
Directory Tree
[4.1k] /home/alan/Music
├── [3.1M] Formula 1 Theme.m4a
├── [2.8M] Prelude_Day_the_Earth_Stood_Still_1951.mp3
├── [ 29k] Playlist usr-share-sounds.xspf
├── [4.1k] Bedtime
│ ├── [8.3M] 224-Star Wars - Return of the Jedi, Victory Celebration-End Title.mp3
│ ├── [7.3M] 116-Crimson Tide Theme.mp3
│ ├── [7.1M] 196-Stars On 45 Oldies Collage 1.mp3
│ ├── [5.8M] 152-Queen Bohemian Rhapsody.mp3
│ ├── [5.7M] 184-Ringo Starr Oh My My.mp3
│ ├── [5.6M] 216-Star Wars - Duel of the Fates Suite.mp3
│ ├── [5.4M] 112-You've Got Mail Suite.mp3
│ ├── [5.4M] 220-Star Wars IV-A New Hope Ending Theme.mp3
│ ├── [4.9M] 124-Glenn Miller Orchestra Sing Sing Sing.mp3
│ ├── [4.6M] 156-Dirty Dancing I've Had The Time Of My Life.mp3
│ ├── [4.3M] 168-Irene Cara Flashdance What A Feeling.mp3
│ ├── [4.1M] 132-Francis Goya Song Of The Volga Boatman.mp3
│ ├── [3.9M] 128-Oak Ridge Boys Elvira.mp3
│ ├── [3.9M] 200-Ray Stevens Convoy.mp3
│ ├── [3.9M] 164-Christopher Cross Arthur's Theme (Best That You Can Do).mp3
│ ├── [3.8M] 148-Nobody Does It Better.mp3
│ ├── [3.8M] 172-Irene Cara Fame.mp3
│ ├── [3.6M] 136-Todd Rundgren Bang On The Drum All Day.mp3
│ ├── [3.5M] 236-Ray Stevens Everything Is Beautiful.mp3
│ ├── [3.5M] 144-Enrique Iglesias Rythm Divine.mp3
│ ├── [3.4M] 120-Paul Simon Kodachrome.mp3
│ ├── [3.2M] 208-Daniel Boone Beautiful Sunday.mp3
│ ├── [3.1M] 176-John Denver Thank God I'm A Country Boy.mp3
│ ├── [3.0M] 204-Trini Lopez If I Had A Hammer.mp3
ETC.
man tree for further info. on formating etc.
Kirk_Rockstein
2024-05-07 18:14:59 UTC
Reply
Permalink
Post by azigni
Hello,
I know this command ls > somefile.txt reads the contents of a folder and
outputs it to somefile.txt.
I have so far, 6.x folders of ripped mp3's from my music collection and I
would like to print out the contents of each folder under the main
folders.
The folder tree is something like this: Music1/EasyListening/several
directories of albums/the songs they each contain.
What do I need to modify the ls output command to to to have it read sub-
folders, sub-sub folders and print out those file names?
Thanks in advance!
Open term/console and cd into top directory (Music1 ?)
and run:
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' > output.txt
Loading...