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.
use the full path
rm /foo/bar/cat/other.file
Do you mean:
cd dog
rm -i /path/to/cat/pattern-to-be-removed*
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:
!#/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.
the first line should be
#!/bin/bash
and your read statment should look like this -- no $ in the variable name
read -p "Enter week you would like to delete files: " num
1 Like
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:
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$