Renaming and Moving Files on the Linux Command Line
In the previous section, we discussed the basic commands for managing files and directories in the Linux file system. Now, let's dive deeper into the commands used for renaming and moving files on the Linux command line.
Renaming Files
The mv
(move) command can be used to rename files in Linux. The syntax is as follows:
mv old_filename new_filename
For example, to rename a file from "example.txt" to "new_example.txt", you would use the following command:
mv example.txt new_example.txt
Moving Files
The mv
command can also be used to move files from one location to another. The syntax is similar to renaming files, but you need to specify the destination directory:
mv /path/to/file /new/destination/path
For instance, to move a file named "document.pdf" from the current directory to the "/home/user/documents" directory, you would use:
mv document.pdf /home/user/documents
Batch Renaming and Moving Files
Sometimes, you may need to rename or move multiple files at once. You can use shell scripting or tools like rename
to automate these tasks.
For example, to rename all files with the extension ".txt" to have the extension ".doc", you could use the following command:
rename 's/.txt$/.doc/' *.txt
By understanding these file renaming and moving commands, you can efficiently organize and manage your files on the Linux command line.