found 如何解决 Linux 中的 string was not found 问题? (linux string was not)

How to Solve “String was not Found” Problem in Linux?

When working with Linux, it is common to encounter errors and issues that can hinder your productivity. One such problem is the “string was not found” error, which can occur when executing commands or searching for files. This error message indicates that the system cannot find the specified string or file, causing frustration and confusion for users.

So, how can you solve the “string was not found” problem in Linux? In this article, we will discuss some of the common causes and solutions for this error.

Cause 1: Typing Error

One of the most common causes of the “string was not found” error is a typing mistake. Linux is case-sensitive, meaning that even a all typo in a command or file name can cause an error. Therefore, it is important to check the spelling and capitalization of your commands and file names before running them.

Solution: Verify the Spelling and Capitalization

To avoid typos, you can use the auto-complete feature by pressing the Tab key after typing the first few characters of a command or file name. This will automatically complete the rest of the word, saving you time and reducing the likelihood of making spelling errors.

Cause 2: Missing Packages

Another reason for the “string was not found” error is missing or incomplete packages that are required to execute the command. Linux applications often depend on other packages to function correctly, and if any of these packages are missing, the command or file will not be found.

Solution: Install the Required Packages

To resolve this issue, you need to identify the missing packages and install them. You can do this by using the package manager of your Linux distribution. For example, if you are using Ubuntu, you can use the following command to search for packages:

$ sudo apt search package-name

Once you have identified the required package, you can install it using the following command:

$ sudo apt install package-name

Cause 3: Path Not Set or Incorrect

The “string was not found” error can also occur when the system cannot locate the file or command because the path is not set or incorrect. Linux mntns a list of directories called the PATH, which contns the locations where the system searches for executable files. If the file or command you are looking for is not located in any of these directories, you will get the “string was not found” error.

Solution: Check and Set the PATH Variable

To check the PATH environment variable, you can use the following command:

$ echo $PATH

This will display a list of directories separated by a colon, and you can check if the directory contning the file or command you are trying to access is included. If it is not, you can add the directory to the PATH variable by editing the .bashrc or .profile file in your home directory.

For example, if you want to add the directory /usr/local/bin to the PATH variable, you can add this line to your .bashrc or .profile file:

export PATH=$PATH:/usr/local/bin

After saving the file and reopening the terminal, the new PATH variable will be loaded, and you can try running the command or file agn.

Conclusion

The “string was not found” error can be frustrating, but it is usually caused by a simple mistake that can be easily fixed. By checking the spelling and capitalization of your commands and file names, installing missing packages, and setting the PATH variable correctly, you can avoid this error and work more efficiently in your Linux environment.

相关问题拓展阅读:

  • c语言string的用法大全
  • linux配置源代码包时出现下面错误

c语言string的用法大全

C语言是一门面向过程的、抽象化的通用程或孝陪序设计语言,广泛应用于底层开发。C语言能以简易的方式编译、处慎坦理低级存储器。C 语言string的用法有哪些呢,请看看下面我为你整理 总结 的c语言string的用法大全_C语言中string使用 方法 。

c语言string的用法

函数原型:char *strdup(const char *s)

函数功能:字符串拷贝,目的空间由该函数分配

函数返回:指向拷贝后的字符串指针

参数说明:src-待拷贝的源字符串

所属文件:

view plain

#include

#include

#include

intmain()

{

char*dup_str,*string=”abcde”;

dup_str=strdup(string);

printf(“%s”,dup_str);

free(dup_str);

return0;

}

@函数名称:strcpy

函数原型:char* strcpy(char* str1,char* str2);

函数功能:把str2指向的字符串拷贝到str1中去

函数返回:返回str1,即指向str1的指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charstring;

char*str1=”abcdefghi”;

strcpy(string,str1);

printf(“thestringis:%s\n”,string);

return0;

}

@函数名称:strncpy

函数原型:char *strncpy(char *dest, const char *src,intcount)

函数功能:将字符串src中的count个字符拷贝到字符串dest中去

