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 08-19-2010, 06:02 AM   #16
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295

Hi,

When executed from /home/tst (as indicated by OP), you don't have to cd into the directory if you provide the abc or xyz in the statement like this:
Code:
#!/bin/bash
for file in xyz/*
do
    filename=`basename $file`
    [[ -e "abc/$filename" ]] && rm -rf "abc/$filename"
done
This works when executed from the parent directory of abc / xyz without the need to change directory. You could also put both paths in variables and use those in combination with the filename only or do it like in your example.

Like with a lot of things there is always more than one solution to a problem

Kind regards,

Eric
 
Old 08-19-2010, 06:12 AM   #17
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Yes I thought that that will work although basename will cause overhead. Also I was not referring to that script. I'm referring to the scripts posted here that didn't remove the directory part and still appends the variable to the second directory.

Anyway instead of basename you can also use an alternative like this:
Code:
for A in abc/*; do
    [[ -e xyz/${A##*/} ]] && rm "$A"
done
 
Old 08-19-2010, 06:14 AM   #18
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by konsolebox View Post
Yes I thought that that will work although basename will cause overhead. Also I was not referring to that script. I'm referring to the scripts posted here that didn't remove the directory part and still appends the variable to the second directory.

Anyway instead of basename you can also use an alternative like this:
Code:
for A in abc/*; do
    [[ -e xyz/${A##*/} ]] && rm "$A"
done
As long as you don't mind depending on bash, cause this is incompatible with about any other shell around.
 
Old 08-19-2010, 06:42 AM   #19
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Sure it was only for bash.

Anyway I think it's also compatible with PD KSH at least. Zsh is probably different and I don't know with Ksh, and [d]ash. This may also be a work around:
Code:
for A in abc/*; do
    [ -e "xyz/${A/*\/}" ] && rm "$A"
done
Code:
for A in abc/*; do
    IFS=/
    set -- $A
    [ -e "xyz/$2" ] && rm "$A"
done
Edit: All shells based from the original shell are compatible with the former method (revised to not use [[):
Code:
cd abc
for A in *; do
    [ -e "../xyz/$A" ] && rm "$A"
done

Last edited by konsolebox; 08-19-2010 at 06:52 AM.
 
Old 09-09-2013, 01:52 PM   #20
lannykint
LQ Newbie
 
Registered: Sep 2013
Posts: 1

Rep: Reputation: Disabled
Duplicate Files Deleter DuplicateFilesDeleter is a simple, but effective tool to locate duplicate files in one or more selected search paths. It scans the files and compares them based on Byte for Byte Comparison, which ensures 100% accuracy. You can then choose to delete the selected duplicate or original files. The program is multi-threaded and performs scans quickly.
 
  


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
How to AUTO remove duplicate files drudge Linux - Newbie 9 03-13-2013 02:19 PM
Script to remove duplicate jpg files ski_phreak Programming 1 05-26-2010 08:22 AM
How to use find and remove folders and files Drigo Linux - Newbie 1 05-31-2009 11:53 PM
remove ~ from all files and folders BoraX Linux - General 1 10-25-2006 07:58 PM
need app to remove duplicate files from the filesystem Ynot Irucrem Linux - Software 2 05-19-2005 12:35 PM


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