Automate Linux File Deletion: Script Guide

In Linux, you can use a Shell script to automate the deletion of files. Here is a simple example:

#!/bin/bash

# 设置要删除的文件路径
file_path="/path/to/file.txt"

# 检查文件是否存在
if [ -f "$file_path" ]; then
  # 删除文件
  rm "$file_path"
  echo "文件已删除"
else
  echo "文件不存在"
fi

Save the above script as an executable file, for example delete_file.sh, then run the script in the terminal to automatically delete the specified file. Make sure to replace /path/to/file.txt with the actual file path you want to delete.

bannerAds