The Linux mv command can rename a file within the same directory. It changes the file’s name without editing its contents.
Rename a file
Open a terminal and go to the directory containing the file. Replace this example path with yours:
cd /home/user/docs/filesCheck the existing names, then rename the file:
ls -l
mv -iT -- "fileA.txt" "fileB.txt"With GNU mv, -i asks before overwriting an existing destination file, and -T prevents the destination being treated as a directory. Quotes support names containing spaces; -- separates options from filenames.
Read any prompt carefully and decline if the destination must be retained. You need the appropriate directory permissions.
Use full paths instead
You can rename the same file without changing directory:
mv -iT -- "/home/user/docs/files/fileA.txt" "/home/user/docs/files/fileB.txt"If the source and destination directories differ, the command also moves the file. Confirm the result:
ls -l -- "/home/user/docs/files/fileB.txt"Update any scripts or application configuration that depend on the old filename.