函数返回:指向dest的指针

参数说明:dest-目的字符串,src-源字符串,count-拷贝的字符个数

所属文件:

view plain

#include

#include

intmain()

{

char*src=”bbbbbbbbbbbbbbbbbbbb”;//20’b’s

chardest=”aaaaaaaaaaaaaaaaaaaa”;//20’a’s

puts(dest);

strncpy(dest,src,10);

puts(dest);

return0;

}

输出:

view plain

/*******************************************

aaaaaaaaaaaaaaaaaaaa

bbbbbbbbbbaaaaaaaaaa

*******************************************/

注意:strncpy只复制指定长度的字符,不会自动在末尾加’\0’。若指定长度超过源字符串长度,不够的部分补‘\0’,

@函数名称:strcat

函数原型:char* strcat(char * str1,char * str2);

函数功能:把字符串str2接到衫蠢str1后面,str1最后的’\0’被取消

函数返回:str1

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charbuffer;

strcpy(buffer,”Hello”);

strcat(buffer,”world”);

printf(“%s\n”,buffer);

return0;

}

@函数名称:strncat

函数原型:char *strncat(char *dest, const char *src, size_t maxlen)

函数功能:将字符串src中前maxlen个字符连接到dest中

函数返回:

参数说明:

所属文件:

view plain

#include

#include

charbuffer;

intmain()

{

strcpy(buffer,”Hello”);

strncat(buffer,”world”,8);

printf(“%s\n”,buffer);

strncat(buffer,”*************”,4);

printf(“%s\n”,buffer);

return0;

}

注意:与strncpy不同的是,strncat会自动在末尾加‘\0’,若指定长度超过源字符串长度,则只复制源字符串长度即停止

@函数名称:strcmp

函数原型:int strcmp(char * str1,char * str2);

函数功能:比较两个字符串str1,str2.

函数返回:str1str2,返回正数.

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

char*buf1=”aaa”,*buf2=”bbb”,*buf3=”ccc”;

intptr;

ptr=strcmp(buf2,buf1);

if(ptr>0)

printf(“buffer2isgreaterthanbuffer1\n”);

else

printf(“buffer2islessthanbuffer1\n”);

ptr=strcmp(buf2,buf3);

if(ptr>0)

printf(“buffer2isgreaterthanbuffer3\n”);

else

printf(“buffer2islessthanbuffer3\n”);

return0;

}

@函数名称:strncmp

函数原型:int strncmp(char *str1,char *str2,int count)

函数功能:对str1和str2中的前count个字符按字典顺序比较

函数返回:小于0:str1str2

参数说明:str1,str2-待比较的字符串,count-比较的长度

所属文件:

view plain

#include

#include

intmain()

{

charstr1=”aabbc”;//

charstr2=”abbcd”;//

//为使测试程序更简练,此处假定了strncmp只返回-1,0,1三个数

charres_info={”};

intres;

//前1个字符比较

res=strncmp(str1,str2,1);

printf(“1:str1%cstr2\n”,res_info);

//前3个字符比较

res=strncmp(str1,str2,3);

printf(“3:str1%cstr2\n”,res_info);

}

输出:

view plain

/****************************************

1:str1=str2

3:str1

view plain

#include

#include

intmain()

{

char*p=”Findallvowels”;

p=strpbrk(p+1,”aeiouAEIOU”);

while(p)

{

printf(“%s\n”,p);

p=strpbrk(p+1,”aeiouAEIOU”);

}

return0;

}

输出:

view plain

/**************************************

indallvowels

allvowels

owels

els

**************************************/

@函数名称:strcspn

函数原型:int strcspn(const char *s1, const char *s2)

函数功能:统计s1中从头开始直到之一个“来自s2中的字符”出现的长度

函数返回:长度

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

printf(“%d\n”,strcspn(“abcbcadef”,”cba”));

printf(“%d\n”,strcspn(“xxxbcadef”,”cba”));

