linux ls -al 各项说明

本文详细解析了Linux系统中ls-al命令的使用方法及输出信息的含义,包括文件类型、权限、所有者等关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在linux下,为了查看文件,经常使用的命令是ls -al,如下所示:
gwwu@hz-dev2.wgw.com:/usr/sbin>ls -al
total 33788
dr-xr-xr-x.  2 root root       12288 Nov  2  2012 .
drwxr-xr-x. 13 root root        4096 Oct 20  2012 ..
-rwxr-xr-x   1 root root       28360 Jun 23  2012 abrtd
lrwxrwxrwx.  1 root root          10 Oct 20  2012 accept -> cupsaccept

lrwxrwxrwx.  1 root root          17 Oct 20  2012 accton -> ../../sbin/accton

文件类型
与权限
链接占用的
节点(i-node)

文件所有者文件所有者
的用户组
文件大小文件的创建时间
/最近修改时间
文件名称
dr-xr-xr-x.
2rootroot12288Nov  2  2012
.
drwxr-xr-x.
13rootroot
4096
Oct 20  2012
..
-rwxr-xr-x
1root
root
28360 
Jun 23  2012
abrtd
lrwxrwxrwx.
1root
root
10
Oct 20
accept -> cupsaccept
lrwxrwxrwx.
1root
root
17Oct 20
../../sbin/accton

仔细的读者可能发现了,第一项中最后有些有一个'.'号,这个表示的意思是有这个符号的项单独用ls无法显示,必须使用ls -al才显示。

其中第一项表示文件类型和权限,一共10位
9 8 7 6 5 4 3 2 1 0
-  r w x r - x  r -  x 
(1)其中第9为表示文件类型,有以下几种:
-: 表示普通文件
d: 目录
b: 块特殊文件
c: 字符特殊文件
l:  符号链接文件
p: 命名管道文件FIFO
s: 套接字文件
(2)8-6位表示所有者权限,5-3位表示同组其它用户权限,2-0:其它用户权限
r:表示可读; w:表示可写;x:表示可执行;
/**********************************************************************/ /* Execute a CGI script. Will need to set environment variables as * appropriate. * Parameters: client socket descriptor * path to the CGI script */ /**********************************************************************/ void execute_cgi(int client, const char *path, const char *method, const char *query_string) { char buf[1024]; int cgi_output[2]; int cgi_input[2]; //在头文件#include <bits/types.h> //pid_t等同于int pid_t pid; int status; int i; char c; int numchars = 1; int content_length = -1; buf[0] = 'A'; buf[1] = '\0'; if (strcasecmp(method, "GET") == 0) while ((numchars > 0) && strcmp("\n", buf)) /* read & discard headers */ numchars = get_line(client, buf, sizeof(buf)); else if (strcasecmp(method, "POST") == 0) /*POST*/ { numchars = get_line(client, buf, sizeof(buf)); while ((numchars > 0) && strcmp("\n", buf)) { buf[15] = '\0'; if (strcasecmp(buf, "Content-Length:") == 0) /*atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数, 应用在计算机程序和办公软件中。int atoi(const char *nptr) 函数会扫描参数 nptr字符串,会跳过前面的空白字符 (例如空格,tab缩进)等。 如果 nptr不能转换成 int 或者 nptr为空字符串,那么将返回 0 */ content_length = atoi(&(buf[16])); numchars = get_line(client, buf, sizeof(buf)); } if (content_length == -1) { bad_request(client); return; } } else/*HEAD or other*/ { } //pipe所需头文件 #include<unistd.h> //pipe函数定义中的fd参数是一个大小为2的一个数组类型的指针。 //该函数成功时返回0,并将一对打开的文件描述符值填入fd参数指向的数组。 //失败时返回 -1并设置errno。 if (pipe(cgi_output) < 0) { cannot_execute(client); return; } if (pipe(cgi_input) < 0) { cannot_execute(client); return; } if ( (pid = fork()) < 0 ) { cannot_execute(client); return; } sprintf(buf, "HTTP/1.0 200 OK\r\n"); send(client, buf, strlen(buf), 0); if (pid == 0) /* child: CGI script */ { char meth_env[255]; char query_env[255]; char length_env[255]; /*#include <unistd.h> int dup(int oldfd); dup用来复制参数oldfd所指的文件描述符。 当复制成功是,返回最小的尚未被使用过的文件描述符, 若有错误则返回-1.错误代码存入errno中返回的新文件描述符和参数oldfd指向同一个文件, 这两个描述符共享同一个数据结构, 共享所有的锁定,读写指针和各项全现或标志位。 假如oldfd的值为1,当前文件描述符的最小值为3,那么新描述符3指向描述符1所拥有的文件表项。*/ //从shell中运行一个进程,默认会有3个文件描述符存在(0、1、2), 0与进程的标准输入相关联,1与进程的标准输出相关联,2与进程的标准错误输出相关联, /*dup2定义是int dup2( int filedes, int filedes2 ) 也是返回一个文件描述符,但是呢这个文件描述符你可以指定, 也就是它的第二个参数filedes2, 如果fiedes2文件描述符指定的文件已经被打开, 那么就先把filedes2指定的文件关闭, 同样还是返回文件描述符这个文件描述符可以用来打开filedes1指定的文件*/ dup2(cgi_output[1], STDOUT); dup2(cgi_input[0], STDIN); //#include <unistd.h> int close(int fd); 返回值:成功返回0,出错返回-1并设置errno //参数fd是要关闭的文件描述符。 close(cgi_output[0]); close(cgi_input[1]); sprintf(meth_env, "REQUEST_METHOD=%s", method); //putenv 就是把meth_env添加到环境变量里,且这个环境变量只在这个子进程里有用 putenv(meth_env); if (strcasecmp(method, "GET") == 0) { sprintf(query_env, "QUERY_STRING=%s", query_string); putenv(query_env); } else { /* POST */ sprintf(length_env, "CONTENT_LENGTH=%d", content_length); putenv(length_env); } //Linux下头文件 #include <unistd.h> 函数定义 int execl(const char *path, const char *arg, ...); /*第一参数path字符指针所指向要执行的文件路径, 接下来的参数代表执行该文件时传递的参数列表:argv[0],argv[1]... 最后一个参数须用空指针NULL作结束。*/ // 例如执行/bin目录下的ls, 第一参数为程序名ls, 第二个参数为"-al", 第三个参数为"/etc/" //execl("/bin/ls","ls","-al","/etc/",NULL); // 执行: ./execl 结果:-rw-r--r-- 1 root root 2218 Jan 13 11:36 /etc/passwd execl(path, NULL); exit(0); } else { /* parent */ close(cgi_output[1]); close(cgi_input[0]); if (strcasecmp(method, "POST") == 0) for (i = 0; i < content_length; i++) { recv(client, &c, 1, 0); write(cgi_input[1], &c, 1); } while (read(cgi_output[0], &c, 1) > 0) send(client, &c, 1, 0); close(cgi_output[0]); close(cgi_input[1]); waitpid(pid, &status, 0); } }
最新发布
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值