Rename files without using for loop


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Rename files without using for loop
# 1  
Old 12-03-2009
Rename files without using for loop

Hi,

Is it possible to rename files at a time in a directory without using the for loop. (ex: intial filename- abc.txt to abc.tmp or abc.txt.tmp)
I need to rename the files in a remote directory to which I'm connecting thru tectia sftp. The commands 'mv', 'for', 'echo' do not work.

I have to rename these files 'mget' them to the local folder and based on the new filename (new extension of the files), I would want to delete the files (rm *.tmp) from remote folder which I have already downloaded.

Please let me know your ideas.
Thanks.
# 2  
Old 12-04-2009
I think rename command is available in sftp just go through the man page of sftp
# 3  
Old 12-07-2009
Yes, 'Rename' command works. But I have to rename all the files that are present in the directory at a time without using a 'For' loop.

Is that possible? Is there any command or idea for doing this?

Thanks.
# 4  
Old 12-07-2009
If I am correct in assuming that you are trying to collect some files to process, then delete the files from the remote machine so that the files are not processed a second time.
Then.

Use mget to get all the files the first time.
As you process each received file append a text file that can be used as input for your next sftp session,
rm file1
rm file2
etc

Then before you start your next sftp session, append
mget *
to the end of the text file and run
sftp host <text.file

The advantage to doing this is that the files remain on the remote machine until you are satisfied that you have successfully processed them.
Also you do not have to rename anything.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to rename files in bash loop

I am trying to use sed to rename all .txt files in /home/cmccabe/test. However, I am getting an error that I seems to be putting the files in a new directory s, instead of in the original. Thank you :). bash # rename classified cd /home/cmccabe/test pattern2_old="_classify"... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

3. Shell Programming and Scripting

Loop through the dir and Rename zip files and their underlying text file.

I have files in the ABC_YYYYMMDD.zip format under a directory. Each zip file contains A text file in the ABC_YYYYMMDD.txt format. I am trying to create a script that will Rename the zip files and their underlying text file replacing the datepart in them with . For eg: in the case of... (1 Reply)
Discussion started by: bash987
1 Replies

4. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

5. UNIX for Dummies Questions & Answers

For Loop To Rename Multiple Files Finds One Non-existant File

Okay so here's something that's confusing me: I have a script that's designed to remove the words "new_" from the front of any file except two exceptions and it looks something like this... for i in new_* do if ] && ]; then j=`echo "$i"|cut -c5-` mv $i $j fi done ... (5 Replies)
Discussion started by: Korn0474
5 Replies

6. Linux

rename files using loop with different name

Hi, i need to write a shell script where i have to loop through all the file in a directory and rename them based on below condition. file1.dat file2.dat file3.dat the above files has to be moved to another directory like below file1_201001.dat file2_201002.dat file3_201003.dat... (3 Replies)
Discussion started by: feroz
3 Replies

7. UNIX for Dummies Questions & Answers

Rename files with sed in an until loop (double post)

I want to change the name of some of my files (mypics-0001, mypics-0002, mypics-0003.....mypics-0240) and I want to double check to see if this code is right: x=0 until do sed 's/mypics\-*/bday/g' done Would this change all of my file names to "bday0001....bday0240"? Please let me... (0 Replies)
Discussion started by: jvpike
0 Replies

8. Shell Programming and Scripting

rename files Ax based on strings found in files Bx

Hi, I'm not very experienced in shell scripting and that's probably why I came across the following problem: I do have several hundred pairs of text files (PF00x.spl and PF00x.shd) where the first file (PF00x.spl) needs to be renamed according a string that is included in the second file... (12 Replies)
Discussion started by: inCH
12 Replies

9. Shell Programming and Scripting

Rename files

Hello, I've a list of file like this img_001 img_22 img_44 and I would rename all with this form photo_0001 photo_0002 photo_0003 photo_0004 suggestions?Thanks to all. (2 Replies)
Discussion started by: cv313x
2 Replies

10. Shell Programming and Scripting

How To Rename a File in a loop

Hi All, I am getting all .txt files from a particular directory, as in a following example: for FILE in `echo $v_filename` do done here i need to rename each original file with a new name for e.g. we have 3 files in test directory /test a.txt b.txt c.txt These files are in a... (3 Replies)
Discussion started by: sandeepb
3 Replies
Login or Register to Ask a Question