Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Linux by (5k points)
edited by

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

1 Answer

0 votes
by (10.2k 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
asked Feb 25, 2021 in SQL by rahulnayar01123 (5k points)
0 votes
1 answer
asked Nov 30, 2020 in Linux by dev_sk2311 (44.4k points)
0 votes
1 answer

Browse Categories

...