Linux基本指令 2

6.man指令

语法:man [选项] 命令

man -a 命令:将所有的章节都显示出来

[0429@localhost ~]$ man -a printf
//进入man手册,按q退出
--Man-- 下一页: printf(1p) [ 查看 (return) | 跳过 (Ctrl-D) | 退出 (Ctrl-C) ]

man [num] 命令:只在第num章节寻找

[0429@localhost ~]$ man 4 printf
在第 4 节中没有关于 printf 的手册页条目。
[0429@localhost ~]$ man 1 printf
//在第一章节中寻找到printf的帮助
[0429@localhost ~]$ 
[0429@localhost ~]$ man 2 printf
在第 2 节中没有关于 printf 的手册页条目。
[0429@localhost ~]$ 

man -k 命令:根据关键字搜索联机帮助

[0429@localhost ~]$ man -k printf
asprintf (3)         - print to allocated string
dprintf (3)          - print to a file descriptor
fprintf (3)          - formatted output conversion
fprintf (3p)         - print formatted output
fwprintf (3)         - formatted wide-character output conversion
fwprintf (3p)        - print formatted wide-character output
ldns_buffer_printf (3) - (未知的主题)
printf (1)           - format and print data
printf (1p)          - write formatted output
printf (3)           - formatted output conversion
printf (3p)          - print formatted output
snprintf (3)         - formatted output conversion
snprintf (3p)        - print formatted output
sprintf (3)          - formatted output conversion
sprintf (3p)         - print formatted output
swprintf (3)         - formatted wide-character output conversion
swprintf (3p)        - print formatted wide-character output
vasprintf (3)        - print to allocated string
vdprintf (3)         - print to a file descriptor
vfprintf (3)         - formatted output conversion
vfprintf (3p)        - format output of a stdarg argument list
vfwprintf (3)        - formatted wide-character output conversion
vfwprintf (3p)       - wide-character formatted output of a stdarg argument list
vprintf (3)          - formatted output conversion
vprintf (3p)         - format output of a stdarg argument list
vsnprintf (3)        - formatted output conversion
vsnprintf (3p)       - format output of a stdarg argument list
vsprintf (3)         - formatted output conversion
vsprintf (3p)        - format output of a stdarg argument list
vswprintf (3)        - formatted wide-character output conversion
vswprintf (3p)       - wide-character formatted output of a stdarg argument list
vwprintf (3)         - formatted wide-character output conversion
vwprintf (3p)        - wide-character formatted output of a stdarg argument list
wprintf (3)          - formatted wide-character output conversion
wprintf (3p)         - print formatted wide-character output

7.cp指令

语法:cp [选项] 源文件或目录 目标文件或目录

功能:复制文件或目录

cp -f 源文件或目录 目标文件或目录:强行复制文件或目录,不管目标文件或目录是否存在

[0429@localhost class35]$ ll
总用量 4
drwxrwxr-x. 2 0429 0429   6 10月 20 00:12 lesson1
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c
[0429@localhost class35]$ cp -f lesson1 lesson2
cp: 略过目录"lesson1"
[0429@localhost class35]$ ll
总用量 4
drwxrwxr-x. 2 0429 0429   6 10月 20 00:12 lesson1
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c

cp -i 源文件或目录 目标文件或目录:覆盖文件之前先询问用户

[0429@localhost class35]$ cp -i main.c lesson1
[0429@localhost class35]$ ll
总用量 4
drwxrwxr-x. 2 0429 0429  19 10月 20 00:37 lesson1
drwxrwxr-x. 2 0429 0429   6 10月 20 00:36 lesson2
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c
[0429@localhost class35]$ cd lesson1
[0429@localhost lesson1]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 00:37 main.c

注意:

*-r 递归处理,将指定目录下的文件与子目录一并处理。若源文件或目录的形态,不属于目录或符号链接,则一律视为普通文件处理。

*-R或--recursive 递归处理,将指定目录下的文件与子目录一并处理。 

8.mv指令

语法:mv [选项] 源文件或目录 目标文件或目录

功能:可以用来移动文件或将文件改名,用来备份文件或目录

