LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Recursive ls with full path (https://www.linuxquestions.org/questions/linux-newbie-8/recursive-ls-with-full-path-4175490953/)

taylorkh 01-11-2014 11:48 AM

Recursive ls with full path
 
I have been doing some housekeeping - archiving video and audio files to DVD. As I will never be able to remember what is on what DVD I am creating a catalog of files - a text file which I can search and find which DVD contains a certain video for example. I have been doing this for years using Windoze and the dir command. Even after using Linux for many years I would mount the DVDs from a Win XP virtual machine to read the file list and concatenate it to my list. I finally decided it is time to do this from Linux directly. Here is an example of what I am after
Quote:

D:\work>dir dvd\*.* /s/b

D:\work\dvd\level1
D:\work\dvd\rootfile1
D:\work\dvd\rootfile2
D:\work\dvd\rootfile3
D:\work\dvd\level1\level2
D:\work\dvd\level1\level1file2
D:\work\dvd\level1\level1file3
D:\work\dvd\level1\level1file1
D:\work\dvd\level1\level2\level2file3
D:\work\dvd\level1\level2\level3
D:\work\dvd\level1\level2\level2file1
D:\work\dvd\level1\level2\level2file2
D:\work\dvd\level1\level2\level3\level3file1
D:\work\dvd\level1\level2\level3\level3file3
D:\work\dvd\level1\level2\level3\level3file2
This was obviously done by the dir command from a sample file/directory structure. In Linux I would like something like
Quote:

/work/dvd/level1/level2/level3/level3file1
I have been doing some research and experimenting with the ls command such as

ls -r -1
ls -r -1 /**/*

I am able to display the files and full path at but not at all levels. For example
Quote:

[ken@taylor12 Desktop]$ ls -r -1 /data/work/dvd/**/*
/data/work/dvd/level1/level1file3
/data/work/dvd/level1/level1file2
/data/work/dvd/level1/level1file1

/data/work/dvd/level1/level2:
level3
level2file3
level2file2
level2file1
I must be missing something - probably something simple. I hate to have to run dir under Wine in order to list the files on my DVDs :cry:

TIA,

Ken

fuorviato 01-11-2014 01:10 PM

Hey there :) Have you ever tried "tree" command in Linux? It has more simple syntax than ls itself and will output each level of a directory.
Give it a try.

taylorkh 01-11-2014 01:50 PM

Thanks fuorviato!

I had used the tree command in Windoze. I had not tried it in Linux. Seems it is not there by default. I have installed the package and played with it a little. It produces a fancier output than I had used previosly. I will substitute it in my DVD cataloging script and see how it works out.

Thanks again,

Ken

fuorviato 01-11-2014 02:13 PM

OK. Feel free to write in case of problems, so maybe we can help around :)

John VV 01-11-2014 02:55 PM

"tree" works very well
i use it all the time
the basic just typing
Code:

tree
---- or -----
tree > FileList.txt

is all i need 99% of the time
have a look at the help page
Code:

tree --help
--------- and ------
man tree


fuorviato 01-11-2014 02:58 PM

Quote:

Originally Posted by John VV (Post 5096259)
"tree" works very well
i use it all the time
the basic just typing
Code:

tree
---- or -----
tree > FileList.txt

is all i need 99% of the time
have a look at the help page
Code:

tree --help
--------- and ------
man tree


That's the power of Linux :)
Ah. If the trick works for you, mark the thread as "solved" pls.

taylorkh 01-11-2014 05:01 PM

Again my sincere thanks fuorviato,

I incorporated tree into my directory reading script thus
Code:

df | grep /dev/sr0 | grep /media | awk '{print$ 6}' | sed s/"\/media\/"// >> dvd.list
mount -t iso9660 /dev/sr0 /dvd
tree /dvd >> dvd.list
echo >> dvd.list
umount /dvd
eject /dev/sr0

It produces nice results for example
Quote:

