Renameing files with the find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renameing files with the find command
# 1  
Old 04-03-2002
Bug Renameing files with the find command

Hi,
I am attempting to rename files in a directory tree, using the find command:

find . -name "file-src*" -exec mv {} file-tgt \;

however, this only moves the file to the current dir: I have also tried:

mv 'find . -name file-src' file-tar

find . -name "file-src*" -exec mv {file-tgt} \;

etc, but to no avail. Any help would be appreciated.

Smilie
# 2  
Old 04-03-2002
There might be better ways to do this.

for i in `find your_dir -type f -name '*'`
do
mv $i $i.mv
done
# 3  
Old 04-03-2002
thanks - I've tried this statement, however I still get the syntax error for the move command; when I replace the mv with echo $i; it writes out the find argument.

e.g. with the move cmd:
for i in 'find . -type f -name "file*" '
do
mv $i $i.bak
done

Output is:
$mv: invalid option

and the echo $i

for i in 'find . -type f -name "file*" '
do
echo $i
done

'find . -type f -name "file*"

Smilie
# 4  
Old 04-03-2002
Are you using single quotes, or backticks? ' or `
Backticks will do what you want. (It's the ` character on the upper-left corner of a standard PC keyboard, usually with the ~ )

If you're using a shell like bash or ksh, you could do it like this:
[...] for each in $(find . -name blah) [...]
But most shells will recognize:
[...] for each in `find . -name blah` [...]
# 5  
Old 04-03-2002
Dont use ' (single quote). Use ` (dont know what it is called but it is left to the '1' key on the key board and above 'TAB')

Smilie
# 6  
Old 04-03-2002
Sorry LivinFree. probably we replied at the same time.
# 7  
Old 04-03-2002
Good stuff -that works fine. Yah I've had some problems using the ' and ` with commands in the past ....
Thanks again.
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command when there exist many files

I want to run find and wondering if it struggles when there are many files. I have tried and does not seem to complain. Is this correct? (8 Replies)
Discussion started by: kristinu
8 Replies

2. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

3. Shell Programming and Scripting

Find command to delete the files

Hi All, I've created 2 files touch -t 201309101234 aa10 touch -t 201309111234 aa11 Exact 60 days before from today date is SEPT 12th . As per the following command as i gave +60 means the files which were created before sept12th should be deleted find /etc/logs/*aa* -type f -atime +60... (5 Replies)
Discussion started by: smile689
5 Replies

4. UNIX for Dummies Questions & Answers

Find command to delete old files

Hi, I want to delete all the log files that was created on year 2008. My command is not working. Any idea? find . -name '*.log' -mtime 1460 -exec ls -lt {} \; Thank you. (2 Replies)
Discussion started by: samnyc
2 Replies

5. UNIX for Dummies Questions & Answers

Command to find files

Hi All, Can anyone give me the command to copy files from 03-Mar-2013 to 07-Mar-2013 in folder. there are nearly 40+ thousand files in directory , so I just need files from Mar 3rd to Mar 7th and copy them to a location . Need quick help pls (2 Replies)
Discussion started by: rockingvj
2 Replies

6. UNIX for Dummies Questions & Answers

command to find files

Hi folks, What command/commands I have to run to find the files including their folder/subfolder which contain word-a, word-b etc. e.g. I expect to find the names of the files including their folders which contain "domain", "subdomain/sub domain", "free domain". etc. TIA B.R. satimis (11 Replies)
Discussion started by: satimis
11 Replies

7. Shell Programming and Scripting

what is the find to command to find the files created last 30 days

what is the find to command to find the files created last 30 days (5 Replies)
Discussion started by: rajkumar_g
5 Replies

8. UNIX for Dummies Questions & Answers

find command -- listing files twice

I noticed the other day that after i used the find command to search for some files, the computer listed them twice -- first with just the names of the files (meaning ./(then the individual file names), then with the directory name, followed by the file names (./directory name/file name). I was... (2 Replies)
Discussion started by: Straitsfan
2 Replies

9. Shell Programming and Scripting

Deleting files using find command

I want to find the files and delete all the files except the last file. I am using find command , I am sending the find output to a file and getting all the lines except the last one and sending it to the remove command . This is not working. can anyone help me out to do it in the find command... (8 Replies)
Discussion started by: deepaklanka
8 Replies

10. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies
Login or Register to Ask a Question