LinuxQuestions.org
Visit Jeremy's Blog.
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 10-11-2020, 04:44 PM   #1
binkyd
Member
 
Registered: Oct 2016
Distribution: Looking again
Posts: 429

Rep: Reputation: 40
Confused by options for "ls"


I want to list directories recursively but I having trouble with the different file types.
I want the list to group the the extensions together and I'm getting frustrated.
This does what I want, except for grouping them:
Code:
ls -R1
Everything I've tried so far makes a mess.
Which option will do this?

Last edited by binkyd; 10-11-2020 at 04:45 PM.
 
Old 10-11-2020, 04:53 PM   #2
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Not all files have extensions and some have several - assuming you mean a bunch of characters after a dot?
 
Old 10-11-2020, 05:16 PM   #3
binkyd
Member
 
Registered: Oct 2016
Distribution: Looking again
Posts: 429

Original Poster
Rep: Reputation: 40
Music directory with mp3, flac and jpg files
I'm trying to get a straight listing so I can actually get rid of duplicates.

None of the programs like fslint, fdupes or shredder [I]can even find duplicates[I] and there's a lot of them - i guess there must be slight differences in the file names (which I can't see) that confuse these programs. (Or are they neurotic about all the details and files must be exact dupes to succeed?)

Looking at about 5000 files here in about 150 directories, and I'm sick of dealing with duplicates.
I need a plain list so I can manually do this without having to go into every freakin' directory one-by-one.

Last edited by binkyd; 10-11-2020 at 05:19 PM.
 
Old 10-11-2020, 05:33 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Have you tried sorting the output?
Code:
ls -R1 | sort

Edit -- Nah. That didn't work...well it does show you duplicates, but doesn't tell you where they are.

Last edited by scasey; 10-11-2020 at 05:38 PM.
 
Old 10-11-2020, 05:37 PM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,619

Rep: Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555
Quote:
Originally Posted by binkyd View Post
I want the list to group the the extensions together and I'm getting frustrated.
As per "ls --help", the -X option will sort by extension.

However, if you use -R to list subdirectories recursively, that will output each directory path, then the sorted files within the directory.

One workaround is to use "find" to handle the recursion and pipe the results through "ls -1X" to sort by extension.

 
1 members found this post helpful.
Old 10-11-2020, 06:05 PM   #6
binkyd
Member
 
Registered: Oct 2016
Distribution: Looking again
Posts: 429

Original Poster
Rep: Reputation: 40
@boughtonp - tell me more please

the man page for find is even scarier
 
Old 10-11-2020, 06:05 PM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,619

Rep: Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555
If you're trying to detect duplicate filenames, you might find this more useful than sorting by extension:

Code:
find . -type f -printf '%f\t%p\n' | sort
Then you can check for sequential lines with the same prefix \n[^\t]+\t to locate the duplicates

(Obviously if your filenames might have tabs in, use a different delimiter.)

 
Old 10-12-2020, 11:57 AM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by JeremyBoden View Post
[snip] you mean a bunch of characters after a dot?
[chuckle]

It doesn't much make any difference to UNIX/Linux but some people still expect there to be a "bunch of characters after a dot".[1]

I wonder how they deal with ".tar.bz2"? "Two dots? Argh!!"

But I digress...


[1] -- Except graphical file managers that still want to associate file extensions to applications.
 
Old 10-12-2020, 12:05 PM   #9
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Graphical file managers look at the mime-type of a file - this can occasionally include looking at what follows a dot in the name.
 
Old 10-12-2020, 12:41 PM   #10
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by binkyd View Post
Music directory with mp3, flac and jpg files
I'm trying to get a straight listing so I can actually get rid of duplicates.

None of the programs like fslint, fdupes or shredder [I]can even find duplicates[I] and there's a lot of them - i guess there must be slight differences in the file names (which I can't see) that confuse these programs. (Or are they neurotic about all the details and files must be exact dupes to succeed?)

Looking at about 5000 files here in about 150 directories, and I'm sick of dealing with duplicates.
I need a plain list so I can manually do this without having to go into every freakin' directory one-by-one.
I think that finding all the files in your music directory trees and obtaining their checksums would be a much better means of finding true duplicates.
Code:
CSLIST=/tmp/list-of-music-checksums
while read DIR
do
    find ${DIR} -type f -exec md5sum {} \; >> ${CSLIST}
done < music-directory.lis
sort < ${CSLIST} > ${CSLIST}.sorted
That'll allow you to find duplicates that, for whatever reason, have different filenames but are actually the same file. You should be able to visually examine the sorted list of checksums+filenames so see the duplicates. If there are a ton of duplicates, you can extract the checksums, sort them and run them through uniq(1) to show the duplicates and use each record of that list to grep the original file containing checksums and filepaths.

If you obtain a list of filenames, you'd still need to obtain information about each file and, say, keep the one with the highest bit rate. If you have a mixture of MP3, Ogg, and FLAC, the inspection gets a [ahem] tad more complicated. Personally, I'd keep anything in FLAC format. Period. Then compare any duplicate MP3s and Oggs to see what bit rate they were encoded with and keep the one with the higher bit rate. If you have an MP3 and an Ogg of the same song and the bit rates are close, maybe give each a listen and see which one sounds "better" to your ears. If they're the same bit rate, I'd keep the Ogg. I once found I had a few duplicates that both sounded "OK" but I ran them through "baudline". That showed pretty clearly that one of them had had a low-pass filter applied while it was encoded. That's the one I tossed.

Personally, I don't get too worked up over a few duplicates. I know that some of the 23,000+ (and growing) music files I have on disk are duplicates but I'm not going to quibble if a song appears in an artist's album-specific subdirectory and also in a greatest hits subdirectory. Sure I'd save a little space by replacing all but one of those with a symbolic link but I'd have to weigh whether it's worth the time tracking them down.

Good luck...
 
Old 10-12-2020, 12:48 PM   #11
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,814

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by JeremyBoden View Post
Graphical file managers look at the mime-type of a file - this can occasionally include looking at what follows a dot in the name.
A lot of the time they seem to simply throw up their hands and list darned near everything under /usr/bin as a candidate for opening the file. Fortunately for the OP, music files with no file extensions are rare. I was the one that brought up file managers, not the OP so let's reset our focus. :^D
 
  


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
[SOLVED] rsync: How to use -prune-empty-dirs with the options: "+ */", "+ *.c" AND "- *"? andrew.comly Linux - Server 2 12-14-2015 06:19 AM
What are the options "Nosuid" "mode" "size" in /etc/fstab? tuxfiles.org does not help pstein Linux - Newbie 1 11-16-2012 12:58 AM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
Confused nay Very Confused chrystlenight SUSE / openSUSE 3 08-28-2007 05:57 PM
Confused about kernel compilation options toolkit Linux - General 3 11-21-2002 09:34 PM

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

All times are GMT -5. The time now is 07:47 AM.

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