Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-03-2010
Registered User
 

Join Date: Aug 2010
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Question Remove files

I know that rm -i, asks a user before removing a file. What I need to accomplish is removing files from a different directory without switching to that directory. Example: I'm currently in directory dog and I want to remove all the files of a certain name in directory cat, but from within the dog directory. Please help.
Sponsored Links
    #2  
Old 09-03-2010
Resident BOFH
 

Join Date: Dec 2007
Posts: 1,100
Thanks: 2
Thanked 76 Times in 74 Posts
use the full path


Code:
rm /foo/bar/cat/other.file

Sponsored Links
    #3  
Old 09-03-2010
Scrutinizer's Avatar
mother ate her
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 5,371
Thanks: 80
Thanked 1,107 Times in 1,011 Posts
Do you mean:

Code:
cd dog
rm -i /path/to/cat/pattern-to-be-removed*

    #4  
Old 09-03-2010
Registered User
 

Join Date: Aug 2010
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Angry Thanks

I'll try this.

---------- Post updated at 10:47 PM ---------- Previous update was at 08:39 PM ----------

Ok I have to write a script to make this work:


Code:
!#/bin/bash

read -p "Enter week you would like to delete files: " $num
rm -i /week$num/smiley*

not sure why it doesn't work. I'm working from a week5 directory and it tells me that the directory doesn't exists.

Last edited by Scott; 09-04-2010 at 05:58 AM.. Reason: Code tags, please...
Sponsored Links
    #5  
Old 09-03-2010
Resident BOFH
 

Join Date: Dec 2007
Posts: 1,100
Thanks: 2
Thanked 76 Times in 74 Posts
the first line should be
Code:
#!/bin/bash


and your read statment should look like this -- no $ in the variable name

Code:
read -p "Enter week you would like to delete files: " num

The Following User Says Thank You to frank_rizzo For This Useful Post:
smiley76112 (09-04-2010)
Sponsored Links
    #6  
Old 09-04-2010
Registered User
 

Join Date: Aug 2009
Location: France
Posts: 236
Thanks: 10
Thanked 46 Times in 45 Posts
Unless you're on a very special system, rm /week$i... probably won't work,
if you need to access the week5's parent directory, use ..(double .). Here are a few examples:

Code:
week5$ ls
[list of files inside week5 directory]
week5$ ls ..
[list of files in the parent folder]
week5$ ls ../week3
[list of files inside week3 directory, relatively from week5]
week5$ cd ..
[Go up to the parent]
parent$


Last edited by tukuyomi; 09-04-2010 at 10:17 AM.. Reason: Formating
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove .nfs and .swp files northwest Shell Programming and Scripting 1 09-24-2009 11:29 PM
how to remove the files along with its link files Ramesh_srk UNIX for Advanced & Expert Users 1 07-02-2009 06:22 AM
compare two files and to remove the matching lines on both the files shellscripter Shell Programming and Scripting 4 06-20-2009 08:48 AM
Remove ^M (CR) from Unix Files acheepi Shell Programming and Scripting 7 07-18-2005 09:28 AM
remove files Nisha Shell Programming and Scripting 7 06-26-2002 12:04 AM



All times are GMT -4. The time now is 04:08 AM.