Tag Archives: rm

How to delete files in Linux

During everyday usage of the Linux operating system, you will encounter situations when you will need to delete one or more files from the file system.

The easiest way to delete a file from BASH is to issue the rm command.

In most Linux distributions the rm command is an alias for “rm -i”, so when you enter rm in the shell, the alias points to rm -i (the “i” stands for interactive).

[root@nyx backup]# rm wordpress.sql
rm: remove regular file `wordpress.sql'? y
[root@nyx backup]#

Delete the file without a confirmation:

[root@nyx backup]# rm -f wordpress.sqlwordpress.sql
[root@nyx backup]#

Delete all the files in the folder called “backup”.  -r stand for recursively, -f  is forcing the delete command without a confirmation. Be careful when you use “-r -f” !

[root@nyx backup]# rm -r -f ./backup/
[root@nyx backup]#

rm

 

 

 

Find files older than x days and delete them:

find /home/backup/* -mtime +30 -exec rm {} \;  
## find files older than 30 days from the /home/backup directory and delete them
Posted in BASH, How to. Tagged with , , , , .