Last updated on May 30th, 2018 at 09:56 am
Rename/Move :mv is Linux command that can use to rename files and directories; it also used to move files and directories from one location to another, same like cut and paste command in MS Windows.
Syntax of mv command:
$ mv [options] source dest
To rename mydata.txt to mynewdata.txt, following command will use:
# mv mydata.txt mynewdata.txt
Absolute path will be used if the file is not on present working directory.
Absolute path example:
# mv /tmp/mydata.txt /home/haider/mynewdata.txt
Above command will cut mydata.txt file from /tmp directory and paste it with mynewdata.txt into /home/haider directory with new name mynewdata.txt. This command is performing both functions at once, Move and Rename.
TIP: You can move files based on extensions, see following command:
# mv /invoices/*.xls /Excel-Files
Now mv command will look all the files with .xls extension in /invoices directory and move into /Excel-Files directory.
Delete files and directories:
The rm command is used to remove or delete files in Linux. By default, it does not remove directories; will see below how to remove directories with rm command.
# rm [Option] [File/Directory]
# rm mydata.txt
To delete directories including all subdirectories use the â€“r option as follows:
# rm -rf old-backups
In above command I used, r (recursive) and f (force) .
If you like this Post, please give us your valuable feedback by pressing Vote Up / Vote Down Button. Thanks.