To rename a file in Bash, you can use the mv
command. For example, to rename a file called oldfile.txt
to newfile.txt
, you would use the following command:
$ mv oldfile.txt newfile.txt
This will rename the file from oldfile.txt
to newfile.txt
. Note that the mv
command can also be used to move a file to a different directory, by specifying the destination directory as part of the command. For example, to move the oldfile.txt
file to the /tmp
directory and rename it to newfile.txt
, you would use the following command:
$ mv oldfile.txt /tmp/newfile.txt
This will move the oldfile.txt
file to the /tmp
directory, and rename it to newfile.txt
.
Overall, the mv
command is a versatile and powerful tool for renaming and moving files in Bash. It is a good idea to become familiar with its usage and options, so that you can use it effectively in your own scripts and command-line work.