drwxrwxr-x. 2 0429 0429   6 10月 20 00:38 lesson1
drwxrwxr-x. 2 0429 0429   6 10月 20 00:36 lesson2
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c
[0429@localhost class35]$ cp main.c lesson2
//复制一个main.c到lesson2
[0429@localhost class35]$ ll
总用量 4
drwxrwxr-x. 2 0429 0429   6 10月 20 00:38 lesson1
drwxrwxr-x. 2 0429 0429  19 10月 20 00:55 lesson2
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c
[0429@localhost class35]$ cd lesson2
[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 00:55 main.c
[0429@localhost lesson2]$ cd ..
[0429@localhost class35]$ ll
总用量 4
drwxrwxr-x. 2 0429 0429   6 10月 20 00:38 lesson1
drwxrwxr-x. 2 0429 0429  19 10月 20 00:55 lesson2
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c
//移动文件,-i:若目标文件已经存在,会进行询问是否覆盖
[0429@localhost class35]$ mv -i main.c lesson2 
mv:是否覆盖"lesson2/main.c"? y
[0429@localhost class35]$ cd lesson2
[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 00:11 main.c

注意:

-f:如果目标文件已经存在,不会询问而直接覆盖掉

-i:如果目标文件已经存在,就会询问是否覆盖掉

9.cat/tac指令

语法:cat [选项] [文件]

功能:查看目标文件的内容

[0429@localhost class35]$ cd lesson2
[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 01:09 main.c
[0429@localhost lesson2]$ vim main.c
[0429@localhost lesson2]$ cat -b main.c
     1	#include<stdio.h>
     2	#include<string.h>
     3	int main()
     4	{
     5	const char *msg0="haha printf\n";
     6	const char *msg1="haha fwrite\n";
     7	const char *msg0="haha write\n";

     8	printf("%s",msg0);
     9	fwrite(msg1,strlen(msg0),1,stout);
    10	write(1,msg2,strlen(msg2));

    11	fork();

    12	return 0;
    13	}

语法:tac [选项] [文件]

功能:逆向显示

[0429@localhost lesson2]$ tac -b main.c


}
return 0;

fork();

write(1,msg2,strlen(msg2));
fwrite(msg1,strlen(msg0),1,stout);
printf("%s",msg0);

const char *msg0="haha write\n";
const char *msg1="haha fwrite\n";
const char *msg0="haha printf\n";
{
int main()
#include<string.h>#include<stdio.h>[0429@localhost lesson2]$ 

注意:

-b:对非空输出行编号

-n:对输出的所有行编号

-s:不输出多行空行

10.more指令

语法:more [选项] [文件]

功能:类似cat,查看目标文件的内容

drwxrwxr-x. 2 0429 0429  6 10月 20 00:38 lesson1
drwxrwxr-x. 2 0429 0429 19 10月 20 01:22 lesson2
[0429@localhost class35]$ cd lesson2
[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 01:22 main.c
[0429@localhost lesson2]$ more -n main.c
more: 未知选项 -n
用法:more [选项] 文件...

选项:
  -d        显示帮助,而不是响铃
  -f        统计逻辑行数而不是屏幕行数
  -l        抑制换页(form feed)后的暂停
  -p        不滚屏,清屏并显示文本
  -c        不滚屏,显示文本并清理行尾
  -u        抑制下划线
  -s        将多个空行压缩为一行
  -NUM      指定每屏显示的行数为 NUM
  +NUM      从文件第 NUM 行开始显示
  +/STRING  从匹配搜索字符串 STRING 的文件位置开始显示
  -V        输出版本信息并退出
[0429@localhost lesson2]$ more -c main.c
//不滚屏,显示文本并清理行尾
#include<stdio.h>
#include<string.h>
int main()
{
const char *msg0="haha printf\n";
const char *msg1="haha fwrite\n";
const char *msg0="haha write\n";

printf("%s",msg0);
fwrite(msg1,strlen(msg0),1,stout);
write(1,msg2,strlen(msg2));

fork();

return 0;
}
[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 01:22 main.c
[0429@localhost lesson2]$ 

11.less指令

语法:less [参数] 文件

功能:less与more类似,但使用less可以随意浏览文件,而more只能向前移动,而且less在查看之前不会加载整个文件。

[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 01:22 main.c
[0429@localhost lesson2]$ less -i main.c

#include<stdio.h>
#include<string.h>
int main()
{
const char *msg0="haha printf\n";
const char *msg1="haha fwrite\n";
const char *msg0="haha write\n";

printf("%s",msg0);
fwrite(msg1,strlen(msg0),1,stout);
write(1,msg2,strlen(msg2));

fork();

return 0;
}
main.c (END)

//按q退出

12.head/tail指令

功能:用来显示开头或结尾某个数量的文字区块

语法:head [参数] ... [文件]...

           tail[必要参数][选择参数][文件]

[0429@localhost lesson2]$ ll
总用量 4
-rw-rw-r--. 1 0429 0429 256 10月 20 01:22 main.c
[0429@localhost lesson2]$ head -5 main.c
#include<stdio.h>
#include<string.h>
int main()
{
const char *msg0="haha printf\n";

[0429@localhost lesson2]$ tail -f main.c
const char *msg0="haha write\n";

printf("%s",msg0);
fwrite(msg1,strlen(msg0),1,stout);
write(1,msg2,strlen(msg2));

fork();

return 0;
}

注意:tail命令后,ctrl + c  进行退出

发布了46 篇原创文章 · 获赞 16 · 访问量 3048

猜你喜欢

转载自blog.csdn.net/weiluyu1225/article/details/83213683