执行命令
#region Linux下执行命令
/// <summary>
/// Linux下执行命令
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public static string RunLinuxCmd(string cmd)
{
var process = new Process
{
StartInfo = new ProcessStartInfo("/bin/bash", "")
};
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardInput.WriteLine(cmd);
process.StandardInput.Close();
var result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Dispose();
return result;
}
#endregion
文件授权
#region Linux文件授权
/// <summary>
/// Linux文件授权
/// </summary>
/// <param name="file">文件路径</param>
/// <param name="chodType">权限类型</param>
public static void chmod(string file, chodType chodType)
{
switch (chodType)
{
case chodType._0777:
const int _0777 =
S_IRUSR | S_IXUSR | S_IWUSR
| S_IRGRP | S_IXGRP | S_IWGRP
| S_IROTH | S_IXOTH | S_IWOTH;
chmod(Path.GetFullPath(file), _0777);
break;
case chodType._0755:
const int _0755 =
S_IRUSR | S_IXUSR | S_IWUSR
| S_IRGRP | S_IXGRP
| S_IROTH | S_IXOTH;
chmod(Path.GetFullPath(file), _0755);
break;
case chodType._0644:
const int _0644 =
S_IRUSR | S_IWUSR
| S_IRGRP
| S_IROTH;
chmod(Path.GetFullPath(file), _0644);
break;
case chodType._0600:
const int _0600 = S_IRUSR | S_IWUSR;
chmod(Path.GetFullPath(file), _0600);
break;
default:
break;
}
}
#endregion
#region Linux文件权限枚举
/// <summary>
/// Linux文件权限枚举
/// </summary>
public enum chodType
{
/// <summary>
/// 777
/// </summary>
_0777,
/// <summary>
/// 755
/// </summary>
_0755,
/// <summary>
/// 644
/// </summary>
_0644,
/// <summary>
/// 600
/// </summary>
_0600
}
#endregion
```
评论区