Linux find source code

Where do you download Linux source code? [closed]

Say I’m interested in the source for one particular Linux utility, like factor . Where can I find the source code for that utility?

8 Answers 8

You can also find out which package the binary comes from an download that packages source code.

On Debian (and Ubuntu and anything else that’s based on Debian) you do that like this:

$ dpkg -S /usr/bin/factor coreutils: /usr/bin/factor $ apt-get source coreutils

The first command will check which package contains the file you are searching for (use » which factor » to find out which binary is executed when you just type » factor «).

The second command will download and unpack the sources (including the patches applied to build the package) to the current directory, so it should be executed in a dedicated or temporary directory.

I’m pretty sure rpm -based distributions have a similar mechanism, but I don’t know their commands.

Thanks, that’s a good, non-Google option. I know Google will always be there, but for some reason I still like knowing how to live without it.

and went to the bottom and found ‘GNU coreutils 6.10’. So I googled ‘coreutils’ and. found the site joschi just linked to.

Thanks, this (a general explanation of how to find the source for a given program) is what I was after.

That may not be a good idea for all things. Some distributions may have modified the original for their distribution. It may be a better idea to use the package management software that comes with you system (Package management can get source as well as binaries) See ‘Saua’ below.

To find the package a binary comes from, in rpm based system, you might type:

which will print the package name. Instead, with:

you will get also information on a package, including it’s home page in many cases.

Source rpms also exist, but how to get them depends on the high-level package manager used on top of RPM (yum, urpmi, apt-get4 for rpm, . ).

On most systems, also, /usr/share/doc/ contains some documentation on the program, and the website link is pretty often found somewhere there, maybe in the README.

Usually you’ll find the source code on the website of the program if it is open source. In this case here since factor is part of coreutils.

On Gentoo, simply look in the ebuild you compiled the package with :D.

# which factor /usr/bin/factor # grep '/usr/bin/factor' /var/db/pkg/*/*/CONTENTS /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/bin/factor 5aaf903daa4345efb11618b3cb47e9a5 1224224574 /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/lib64/debug/usr/bin/factor.debug 517d965636850633e9b15926dde8c222 1224224575 # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/SRC_URI ftp://alpha.gnu.org/gnu/coreutils/coreutils-6.12.tar.lzma mirror://gnu/coreutils/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12-patches-1.0.tar.lzma http://dev.gentoo.org/~vapier/dist/coreutils-6.12-patches-1.0.tar.lzma # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/HOMEPAGE http://www.gnu.org/software/coreutils/

But of course, the source code is probably still available in /usr/portage/distfiles .

Читайте также:  Linux types of servers

Источник

Where can I find system call source code?

In Linux where can I find the source code for all system calls given that I have the source tree? Also if I were to want to look up the source code and assembly for a particular system call is there something that I can type in terminal like my_system_call ?

3 Answers 3

You’ll need the Linux kernel sources in order to see the actual source of the system calls. Manual pages, if installed on your local system, only contain the documentation of the calls and not their source itself.

Unfortunately for you, system calls aren’t stored in just one particular location in the whole kernel tree. This is because various system calls can refer to different parts of the system (process management, filesystem management, etc.) and therefore it would be infeasible to store them apart from the part of the tree related to that particular part of the system.

The best thing you can do is look for the SYSCALL_DEFINE2 macro. It is used (obviously) to define the given block of code as a system call. For example, fs/ioctl.c has the following code :

SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) < /* do freaky ioctl stuff */ >

Such a definition means that the ioctl syscall is declared and takes three arguments. The number next to the SYSCALL_DEFINE means the number of arguments. For example, in the case of getpid(void) , declared in kernel/timer.c , we have the following code :

Hope that clears things up a little.

Источник