printf(“%d\n”,strcspn(“”,”cba”));

return0;

}

输出:

view plain

/************************

0

3

9

************************/

@函数名称:strspn

函数原型:int strspn(const char *s1, const char *s2)

函数功能:统计s1中从头开始直到之一个“不来自s2中的字符”出现的长度

函数返回:位置指针

参数说明:

所属文件:

view plain

#include

#include

#include

intmain()

{

printf(“%d\n”,strspn(“abcbcadef”,”cba”));

printf(“%d\n”,strspn(“xxxbcadef”,”cba”));

printf(“%d\n”,strspn(“”,”cba”));

return0;

}

输出:

view plain

/************************

6

0

0

************************/

@函数名称:strchr

函数原型:char* strchr(char* str,char ch);

函数功能:找出str指向的字符串中之一次出现字符ch的位置

函数返回:返回指向该位置的指针,如找不到,则返回空指针

参数说明:str-待搜索的字符串,ch-查找的字符

所属文件:

view plain

#include

#include

intmain()

{

char*str=”Thisisastring!”;

charch;

char*p;

while(1)

{

printf(“Pleaseinputachar:”);

ch=getchar();

p=strchr(str,ch);

if(p)

printf(“%cisthe%dcharacterof\”%s\”\n”,ch,(int)(p-str+1),str);

else

printf(“Notfound!\n”);

printf(“PressESCtoquit!\n\n”);

if(27==getch())

break;

fflush(stdin);

}

return0;

}

运行结果:

view plain

/********************************************

Pleaseinputachar:i

iisthe3characterof”Thisisastring!”

PressESCtoquit!

Pleaseinputachar:l

Notfound!

PressESCtoquit!

Pleaseinputachar:s

sisthe4characterof”Thisisastring!”

PressESCtoquit!

**********************************************/

@函数名称:strrchr

函数原型:char *strrchr(const char *s, int c)

函数功能:得到字符串s中最后一个含有c字符的位置指针

函数返回:位置指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charstring;

char*ptr,c=’r’;

strcpy(string,”Thisisastring”);

ptr=strrchr(string,c);

if(ptr)

printf(“Thecharacter%cisatposition:%d”,c,ptr-string);

else

printf(“Thecharacterwasnotfound”);

return0;

}

@函数名称:strstr

函数原型:char* strstr(char* str1,char* str2);

函数功能:找出str2字符串在str1字符串中之一次出现的位置(不包括str2的串结束符)

函数返回:返回该位置的指针,如找不到,返回空指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

char*str1=”OpenWatcomC/C++”,*str2=”Watcom”,*ptr;

ptr=strstr(str1,str2);

printf(“Thesubstringis:%s\n”,ptr);

return0;

}

输出:

The substringis:Watcom C/C++

@函数名称:strrev

函数原型:char *strrev(char *s)

函数功能:将字符串中的所有字符颠倒次序排列

函数返回:指向s的指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charforward=”string”;//原文中定义为char*是不对的,指向代码段的指针内容是不可变的

printf(“Beforestrrev():%s”,forward);

strrev(forward);

printf(“Afterstrrev():%s”,forward);

return0;

}

输出:

view plain

/************************************

Beforestrrev():string

Afterstrrev():gnirts

************************************/

@函数名称:strnset

函数原型:char *strnset(char *s, int ch, size_t n)

函数功能:将字符串s中前n个字符设置为ch的值

函数返回:指向s的指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charstring=”aaaaaaaaaaaaaaaaaaaaaaa”;

charletter=’x’;

printf(“stringbeforestrnset:%s\n”,string);

strnset(string,letter,10);

printf(“stringafterstrnset:%s\n”,string);

return0;

}

输出:

view plain

/*************************************************

stringbeforestrnset:aaaaaaaaaaaaaaaaaaaaaaa

stringafterstrnset:xxxxxxxxxxaaaaaaaaaaaaa

*************************************************/

@函数名称:strset

函数原型:char *strset(char *s, int ch)

