Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (6.1k points)
edited by

Is there any way to change a directory name without using 'rename' function and 'mv' command?

1 Answer

0 votes
by (11.7k points)

Using the command given below, the directory can be renamed in Linux.

mv /home/user/oldname /home/user/newname

If you want to rename multiple directories on Linux, you need to create a new script file and use the “mv” command in a “for” loop to iterate over directories.

Code snippet:

#!/bin/bash 

# Takes directory entries specified and renames them using the pattern provided.

for directory in *

do

    if [ -d "$directory" ]

    then

      mv "${directory}" "${directory}_temp" || echo 'Could not rename '"$directory"''

    fi

done

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
4 answers
asked Feb 25, 2021 in SQL by rahulnayar01123 (6.1k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...