當前位置:首頁 » 知網查重 » linuxc當前目錄

linuxc當前目錄

發布時間: 2021-03-31 07:13:18

① linux命令:瀏覽當前目錄下的所有以「.c」為後綴名的文件 。。是什麼

Linux中瀏覽當前目錄下所有以".c"為後綴名的文件,可以使用ls命令,直接執行如下命令:

ls*.c

② Linux下用c語言打開文件路徑問題

C語言程序也是啟動一個進程, 所以他也也有環境變數, 默認是繼承父進程的環境變版量;如果是shell界面直接權啟動, 那麼就是繼承shell的環境變數; 如果是其他程序啟動這個那麼就是繼承那個程序的環境變數;
首先沒有搞清楚hello.html是可執行程序, 還是不可執行文件;現在我默認把他當作可執行文件
./表示當前目錄;即執行當前目錄下的hello.html; 如果沒有則報錯
而直接使用程序(hello.html)默認是先在PATH環境變數中查找; 如果PATH環境變數中沒有則報錯;

③ Linux 當前目錄是C:/a/b/c,想用vi命令打開D:x/y/z 下的一個名為f.xml的文

vi /x/y/z/f.xml

④ linux命令:瀏覽當前目錄下的所有以「.c」為後綴名的文件是什麼

Linux中瀏覽當前目錄下所有以".c"為後綴名的文件,可以使用ls命令,直接執行如下命令:

ls*.c

⑤ linux 利用for循環將當前目錄下的.c文件移到指定的目錄下,並按文件大小順序,顯示移動後指定目錄的內容

#!/bin/bash
echo -n "請輸入目標目錄位置:"
read dir

for i in `ls | grep -E "*\.c"`
do
mv $i $dir
done
ls -lS $dir

⑥ linux 強制刪除當前目錄及其子目錄下的所有C程序

rm -rf `find ./ -name *.c` 注意: ` 這個符號是1旁邊那個哈

⑦ linux c 查看當前目錄下是否有指定文件

1. Shell 版本
#獲取當前腳本所在絕對路徑
cur_dir=$(cd "$(dirname "$0")"; pwd)

2. C語言版本
方法一、用realpath函數。這種方法用於開機啟動程序獲取自身目錄會出錯
char current_absolute_path[MAX_SIZE];
//獲取當前目錄絕對路徑
if (NULL == realpath("./", current_absolute_path))
{
printf("***Error***\n");
exit(-1);
}
strcat(current_absolute_path, "/");
printf("current absolute path:%s\n", current_absolute_path);
方法二、用getcwd函數。這種方法用於開機啟動程序獲取自身目錄會出錯
char current_absolute_path[MAX_SIZE];
//獲取當前目錄絕對路徑
if (NULL == getcwd(current_absolute_path, MAX_SIZE))
{
printf("***Error***\n");
exit(-1);
}
printf("current absolute path:%s\n", current_absolute_path);

方法三、用readlink函數。這種方法最可靠,可用於開機啟動程序獲取自身目錄
char current_absolute_path[MAX_SIZE];
//獲取當前程序絕對路徑
int cnt = readlink("/proc/self/exe", current_absolute_path, MAX_SIZE);
if (cnt < 0 || cnt >= MAX_SIZE)
{
printf("***Error***\n");
exit(-1);
}
//獲取當前目錄絕對路徑,即去掉程序名
int i;
for (i = cnt; i >=0; --i)
{
if (current_absolute_path[i] == '/')
{
current_absolute_path[i+1] = '\0';
break;
}
}
printf("current absolute path:%s\n", current_absolute_path);

⑧ 誰能用C給寫個在linux下,遍歷當前目錄下的

UNIX環境高級編程,或者LINUX程序設計里頭都有這個例子。
從《LINUX程序設計第二版》當中找了個print2.c的代碼給你
/* We start with the appropriate headers and then a function, printdir,
which prints out the current directory.
It will recurse for subdirectories, using the depth parameter is used for indentation. */

#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

void printdir(char *dir, int depth)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;

if((dp = opendir(dir)) == NULL) {
fprintf(stderr,"cannot open directory: %s\n", dir);
return;
}
chdir(dir);
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode)) {
/* Found a directory, but ignore . and .. */
if(strcmp(".",entry->d_name) == 0 ||
strcmp("..",entry->d_name) == 0)
continue;
printf("%*s%s/\n",depth,"",entry->d_name);
/* Recurse at a new indent level */
printdir(entry->d_name,depth+4);
}
else printf("%*s%s\n",depth,"",entry->d_name);
}
chdir("..");
closedir(dp);
}

/* Now we move onto the main function. */

int main(int argc, char* argv[])
{
char *topdir, pwd[2]=".";
if (argc != 2)
topdir=pwd;
else
topdir=argv[1];

printf("Directory scan of %s\n",topdir);
printdir(topdir,0);
printf("done.\n");

exit(0);
}

⑨ linux c怎麼獲取進程信息 當前目錄

//獲取當前進程名(進程目錄在函數內已獲取到)
boolGetLocalProgramName(char*processname)
{
charprocessdir[1024]={0};
char*path_end;
size_tlen=1024;

boolret=false;

do
{
if(readlink("/proc/self/exe",processdir,len)<=0)
{
fprintf(stderr,"[ERROR]cannotgetprocessname ");
break;
}

path_end=strrchr(processdir,'/');//進程目錄
if(path_end==NULL)
{
fprintf(stderr,"[ERROR]cannotparseprocessname ");
break;
}

++path_end;
*path_end='';
strcpy(processname,path_end);

ret=true;
}while(0);

returnret;
}

這是我以前的代碼,稍微改造一下就行。

熱點內容
塗鴉論文 發布:2021-03-31 13:04:48 瀏覽:698
手機資料庫應用 發布:2021-03-31 13:04:28 瀏覽:353
版面217 發布:2021-03-31 13:04:18 瀏覽:587
知網不查的資源 發布:2021-03-31 13:03:43 瀏覽:713
基金贖回參考 發布:2021-03-31 13:02:08 瀏覽:489
懸疑故事範文 發布:2021-03-31 13:02:07 瀏覽:87
做簡單的自我介紹範文 發布:2021-03-31 13:01:48 瀏覽:537
戰略地圖參考 發布:2021-03-31 13:01:09 瀏覽:463
收支模板 發布:2021-03-31 13:00:43 瀏覽:17
電氣學術會議 發布:2021-03-31 13:00:32 瀏覽:731