函数功能:将字符串s中所有字符设置为ch的值

函数返回:指向s的指针

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charstring=””;

charsymbol=’c’;

printf(“Beforestrset():%s”,string);

strset(string,symbol);

printf(“Afterstrset():%s”,string);

return0;

}

@函数名称:strtok

函数原型:char *strtok(char *s1, const char *s2)

函数功能:分解s1字符串为用特定分隔符分隔的多个字符串(一般用于将英文句分解为单词)

函数返回:字符串s1中首次出现s2中的字符前的子字符串指针

参数说明:s2一般设置为s1中的分隔字符

规定进行子调用时(即分割s1的第二、三及后续子串)之一参数必须是NULL

在每一次匹配成功后,将s1中分割出的子串位置替换为NULL(摘下链中之一个环),因此s1被破坏了

函数会记忆指针位置以供下一次调用

所属文件:

view plain

#include

#include

intmain()

{

char*p;

char*buffer;

char*delims={“.,”};

buffer=strdup(“Findwords,allofthem.”);

printf(“%s\n”,buffer);

p=strtok(buffer,delims);

while(p!=NULL){

printf(“word:%s\n”,p);

p=strtok(NULL,delims);

}

printf(“%s\n”,buffer);

return0;

}//根据测试,可以随时给strtok的之一个参数输入一个新的字符串,开始新字符串的分隔

PS:根据测试,可以随时给strtok的之一个参数输入一个新的字符串,开始新字符串的分隔

@函数名称:strupr

函数原型:char *strupr(char *s)

函数功能:将字符串s中的字符变为大写

函数返回:

参数说明:

所属文件:

view plain

#include

#include

intmain()

{

charstring=”abcdefghijklmnopqrstuvwxyz”,*ptr;//会影响原字符串的内存,用char来声明

ptr=strupr(string);

printf(“%s”,ptr);

return0;

}

@函数名称:strlwr

函数原型:char *strlwr(char *s)

函数功能:将字符串中的字符变为小写字符

函数返回:指向s的指针

参数说明:

所属文件:

view plain

#include

intmain()

{

charstr=”HOWTOSAY”;

printf(“%s”,strlwr(str));

return0;

}

@函数名称:strerror

函数原型:char *strerror(int errnum)

函数功能:得到错误信息的内容信息

函数返回:错误提示信息字符串指针

参数说明:errnum-错误编号

所属文件:

view plain

#include

#include

intmain()

{

char*buffer;

buffer=strerror(errno);

printf(“Error:%s”,buffer);

return0;

}

@函数名称:memcpy

函数原型:void *memcpy(void *dest, const void *src, size_t n)

函数功能:字符串拷贝

函数返回:指向dest的指针

参数说明:src-源字符串,n-拷贝的更大长度

所属文件:,

view plain

#include

#include

intmain()

{

charsrc=”******************************”;

chardest=”abcdefghijlkmnopqrstuvwxyz”;

char*ptr;

printf(“destinationbeforememcpy:%s\n”,dest);

ptr=memcpy(dest,src,strlen(src));

if(ptr)

printf(“destinationaftermemcpy:%s\n”,dest);

else

printf(“memcpyfailed”);

return0;

}

输出:

view plain

/*************************************************************

destinationbeforememcpy:abcdefghijlkmnopqrstuvwxyz

destinationaftermemcpy:******************************456709

**************************************************************/

@函数名称:memccpy

函数原型:void *memccpy(void *dest, const void *src, int c, size_t n)

函数功能:字符串拷贝,到指定长度或遇到指定字符时停止拷贝

函数返回:

参数说明:src-源字符串指针,c-中止拷贝检查字符,n-长度,dest-拷贝底目的字符串指针

所属文件:,

view plain

#include

#include

intmain()

{

char*src=”Thisisthesourcestring”;

chardest;

char*ptr;

ptr=memccpy(dest,src,’c’,strlen(src));

if(ptr)

{

*ptr=’\0′;

printf(“Thecharacterwasfound:%s”,dest);

}

else

printf(“Thecharacterwasn’tfound”);

return0;

}

