The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting only directory not files manoj.solaris Linux 13 05-02-2008 08:24 AM
deleting specific lines from all files in a directory vrms UNIX for Dummies Questions & Answers 3 04-25-2008 11:08 AM
deleting empty files in a directory berlin_germany Shell Programming and Scripting 5 01-26-2007 03:47 PM
UNIX Shell script to chec timeout period when collecting files in directory - HELP Danny Fang Shell Programming and Scripting 1 03-23-2006 08:41 PM
Accidentally deleting directory/files milhan UNIX for Advanced & Expert Users 4 08-27-2003 09:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2006
onlyc onlyc is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 7
Question shell script: deleting files from a directory

i have the following problem:
use shell script:

Two directories have to be searched for files havin the same name.
then delete these files from one of these directories.
the directory names have to be accepted as command line arguments.

what i have done till now is:

1. run a loop through both directories and
2. tried to compare the filenames.
3. i am not able to compare the names of files since the filenames are extracted alongwith the directory (dirname/filename)
4. i tried using cut.
  #2 (permalink)  
Old 07-09-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Suppose you want to compare two directories test1 and test2 and want to delete files from test2 directory if found in test1, you can do something like this:
Code:
#! /bin/ksh
for i in ./test1/*; do
filename=`basename $i`
if [[ -f ./test2/$filename ]]; then
rm ./test2/$filename
fi
done
Regards,
Tayyab
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0