How to find the source code by a simple method [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

As I know,the Linux is a open source project,which mean we can find all code that build this system. But that is too hard for me. Is there a simple method which can check the source code of any command? Such as the function hostname . I find it will write the information into its configure file(it may be not /etc/sysconfig/network in CentOS 6.3 I think). I hope to find the real configure file. So how to find a source code about a command(such as hostname ) by a simple method?

welcome. sometimes a google search such as «hostname.c site:github.com» yields useful results for this type of query.

You must ask the packaging system which package provided the command, and how it was built. This might need to be done recursively for dependencies.

1 Answer 1

There’s no simple method. But it’s doable for files which are part of an RPM:

  • rpm -qf for a given filename identifies the package
  • rpm -qi for a given package tells a little about where the program came from.
  • In particular, if it’s a CentOS package, you can find a source-rpm («.srpm») on CentOS’s web/ftp-server. That can be unpacked to get the source-tarball and patches.

If it’s not in an RPM, it’s hard to find the source unless you know how the file got there. For non-CentOS packages, the packager may identify the source location, maybe not.

Читайте также:  Запустить процесс от имени другого пользователя linux

For instance, your example hostname might be provided by coreutils, but RPM says it is not:

$ rpm -qi `rpm -qf /usr/bin/hostname` Name : hostname Version : 3.13 Release : 3.el7 Architecture: x86_64 Install Date: Fri Jul 4 13:23:13 2014 Group : System Environment/Base Size : 19449 License : GPLv2+ Signature : RSA/SHA256, Thu Jul 3 21:54:35 2014, Key ID 24c6a8a7f4a80eb5 Source RPM : hostname-3.13-3.el7.src.rpm Build Date : Mon Jun 9 17:48:44 2014 Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem Vendor : CentOS URL : http://packages.qa.debian.org/h/hostname.html Summary : Utility to set/show the host name or domain name Description : This package provides commands which can be used to display the system's DNS name, and to display or set its hostname or NIS domain name. 

Since the Vendor is CentOS , you can find the source on CentOS’s site. Or you could follow the given URL (which can take some work). In this case, Debian offers a link to browse the source code, because Debian maintains the program. In cases where they do not, often a tar-ball is the best you’ll find.

Источник

How do I look at the source code for a command? [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

$ ls -al /usr/bin/echo -rwxr-xr-x. 1 root root 32536 Oct 31 2016 /usr/bin/echo 
  1. Find out which package it’s in
  2. Get the source
  3. Rebuild it
  4. Test it
  5. Install the new version system-wide

(I know that 5’s not a good idea, I’m just curious. )

I’m currently on Fedora, but I’d also be interested in the answers for Debian

A link to a relevant tutorial would be a good answer.

$ type -a echo echo is a shell builtin echo is /usr/bin/echo 

So I guess it’s the one in /usr/bin/echo I’d like to see rather than trying to read the whole of bash .

type -a echo ; echo is a shell builtin ; echo is /usr/bin/echo ; So I guess I want to see the /usr/bin/echo one rather than read all of bash!

2 Answers 2

Debian (and derivatives)

Run dpkg -S /path to see which package /path belongs to:

$ dpkg -S /bin/echo coreutils: /bin/echo 

Get the source (I’m on Ubuntu):

$ apt-get source coreutils Reading package lists. Done Need to get 5,755 kB of source archives. Get:1 http://jp.archive.ubuntu.com/ubuntu xenial/main coreutils 8.25-2ubuntu2 (dsc) [2,071 B] Get:2 http://jp.archive.ubuntu.com/ubuntu xenial/main coreutils 8.25-2ubuntu2 (tar) [5,725 kB] Get:3 http://jp.archive.ubuntu.com/ubuntu xenial/main coreutils 8.25-2ubuntu2 (diff) [28.0 kB] Fetched 5,755 kB in 3s (1,758 kB/s) gpgv: Signature made 2016年02月18日 22時28分36秒 JST using RSA key ID 73F3F233 gpgv: Can't check signature: public key not found dpkg-source: warning: failed to verify signature on ./coreutils_8.25-2ubuntu2.dsc dpkg-source: info: extracting coreutils in coreutils-8.25 dpkg-source: info: unpacking coreutils_8.25.orig.tar.xz dpkg-source: info: unpacking coreutils_8.25-2ubuntu2.debian.tar.xz dpkg-source: info: applying no_ls_quoting.patch dpkg-source: info: applying 61_whoips.patch dpkg-source: info: applying 63_dd-appenderrors.patch dpkg-source: info: applying 72_id_checkngroups.patch dpkg-source: info: applying 80_fedora_sysinfo.patch dpkg-source: info: applying 85_timer_settime.patch dpkg-source: info: applying 99_kfbsd_fstat_patch.patch dpkg-source: info: applying 99_hppa_longlong.patch dpkg-source: info: applying 99_float_endian_detection.patch 
$ cd coreutils-8.5 $ find src -iname '*echo*' src/echo.c 

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Читайте также:  Ssh over vpn linux

Simple custom implementation of the Linux find command.

dlowrey/find

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A simplified implementation of the ‘find’ utility on Linux systems. This utility is used to locate files on a Unix or Linux system, searching any set of directories that are specified for files that match the supplied search criteria, including:

and optionally perform an action once that file has been found. Supported actions so far include:

  • default printing the full path,
  • deleteing/removing the file (delete, rm),
  • output the file contents (cat),
  • move/rename the fiel (mv)
  1. Clone this Repo, or obtain a copy of the find.c file.
  2. On a Linux OS, gcc -o find /path/to/find.c
  3. You can now run ./find from the directory where #2 was executed from.

Displays the pathnames of all files and directories in the specified directory and all subdirectories. If no directory is specified, the default is the current working directory.

find where-to-look criteria

find where-to-look -name

This will search the specified directory (where-to-look) and all subdirectories for any files or directories named and display their paths.

find where-to-look -min

This will find files and directories modified with the specified number of minutes ago You can specify a number “n” to mean exactly n, “-n” to mean less than n, and “+n” to mean more than n.

  • find testdir -min +10
  • find testdir -min -10
  • find testdir -min 10
  • find -min +10

find where-to-look -inum

Find a file or directory that has i-node number given.

find where-to-look criteria execute

find where-to-look criteria -exec [delete|rm]

Find files or directories matching any specified criteria and remove them.

  • find testdir -name testfile -exec delete
  • find -name dir3 -exec rm
  • find -name testfile2 -exec rm

find where-to-look criteria -exec cat

Find files matching any specified criteria and output their contents.

find where-to-look criteria -exec mv newfilename

Find files or directories matching any specified criteria and rename/move them.

About

Simple custom implementation of the Linux find command.

Источник

Оцените статью
Adblock
detector