输出:

view plain

/*****************************************

Thecharacterwasfound:Thisisthesourc

*****************************************/

PS:指定字符被复制到dest中,memccpy返回了dest中指定字符的下一处的地址,返回NULL表示未遇到指定字符

@函数名称:memchr

函数原型:void *memchr(const void *s, int c, size_t n)

函数功能:在字符串中第开始n个字符中寻找某个字符c的位置

函数返回:返回c的位置指针,返回NULL时表示未找到

参数说明:s-要搜索的字符串,c-要寻找的字符,n-指定长度

所属文件:,

view plain

#include

#include

intmain()

{

charstr;

char*ptr;

strcpy(str,”Thisisastring”);

ptr=memchr(str,’r’,strlen(str));

if(ptr)

printf(“Thecharacter’r’isatposition:%d”,ptr-str);

else

printf(“Thecharacterwasnotfound”);

return0;

}

@函数名称:memcmp

函数原型:int memcmp(const void *s1, const void *s2,size_t n)

函数功能:按字典顺序比较两个串s1和s2的前n个字节

函数返回:0分别表示s1s2

参数说明:s1,s2-要比较的字符串,n-比较的长度

所属文件:,

view plain

#include

#include

intmain()

{

char*buf1=”ABCDE123″;

char*buf2=”abcde456″;

intstat;

stat=memcmp(buf1,buf2,5);

printf(“Thestringstoposition5are”);

if(stat)printf(“not”);

printf(“thesame\n”);

return0;

}

@函数名称:memicmp

函数原型:int memicmp(const void *s1, const void *s2, size_t n)

函数功能:按字典顺序、不考虑字母大小写对字符串s1,s2前n个字符比较

函数返回:0分别表示s1s2

参数说明:s1,s2-要比较的字符串,n-比较的长度

所属文件:,

view plain

#include

#include

intmain()

{

char*buf1=”ABCDE123″;

char*buf2=”abcde456″;

intstat;

stat=memicmp(buf1,buf2,5);

printf(“Thestringstoposition5are”);

if(stat)printf(“not”);

printf(“thesame”);

return0;

}

输出:

view plain

/**************************************

Thestringstoposition5arethesame

***************************************/

@函数名称:memmove

函数原型:void *memmove(void *dest, const void *src, size_t n)

函数功能:字符串拷贝

函数返回:指向dest的指针

参数说明:src-源字符串,n-拷贝的更大长度

所属文件:,

view plain

#include

#include

intmain()

{

chardest=”abcdefghijklmnopqrstuvwxyz”;

printf(“destinationpriortomemmove:%s\n”,dest);

memmove(dest+1,dest,35);

printf(“destinationaftermemmove:%s”,dest);

return0;

}

PS:与memcpy不同的是,memmove可以处理目的字符串与源字符串地址空间出现重叠的情况,可保证待复制的内容不被破坏。

@函数名称: memset

函数原型: void *memset(void *s, int c, size_t n)

函数功能: 字符串中的n个字节内容设置为c

函数返回:

参数说明: s-要设置的字符串,c-设置的内容,n-长度

所属文件: ,

view plain

#include

#include

#include

intmain()

{

charbuffer=”Helloworld”;

printf(“Bufferbeforememset:%s/n”,buffer);

memset(buffer,’*’,strlen(buffer)-1);

printf(“Bufferaftermemset:%s”,buffer);

return0;

}

c语言string的用法大全相关 文章 :

c语言string的用法

c语言的用法

Linux C语言字符与字符串处理

c语言中strcmp的用法

c语言大括号的用法

c语言位运算符的用法

c语言char的用法

c语言中sort的用法详解

c语言中int的用法

linux配置源代码包时出现下面错误

“exact error that occured. This usually means GLIB is incorrectly installed”

是不是由于GLIB的版本太低了?查看判御轿你的拆漏软件的readme啊,确认你的系统是否满足所有依赖关掘肆系。

