LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-11-2014, 11:48 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
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

TIA,

Ken
 
Old 01-11-2014, 01:10 PM   #2
fuorviato
Member
 
Registered: Dec 2013
Location: Poland
Distribution: Sabayon/Gentoo 64bit
Posts: 215

Rep: Reputation: 14
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.
 
1 members found this post helpful.
Old 01-11-2014, 01:50 PM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
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
 
Old 01-11-2014, 02:13 PM   #4
fuorviato
Member
 
Registered: Dec 2013
Location: Poland
Distribution: Sabayon/Gentoo 64bit
Posts: 215

Rep: Reputation: 14
OK. Feel free to write in case of problems, so maybe we can help around
 
Old 01-11-2014, 02:55 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
"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
 
Old 01-11-2014, 02:58 PM   #6
fuorviato
Member
 
Registered: Dec 2013
Location: Poland
Distribution: Sabayon/Gentoo 64bit
Posts: 215

Rep: Reputation: 14
Quote:
Originally Posted by John VV View Post
"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.

Last edited by fuorviato; 01-11-2014 at 02:59 PM.
 
Old 01-11-2014, 05:01 PM   #7
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
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.
 
Old 01-11-2014, 06:00 PM   #8
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
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
 
Old 01-11-2014, 06:11 PM   #9
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
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.

Last edited by descendant_command; 01-11-2014 at 06:14 PM.
 
Old 01-11-2014, 06:23 PM   #10
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks descendant_command,

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

Ken
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive ls output to file with path? dwmolyneux Linux - General 3 06-19-2012 10:46 AM
[SOLVED] Full Path Name Juve IT Linux - Newbie 6 12-16-2010 08:22 PM
Shell: tr can only be used when given full path (despite being in $PATH) chochem Programming 2 06-27-2008 08:37 AM
mod_rewrite full path chrille112 Linux - Newbie 6 03-06-2008 06:49 AM
Full Path Verbal Kint Linux - General 7 01-30-2008 09:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration