Where can I find source code for Linux core comman

2019-01-12 13:05发布

I'd like to read the actual code which the linux commands are written with. I've gained some experience using them and now I think it's time to interact with my machine at a deeper level. I've found some commands here http://directory.fsf.org/wiki/GNU.

Unfortunately I wasn't able to find basic commands such as 'ls' which seems to me easy enough to begin.

Do you happen to know some web page, book or any other stuff to begin?

I'm running on Ubuntu 12.04

8条回答
We Are One
2楼-- · 2019-01-12 13:43

ls is part of coreutils. You can get it with git :

git clone git://git.sv.gnu.org/coreutils

You'll find coreutils listed with other packages (scroll to bottom) on this page.

查看更多
成全新的幸福
3楼-- · 2019-01-12 13:43
兄弟一词,经得起流年.
4楼-- · 2019-01-12 13:45

Visit for example:

http://ftp.gnu.org/pub/gnu/coreutils/

You can browse the code online. Open one of the archives and check for the src folder.

查看更多
等我变得足够好
5楼-- · 2019-01-12 13:48

All these basic commands are part of the coreutils package.

You can find all information you need here:

http://www.gnu.org/software/coreutils/

If you want to download the latest source, you should use git:

git clone git://git.sv.gnu.org/coreutils

To install git on your Ubuntu machine, you should use apt-get (git is not included in the standard Ubuntu installation):

sudo apt-get install git

Truth to be told, here you can find specific source for the ls command:

http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c

Only 4984 code lines for a command 'easy enough' as ls... are you still interested in reading it?? Good luck! :D

查看更多
戒情不戒烟
6楼-- · 2019-01-12 13:52
    cd ~ && apt-get source coreutils && ls -d coreutils*     

You should be able to use a command like this on ubuntu to gather the source for a package, you can omit sudo assuming your downloading to a location you own.

查看更多
Melony?
7楼-- · 2019-01-12 13:54

Actually more sane sources are provided by http://suckless.org look at their sbase repository:

git clone git://git.suckless.org/sbase

They are clearer, smarter, simpler and suckless, eg ls.c has just 369 LOC

After that it will be easier to understand more complicated GNU code.

查看更多
登录 后发表回答