How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh".
Appreciate your inputs.Thanks.

Answers were Sorted based on User's Feedback



How do you rename the files(*.sh) with file names containing space in it?for example "interview..

Answer / senthil m

For single file, you can do following command;

mv interview\ question.sh interview-question.sh

For multiple files on the current working folder;

for i in *\ *.sh
do
j=`echo $i|sed "s/ /-/g"`
mv "$i" $j
done

Is This Answer Correct ?    7 Yes 0 No

How do you rename the files(*.sh) with file names containing space in it?for example "interview..

Answer / chetan

sorry, forgot to keep the "mv" command in my last post.

for i in *.sh
do
n=`echo $i|sed 's/ /-/g'`
mv "$i" $n
done

Is This Answer Correct ?    5 Yes 1 No

How do you rename the files(*.sh) with file names containing space in it?for example "interview..

Answer / abc

For single file, you can do following command;

mv "interview question.sh" interview-question.sh

Is This Answer Correct ?    4 Yes 0 No

How do you rename the files(*.sh) with file names containing space in it?for example "interview..

Answer / indusharma5

I tried following, but it doesn't work.
find . -name "*.sh" -0 -print0| xargs -n1 -I{} -0 sh -c '`mv {} echo "{}"|sed -n 's/ /-/g'`'

Is This Answer Correct ?    2 Yes 0 No

How do you rename the files(*.sh) with file names containing space in it?for example "interview..

Answer / chetan

for i in *.sh
do
echo $i|sed 's/ /-/g'
done

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Shell Script Interview Questions

How do scripts work?

0 Answers  


What is the use of script interpreter in shell scripting?

3 Answers  


Is shell scripting useful?

0 Answers  


give me some website where i can get unix and testing meterials

1 Answers  


Determine the output of the following command: name=shubham && echo ‘my name is $name’.

0 Answers  


How will you connect to a database server from linux?

0 Answers  


Is scripting and coding the same thing?

0 Answers  


What is a program shell?

0 Answers  


is this growing field and what is average package in this?

0 Answers  


Explain about gui scripting?

0 Answers  


how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com

0 Answers  


How can any user find out all information about a specific user like his default shell, real-life name, default directory, when and how long he has been using the system?

0 Answers  


Categories