当前位置:网站首页>02 specific implementation of LS command
02 specific implementation of LS command
2022-07-04 04:08:00 【Blue wind 9】
Preface
// ha-ha Yesterday's was a little perfunctory , I can't say it's not a detail ?
ha-ha This command Should be linux Users Basically, I will use it ?
ha-ha Here we are mainly to glance at How does this command work
main Mainly parameter processing , Cycle through the paths Output the information of each path
print_dir It is mainly to traverse each under the current path Sub file ( clip ), The specific business is entrusted to gobble_file, Collect each Sub file ( clip ) Information about
gobble_file Mainly used lstat/stat Command to get each file ( clip ) Related metadata of
print_current_files Mainly output each Sub file ( clip ) Information about , Here, this involves the specific output format , We are here to ls -l For example
print_long_format The output of is common ll Processing of output , Output fmode, nlink, user, group, size, mtime, fileName
be based on linux-4.4.0 + coreutils-8.25
Debugging is command based "ls -l /"
main
What you can see is ls There is only one path behind "/"
Here is the call print_dir To output "/" Each of the following Sub file ( clip ) Information about

print_dir
be based on opendir, readdir And so on api Traverse "/" Each of the following Sub file ( clip )
call gobble_file To get each Sub file ( clip ) Related metadata of

gobble_file
adopt stat/lstat relevant api To get the current file ( clip ) Metadata information of

print_current_files
according to Output format Make different outputs , Here we are print_long_format

print_long_format
The function content is long , It's not finished here
Use buf towards stdout Output fmode, nlink
user, group Additional system calls are required to obtain uid, gid The corresponding name , Use it directly stdout Output
Use buf towards stdout Output size, mtime, fileName


ha-ha These built-in commands Is it not so mysterious ?
Of course Here is only the core context of analysis , Real implementation details There are also many designs
End
边栏推荐
- 投资深度思考
- 微信公众号网页授权
- Value transfer communication between components (parent to child, child to parent, brother component to value)
- Epidemic strikes -- Thinking about telecommuting | community essay solicitation
- Perf simple process for multithreaded profile
- Defensive programming skills
- pytest多进程/多线程执行测试用例
- 【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
- 【读书会第十三期】多媒体处理工具 FFmpeg 工具集
- Apple submitted the new MAC model to the regulatory database before the spring conference
猜你喜欢

I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer

Why is it recommended that technologists write blogs?

Detailed explanation of PPTC self recovery fuse

Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)

Third party login initial version

Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption

Wechat official account web page authorization

Select sorting and bubble sorting template

Unity 绘制弹球和台球的运动轨迹

选择排序与冒泡排序模板
随机推荐
思考的小记录
JVM family -- monitoring tools
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
Perf simple process for multithreaded profile
Why is it recommended that technologists write blogs?
指针数组和数组指针
vue多级路由嵌套怎么动态缓存组件
Redis cluster view the slots of each node
Zlmediakit compilation and webrtc push-pull flow testing
Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool
Rhcsa-- day one
The new data center helps speed up the construction of a digital economy with data as a key element
ctf-pikachu-CSRF
vim映射命令
LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)
Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
还原窗口位置的微妙之处
【读书会第十三期】多媒体处理工具 FFmpeg 工具集
Katalon framework test web (XXVI) automatic email
Smart subway | cloud computing injects wisdom into urban subway transportation