这是我的资料来源:
#!/bin/bash
echo "Running script to free general cached memory!"
echo "";
echo "Script must be run as root!";
echo "";
echo "Clearing swap!";
swapoff -a && swapon -a;
echo "";
echo "Clear inodes and page file!";
echo 1 > /proc/sys/vm/drop_caches;
echo "";
它清除缓存和内容,并回显它需要以root用户身份在终端中运行。我基本上只是希望脚本检测到没有以root身份执行时停止运行。
例:
"Running script to free general cached memory!"
"Warning: script must be run as root or with elevated privileges!"
"Error: script not running as root or with sudo! Exiting..."
如果以提升的特权运行,它将正常运行。有任何想法吗?谢谢!
root
通过为必须与root
一起运行的所有命令加上前缀前缀来限制工作量sudo
。