查看当前目录属于哪一个盘 -mtime -ctime的区别

1、查看当前目录属于哪一个盘
df $(pwd) | grep -E ‘^(/)’
2、-mtime -ctime的区别
-mtime 修改时间
-ctime 创建时间

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用C++的文件操作库来实现类似于“ls -l”的功能。以下是一个示例代码: ```c++ #include <iostream> #include <fstream> #include <dirent.h> #include <sys/stat.h> #include <pwd.h> #include <grp.h> #include <ctime> #include <iomanip> void ls_l(const char* path = ".") { DIR* dir = opendir(path); if (dir == NULL) { std::cerr << "Failed to open directory: " << path << std::endl; return; } struct dirent* entry; while ((entry = readdir(dir)) != NULL) { std::string name = entry->d_name; // Skip "." and ".." directory entries if (name == "." || name == "..") { continue; } // Get file information struct stat st; std::string full_path = std::string(path) + "/" + name; if (stat(full_path.c_str(), &st) != 0) { std::cerr << "Failed to get file information: " << full_path << std::endl; continue; } // Print file information std::cout << ((S_ISDIR(st.st_mode)) ? "d" : "-") // File type << ((st.st_mode & S_IRUSR) ? "r" : "-") // Owner read permission << ((st.st_mode & S_IWUSR) ? "w" : "-") // Owner write permission << ((st.st_mode & S_IXUSR) ? "x" : "-") // Owner execute permission << ((st.st_mode & S_IRGRP) ? "r" : "-") // Group read permission << ((st.st_mode & S_IWGRP) ? "w" : "-") // Group write permission << ((st.st_mode & S_IXGRP) ? "x" : "-") // Group execute permission << ((st.st_mode & S_IROTH) ? "r" : "-") // Other read permission << ((st.st_mode & S_IWOTH) ? "w" : "-") // Other write permission << ((st.st_mode & S_IXOTH) ? "x" : "-") // Other execute permission << std::setw(2) << st.st_nlink << " "; // Number of hard links struct passwd* pw = getpwuid(st.st_uid); if (pw != NULL) { std::cout << std::setw(8) << pw->pw_name << " "; // Owner name } else { std::cout << std::setw(8) << st.st_uid << " "; // Owner UID } struct group* gr = getgrgid(st.st_gid); if (gr != NULL) { std::cout << std::setw(8) << gr->gr_name << " "; // Group name } else { std::cout << std::setw(8) << st.st_gid << " "; // Group GID } std::cout << std::setw(10) << st.st_size << " "; // File size char time_buf[80]; strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", localtime(&st.st_mtime)); std::cout << time_buf << " "; // Last modification time std::cout << name << std::endl; // File name } closedir(dir); } int main(int argc, char* argv[]) { if (argc == 1) { ls_l("."); } else { for (int i = 1; i < argc; i++) { ls_l(argv[i]); } } return 0; } ``` 该程序使用`opendir`和`readdir`函数来遍历目录中的文件和子目录,并使用`stat`函数获取文件信息。然后,程序使用一些C++的IO操作和格式化输出来显示文件信息,类似于“ls -l”的格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涯一涯二涯三

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值