Video_1738
/dvd
|-- Female Comedy Teams
| |-- Disc 1
| | |-- 01 - Feed 'em and Weep (1928) (DVDRip) [Guild55].avi
| | |-- 02 - A Pair of Tights (1929) (DVDRip) [Guild55].avi
| | |-- 03 - Babes in the Goods (1934) (DVDRip) [Guild55].avi
| | |-- 04 - Maid in Hollywood (1934) (DVDRip) [Guild55].avi
| | |-- 05 - Show Business (1932) (DVDRip) [Guild55].avi
| | |-- 06 - Asleep in the Feet (1933) (DVDRip) [Guild55].avi
| | `-- 07 - Work in Progress - Restoration of Going Ga-ga (1929) DVDRip [Guild55].avi
| `-- Disc 2
| |-- 01 - The Bargain of the Century (1933) (DVDRip) [Guild55].avi
| |-- 02 - Beauty and the Bus (1933) (DVDRip) [Guild55].avi
| |-- 03 - The Pajama Party (1931) (DVDRip [Guild55].avi
| |-- 04 - On the Loose (1931) (DVDRip) [Guild55].avi
| |-- 05 - The Misses Stooge (1935) (DVDRip) [Guild55].avi
| `-- 06 - Top Flat (1935) (DVDRip) [Guild55].avi
`-- MalteseFalcon.mkv

3 directories, 14 files
I could do without the /dvd line and the 3 directories, 14 files line but I can live with that (or delete it manually before I paste the results of a batch of DVDs into the master catalog file.) Or I might get creative and figure out how to strip out those lines. I think head and tail might come into play but I will have to do a little reading first.

You have provided me with the answer to my original question and I will mark this thread as solved!

Thanks once more,

Ken

p.s. The way I use this script is as follows:

1 - insert a DVD
2 - allow the DVD to auto mount
3 - run the script (as root because of mount/umount)
4 - pick up the ejected DVD and repeat - all rather efficient

I think I can improve it by parsing the label of the DVD to a variable and substituting it into the tree command. That would eliminate the redundant mount and allow me to run the script as a normal user. That is on my todo list.

taylorkh 01-11-2014 06:00 PM

My new and improved script - even simpler
Code:

#!/bin/bash

MYDISK=`df | grep /dev/sr0 | grep /media | awk '{print$ 6}'`
tree  $MYDISK >> dvd.list
echo  >> dvd.list
echo  >> dvd.list
eject /dev/sr0

which results in
Quote:

/media/Video_1738
|-- Female Comedy Teams
| |-- Disc 1
| | |-- 01 - Feed 'em and Weep (1928) (DVDRip) [Guild55].avi
| | |-- 02 - A Pair of Tights (1929) (DVDRip) [Guild55].avi
| | |-- 03 - Babes in the Goods (1934) (DVDRip) [Guild55].avi
| | |-- 04 - Maid in Hollywood (1934) (DVDRip) [Guild55].avi
| | |-- 05 - Show Business (1932) (DVDRip) [Guild55].avi
| | |-- 06 - Asleep in the Feet (1933) (DVDRip) [Guild55].avi
| | `-- 07 - Work in Progress - Restoration of Going Ga-ga (1929) DVDRip [Guild55].avi
| `-- Disc 2
| |-- 01 - The Bargain of the Century (1933) (DVDRip) [Guild55].avi
| |-- 02 - Beauty and the Bus (1933) (DVDRip) [Guild55].avi
| |-- 03 - The Pajama Party (1931) (DVDRip [Guild55].avi
| |-- 04 - On the Loose (1931) (DVDRip) [Guild55].avi
| |-- 05 - The Misses Stooge (1935) (DVDRip) [Guild55].avi
| `-- 06 - Top Flat (1935) (DVDRip) [Guild55].avi
`-- MalteseFalcon.mkv

3 directories, 14 files
Ken

descendant_command 01-11-2014 06:11 PM

What about just
Code:

me@lappy:~/Desktop$ find
.
./munin
./munin/munin
./munin/munin/munin-node.exe
./munin/munin/readme.htm
./munin/munin/XEventMessage.dll
./munin/munin/munin-node.ini
./377_eth_2e_06.pdf
./estick
./estick/NickCV.doc
./estick/autorun.inf
./estick/cd
./estick/cd/Desktop.ini
./estick/cd/setup.exe
./infected
./infected/infected
./infected/infected/Music.lnk
./infected/infected/New Folder.lnk
./infected/infected/Passwords.lnk
./infected/infected/Pictures.lnk
./infected/infected/Documents.lnk
./infected/infected/fuedue.exe
./infected/infected/autorun.inf
./infected/infected/Video.lnk
./infected/infected/fuedue.scr

It would be more useful for scripting (if you wanted that) that the "formatted list" from tree.

edit: probably not what you want, but it also answers the OP for future searchers who may.

taylorkh 01-11-2014 06:23 PM

Thanks descendant_command,

I have played with find a bit. I appreciate your adding to the thread for completeness and future reference.

Ken


All times are GMT -5. The time now is 11:21 AM.