To delete files on a Linux server, you can use the rm (remove) command. Here's how it works:
Basic Syntax:
rm [options] filename
Example:
rm oldfile.txt
This deletes oldfile.txt in the current directory.
Delete Multiple Files:
rm file1.txt file2.txt file3.txt
Recursive Deletion (for Directories):
Use -r (or --recursive) to delete a directory and its contents:
rm -r mydirectory/
Force Deletion (no Confirmation Prompt):
Use -f (or --force) to skip confirmation warnings:
rm -f importantfile.txt
Combine Options (Recursive + Force):
rm -rf mydirectory/
⚠️ Warning: rm -rf is powerful and can permanently delete data. Use with caution.
If you want to delete all .log files in /var/log/myapp/ without confirmation:
rm -f /var/log/myapp/*.log
For secure file deletion (overwriting data before removal), consider tools like shred:
shred -u sensitivefile.txt
If managing files on a Tencent Cloud Linux server, you can execute these commands via SSH or use Tencent Cloud Console > Cloud Virtual Machine (CVM) > Login to Server. For automated cleanup, consider Tencent Cloud Batch Compute or Serverless Cloud Function (SCF) for scheduled tasks.