LinuxQuestions.org
Review your favorite Linux distribution.
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-30-2015, 02:01 AM   #1
chatar
LQ Newbie
 
Registered: Jan 2015
Posts: 1

Rep: Reputation: Disabled
Only keep one version for each file and delete others


down vote favorite


I have list of n files and some of the files are duplicate. How can I keep only 1 copy and delete others?

File format - x_y_z_timestamp.tgz, x1_y1_z1_timestamp.tgz ... xn_yn_zn_timestamp.tgz

e.g.

x_y_z_20150113060314.tgz
x_y_z_20150113114533.tgz
x1_y1_z1_20150113060314.tgz
x1_y1_z1_20150113114533.tgz
x2_y2_z2_20150113060314.tgz
x2_y2_z2_20150113114533.tgz

Outcome -

x_y_z_20150113114533.tgz
x1_y1_z1_20150113114533.tgz
x2_y2_z2_20150113114533.tgz
 
Old 01-30-2015, 04:15 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Here it is:

Code:
for f in *; do
 if [ -e "$f" ]; then
  for t in *; do
   if [ "$f" == "$t" ]; then
    true
   else
    cmp -s "$f" "$t"
    [ $? -eq 0 ] && rm "$t"
   fi
  done
 fi
done
 
Old 01-30-2015, 06:54 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
do you need this: http://www.filebuzz.com/fileinfo/316...for_Linux.html
you can find several similar tools on the net
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Shell script to get name of file, delete original file, rename blank file chrisgti Linux - General 11 09-15-2012 03:49 AM
Create the file, write into that file but can't delete file in Linux pandunr Linux - Newbie 3 06-15-2011 09:45 AM
[SOLVED] How to find duplicate files and delete all except most recent version rjo98 Linux - Newbie 4 08-17-2010 11:13 AM
i can't delete last version secretboy Linux - Software 4 11-17-2004 03:48 AM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 03:46 AM


All times are GMT -5. The time now is 04:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration