Meysam
0
Q:

how to rename a file in linux

mv oldnamefile1 newnamefile1
9
To use mv to rename a file type mv , a space, the name of the file, a space, and the new name you wish the file to have.
Then press Enter. You can use ls to check the file has been renamed
eg. mv demo.py demo1.py
1
# Basic syntax using rename:
rename search_string replacement_string files

# Example usage:
# Say you have a directory containing the following files:
badly_name_file_1.txt
badly_named_file_1.txt
badly_named_file_2.txt
badly_named_file_3.png

rename txt png *txt # This would change all extensions to .png, e.g.:
badly_name_file_1.png
badly_named_file_1.png
badly_named_file_2.png
badly_named_file_3.png

# *txt returns all files that end in txt and then if txt is found in the
#	file name, it gets replaced with png

rename named speled badly* # This would change named to speled in all
#	files that begin with badly, e.g.:
badly_name_file_1.txt # This one is skipped because it doesn't have named
badly_speled_file_1.txt
badly_speled_file_2.txt
badly_speled_file_3.png
1
# Linux - Bash

# syntax:
mv <source-filename> <destination-filename>

# example-1 (fundamental - no switches):
mv "Initial_File_Name.txt" "New_File_Name.txt"
4
mv oldfile.txt newfile.txt
0
mv oldname newname
3
mv "old location" "new location"

mv /home/user/my_static /home/user/static

mv "file1.ext" "file2.ext"
3
mv (option) filename1.ext filename2.ext
5

New to Communities?

Join the community