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 shell works?

1 Answers  


What are the additional egrep symbols?

2 Answers  


How do I run a powershell script?

0 Answers  


How can I set the default rwx permission to all users on every file which is created in the current shell?

0 Answers  


Create a bash shell script to sort and then uniq the file from the command line & store it to a new file and output the results to the screen. Name this script "sortAndUniq.sh"

5 Answers  






RAM one table colums a1,a2,a3,a4 respective values 2,4,7,8 KRISH one table colums a1,a2,a3,a4 respective values 3,4,6,9 IN RAM & KRISH a4 column if comparing values RAM A4 - KRISH A4 ( 8-9 =1 THEN print 5 or (RAM) a4 value 10 KRISH a4 values 2 then 10 -2 =8 print 5*8=40 or diff 5 print same

1 Answers   Tech Mahindra,


What is the way to do multilevel if-else's in shell scripting?

0 Answers  


How can I send a mail with a compressed file as an attachment?

0 Answers  


Is shell script a programming language?

0 Answers  


How does ls command work?

0 Answers  


Why is used in shell scripting?

0 Answers  


What is the use of echo in shell script?

0 Answers  


Categories