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

on “sed” command EmpData(Sample Database) 1122|j.b. saxena |g.m. |account |12/12/52|6000 2233|n.k. gupta |d.g.m |sales |31/12/40|9000 4545|anil agarwal |director |account |06/07/47|7500 5656|lalit choudhury |executive|marketing|07/09/50|5000 1265|chanchal singhvi|g.m. |admin |12/09/63|6000 0110|shyam saksena |chairman |marketing|12/12/43|8000 5566|jai sharma |director |account |23/12/89|7000 7733|jayant |d.g.m |sales |29/02/70|6000 1. From the above database substitute the delimiter of first 3 lines with “ : “ 2. From the above database substitute the delimiter with “ : ” 3. Insert the string “ XYZ Employees” in the first line. 4. Store the lines pertaining to the directors, d.g.m and g.m into three separate files. 5. Using address store first 4 lines into a file Empupdate. 6. Find the pattern “account” in the database and replaces that with “accounts”. 7. Select those lines which do not have a pattern “g.m”. 8. Insert a blank line after every line in the database.

0 Answers  


How important is shell scripting?

0 Answers  


What are the different commands available to check the disk usage?

0 Answers  


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

4 Answers   ANZ,


What is echo in shell?

0 Answers  






How many prompts are available in a UNIX system?

1 Answers  


How do you know which shell I am using?

0 Answers  


What is shell company all about?

0 Answers  


How do I debug a shell script?

0 Answers  


How Connect to a Database in Shell Programming?

4 Answers   Syntel,


what is the difference between writing code in shell and editor?

1 Answers  


How to create environment variables?What are the conditions for creating variables?

1 Answers   Infosys, Wipro,


Categories