./configure –prefix=/usr/local/ 要像这样的格式。。。

www.bjbfbx.com

”的污水神好敏流量计with-zlib –with-curl –enable-bcmath –with-jpeg-dir –with-png-dir –with-xpm-dir –with-天然气流量计

这是什么意思,请指点./configure –prefix=/usr/local/php/ –with-apxs2=/usr/local/bin/apxs –with-config-file-path=/usr/local/php/lib/游枝 –with-config-file-scan-dir=/usr/local/etc/ –with-zlib –with-curl –enable-bcmath –with-jpeg-dir –with-png-dir –with-xpm-dir –with-freetype-dir –with-gd –with-mhash –enable-mbstring –with-mcrypt –with-libxml-dir –with-iconv-dir –with-pcre-dir –enable-mysqlnd –with-mysql=

关于linux string was not的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

香港服务器首选树叶云,2H2G首月10元开通。
树叶云(shuyeidc.com)提供简单好用,价格厚道的香港/美国云服务器和独立服务器。IDC+ISP+ICP资质。ARIN和APNIC会员。成熟技术团队15年行业经验。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/185524.html<

(0)
管理的头像管理
上一篇2025-03-29 09:30
下一篇 2025-03-29 09:31

相关推荐

  • 云服务器和云虚拟主机怎么选?云服务器和虚拟主机区别

    云服务器适合业务增长快、需弹性扩展的场景,而云虚拟主机适合预算有限、技术门槛低的小型静态网站或测试环境,二者核心区别在于资源独享性与运维复杂度,核心差异解析:从底层架构到使用体验很多人容易混淆这两者,觉得它们都是“买空间建站”,它们的底层逻辑完全不同,云服务器(ECS)就像是你租了一整栋别墅,水电网络独立,你想……

    2026-06-29
    0
  • 赣州智慧旅游招聘是真的吗?赣州旅游人才招聘信息

    中级岗位(3-5年经验)月薪范围通常在6000-10000元,这类岗位需要独立负责项目模块,如独立运营一个抖音账号,或维护一个景区小程序的功能迭代,具备成功案例的候选人议价能力较强,高级岗位(5年以上经验)月薪范围通常在10000-20000元,部分核心管理岗可达更高,这类人才需要具备战略规划能力,如制定整个景……

    2026-06-29
    0
  • 赣州智能物联网车位锁如何管理?智能车位锁管理系统多少钱

    赣州智能物联网车位锁管理的核心在于通过云端平台实现远程控锁、状态实时监控及自动计费,彻底解决传统车位“被占难管”与“找位难”的痛点,在赣州这样的城市,随着机动车保有量的持续增长,老旧小区、商业综合体以及私人固定车位的资源矛盾日益凸显,传统的机械地锁或简易遥控锁,不仅操作繁琐,更无法实现数据化管理,引入智能物联网……

    2026-06-29
    0
  • 赣州智能消防栓好用吗,智能消防栓多少钱一个

    赣州智能消防栓通过物联网技术实现实时监测与远程报警,能显著降低火灾响应时间并提升城市消防安全管理水平,是目前智慧城市建设中不可或缺的基础设施,赣州智能消防栓的核心价值与应用场景传统消防栓往往存在“看不见、摸不着、用不了”的痛点,在赣州这样地形复杂、老城区与新城区并存的区域,传统设施的管理难度极大,智能消防栓的出……

    2026-06-29
    0
  • 云服务器和物理机到底有啥区别?

    云服务器本质上是虚拟化资源池中的弹性实例,而传统物理服务器是独占的硬件实体,前者胜在弹性与运维便捷,后者强在物理隔离与性能稳定,具体选择取决于业务对成本、扩展性及安全合规的权衡,很多人初次接触服务器时,容易把“云服务器”和“传统物理服务器”混为一谈,觉得它们都是用来跑网站或存数据的盒子,这两者的底层逻辑完全不同……

    2026-06-29
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注