是的,PHP 可以在 Linux 系统下通过命令行执行文件操作
- 创建文件:
echo "Hello, World!" > hello.txt
- 读取文件内容:
cat hello.txt
- 追加内容到文件:
echo "This is a new line." >> hello.txt
- 删除文件:
rm hello.txt
- 重命名文件:
mv old_name.txt new_name.txt
- 检查文件是否存在:
if [ -e "hello.txt" ]; then echo "File exists."; else echo "File does not exist."; fi
- 获取文件权限:
ls -l hello.txt
- 更改文件权限:
chmod 644 hello.txt
- 创建目录:
mkdir new_directory
- 删除目录:
rmdir new_directory
这些仅仅是 PHP 在 Linux 系统下执行文件操作的一些基本示例。PHP 还提供了许多其他函数来处理文件和目录,如 file_get_contents()
、file_put_contents()
、file_exists()
等。