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

What is shell and terminal?

0 Answers  


How would you print just the 25th line in a file using smallest shell script?

4 Answers  


How to get script name inside a script?

0 Answers  


What is the difference between a shell variable that is exported and the one that is not exported?

6 Answers  


The information of the two files should be redirect to Third file in such a way that, the third file contain the information like this. 1st line in third file should be from 1st file 2nd line in Third file should be from 2nd file 3rd line in Third file should be from 1st file 4th line in Third file should be from 2nd file - - so on

2 Answers   Caritor,






What does chmod do?

0 Answers  


What is shell application?

0 Answers  


What is bash shell command?

0 Answers  


How will you list only the empty lines in a file (using grep)?

4 Answers   ANZ,


What are different types of shell?

0 Answers  


What is path variable bash?

0 Answers  


What is a beat in a script?

0 Answers  


Categories