rm: It is used to remove/delete the file from the directory.
Syntax: rm [options..] [file|directory]
- Files can deleted with rm. It can delete more than one file with a single invocation. For deleting a single file we have to use rm command with the filename to be deleted.
- The deleted file can’t be recovered. rm can’t delete the directories. If we want to remove all the files from the particular directory we can use the * symbol.
- Ignore nonexistent files, and never prompt before removing.
- Prompt before every removal.
$ rm myfile.txt
- Remove the file myfile.txt. If the file write-protected, you will prompt to confirm that you really want to delete it.
$ rm *
- Remove all files in the working directory. If it write-protected, you will prompt before rm removes it.
$ rm -f myfile.txt
- Remove the file myfile.txt. You will not prompt, even if the file write-protected; if rm can delete the file, it will.
$ rm -f *
- Remove all files in the working directory. rm will not prompt you for any reason before deleting them.
$ rm -i *
- Attempt to remove every file in the working directory, but prompt before each file to confirm.
mv: It used to move/rename the file from one directory to another.
Syntax: mv [options] oldname newname
- mv command which is short for a move.
- Moreover, mv command is different from cp command as it completely removes the file from the source and moves to the directory specified, where cp command just copies the content from one file to another.
- mv has two functions: it renames a file and it moves a group of files to a different directory. Mv doesn’t create a copy of the file, it merely renames it. No additional space consumed on disk during renaming. For example, if we rename a file os to os1 and then if we try to read file os we will get the error message as it renamed to os1 there is no existence of the file named os.
- mv will move the file(s) without prompting even if it writing over an existing target. Note that this is the default if the standard input is not a terminal
- Prompts before overwriting another file
$ cat file1
- $ mv file1 file2
rename file1 to file2
- If the destination file doesn’t exist it will create. mv can also use to rename a directory. A group of files can also move to a directory. mv doesn’t prompt for overwriting destination file if it exists.