CentOS Linux Server Guide

Remove or delete file in CentOS Linux

rm - Linux command to remove or delete files or directories



SYNOPSIS
rm [OPTION]... FILE...

DESCRIPTION
This manual page documents the GNU version of rm. rm removes each specified file. By default, it does not remove directories.

If a file is un-writable, the standard input is a tty, and the -f or --force option is not given, rm prompts the user for whether to remove the file. If the response is not affirmative, the file is skipped.

 

 
command and options Description

rm

rm -i

 

remove file/files in interactive mode. For most of the Linux distros, rm is alias to rm -i y by default. When a file is going to be deleted, the system will ask your for confimation, you have to type in Y or y or yes then press <Enter> to perform delete.
# ls
1.txt 2.txt myDir newmyDir


#
rm 1.txt
rm: remove regular empty file `1.txt'? yes


#
rm -i 2.txt
rm: remove regular empty file `2.txt'? yes

 

 

rm -f

-f, means to tell the server to remove the file in 'force' mode, with this option the system will remove the files automaticatlly without asking the following question

rm: remove regular empty file....

Warning: Be extra careful when you using -f option.


#
rm -f try_force_remove_file.txt
 

 

rm -v

The is the verbose mode, this will show you what has been done by the system.
 

# rm -v test_verbose_mode.txt
rm: remove regular empty file `test_verbose_mode.txt'? yes
removed `test_verbose_mode.txt'

 

rm -r

 

This will ask the system to remove directories and their contents recursively. At the below example we deleting aFolder (subfolder), nFolder(parent folder, and a_files.txt (files)

#ls -lR nFolders/
nFolders/:
total 12
-rw-r--r-- 1 root root 0 Nov 29 17:40 a_files.txt
drwxr-xr-x 2 root root 4096 Nov 29 17:40 aFolder

nFolders/aFolder:
total 4
-rw-r--r-- 1 root root 0 Nov 29 17:40 aFolder_files


#
rm -rfv nFolders/
removed `nFolders//aFolder/aFolder_files'
removed directory: `nFolders//aFolder'
removed `nFolders//a_files.txt'
removed directory: `nFolders/'

 

 

Back to Managing Files and Folders in CentOS Linux



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy