- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试从 cmd 行读取路径,然后运行“ls”cmd 以仅打印指定路径中的隐藏文件及其长信息,然后打印到文本文件。我的问题是“ls”返回:
ls: 非法选项 --
ls: 非法选项 -- .
ls: 非法选项 -- ?
ls: 非法选项 -- *
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define NUMARG 2
/* start main */
int main(int argc, char *argv[]){
/* define data */
DIR *dirptr;
struct dirent *dp;
int pid;
int fd = open("output_file", O_WRONLY|O_CREAT, 0666);
/* Command Line Check */
if(argc != NUMARG){
fprintf(stderr, "usage: %s dirname\n", argv[0]);
exit(1);
}
/* Open the specified directory */
if((dirptr = opendir(argv[1])) == NULL){
fprintf(stderr, "Could not open directory %s\n", argv[1]);
exit(1);
}
/* fork another process */
switch(pid = fork()){
/* succesfull child process */
case 0:
dup2(fd, 1);
close(fd);
printf("Running ls\n");
execlp( "ls", "ls" , "-ld .?*", argv[1], (char*)NULL);
perror("execlp");
exit(1);
default:
sleep(5);
printf("Hitting default...\n");
break;
case -1:
perror("err");
exit(1);
}
}
最佳答案
通过 shell 运行 ls
execlp("/bin/sh", "/bin/sh", "-c", "ls -l .?*", (char *) NULL);
这样您就可以访问 shell 通配符。
关于c - 如何使用 'ls' cmd 仅打印目录中的隐藏文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36956510/
如果我执行 ls -la,我会得到如下结果 total 16 drwxr-xr-x 4 rockse staff 136 Apr 28 16:55 . drwx------+ 23 rocks
我找到了一些Linux文件,当我键入ls -lah时,它将输出以下权限格式: ... drwxr-xr-x. 2 root root ... -rw-rw-r--. 1 root r
我正在尝试从 python 执行 ls -l 来检查文件的最后修改日期。 os.listdir 不显示长列表格式。subprocess.call 显示格式,但实际上打印它,并返回 0。我希望能够将其放
以下 shell 函数定义卡在 Cygwin 的 bash 控制台 (RHEL/Ubuntu) 中,当它被调用时它只是退出终端。 $ function ls { ls; } $ ls 为什么会出现这种
为什么这两个命令的输出不同: ls | cat ls 第一个似乎用换行符分隔文件名。 这也适用于命令 suc 有 ls > outfile 和类似的东西。 我使用的是 Mac OSX,如果这有什么不同
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我使用 eshell-parse-command 'ls -l' 得到了这个: (progn (eshell-trap-errors (eshell-named-command "l
如何使用 RegExp 在 JavaScript 中实现类似于 alias 的功能? ALIAS = [{pattern: /^ls[$ ]/, replace: 'ls --color '}] s
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在编写一个 shell 程序,当将值传递给 execv() 时,我需要一个指向程序名称的 char 指针(即 ls),我需要一个指向参数的 char 指针数组的指针。 我会检查并解析用户的输入,如
我对使用 bash 编写脚本还比较陌生,并编写了以下脚本: # Set variables logfile=/tmp/peter/logfile.log indir=/mls/indir/IG/ te
所以基本上我有一个任务要使用 strace 进行分析,ls 命令需要哪些系统调用才能提供与 ls -l 相同的信息。 但是对于 ls -l 命令有许多奇怪的系统调用,例如 stat 64 被调用时使用
我在 ubuntu 的文件夹中有一个文件夹列表。IE。/mnt/source/customcode/files/brands/下 root@a919794ec280:/mnt/source/custo
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
#include #include #include #include #include int flag; void catch (int sig) { if (sig == SIGI
我使用 Process 来调用 shell(zsh),我想 cd ~ 或其他一些目录,例如在 shell 中定义的 cd $PROJ_ROOT。但似乎无法处理这些 token 。如何解决这个问题? s
我在我的 Centos5 机器上运行了这个: ls -al & ; ls -al 我期待它在后台运行 ls -al,同时在前台运行 ls -al,并演示终端的输出是如何被破坏的通过这样做。 但是,我得
当我在 PowerShell 中使用 Get-ChildItem 时,我会得到目录中以行格式设置的项目列表。该列表经常会超出屏幕,如果我想查看列表的其余部分或以前的命令和输出,则迫使我向上滚动。我想为
我试图用所有必要的参数绕过调用 JNIEnv->DefineClass 方法,但当我尝试从 java 调用该方法时,它总是返回 java.lang.NoClassDefFoundError: ls.H
我是一名优秀的程序员,十分优秀!