Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using GNU/Linux and BASH shell,

What i wanted to do is in server is to

i need to be able to download the files stating with B* and D* and then rename them to ~B* and ~D*(same file name just ~ in-front)

i wrote following which works fine for the downloading part ideally i would like it to use ls command output as well but dont know how to do that.

cd inbox
get D*
get B*
ls B*|rename $0 ~B.* 

Any idea ?

ideally what i would like to do is ls command to send the list of files one by one to the get command and then the once the get command is completed i want rename command executed renaming the server files

share|improve this question

Do not execute this within your ftp session. Come out and execute it:

ls [BD]* | sed 's/.*/mv & ~&/' | sh
share|improve this answer
does anyone has any idea or any reference guide to what they mean in /s.*/ what is "s" i expect it a regular expression but i am used to php regular exp but this seems to be totally different... any link please for this ref ? i.e rename "s/ *//g" *.mp3 – user1179459 Oct 18 '12 at 3:24
.* will match your entire file name and in the replacement section, mv command is generated. This mv command is executed using a shell. – Guru Oct 18 '12 at 3:25
Can you expound upon this? Why is it so important to not execute within the ftp session. – KronoS Oct 18 '12 at 3:47
@KronoS my mistake, it can very well be part of the ftp session itself with an exclamation(!) in the beginning of ls. – Guru Oct 18 '12 at 4:24
If it is executed in the ftp session (without the !) then it will attempt to do the rename on the remote server, or just fail. – HayekSplosives Oct 22 '12 at 15:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.