LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2006, 12:16 PM   #1
mohdniyas
LQ Newbie
 
Registered: Oct 2006
Location: Bangalore
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 0
Viewing source code for linux command


Hi,
How to view the source code for linux shell commands like cat,ls,date,etc?
I tried to open the file /bin/cat using OpenOffice but many charecters in the file are unintelligible..
I thought i can view the source code in C language..How to view it?
Should we use some other coding than Unicode to view the source code in readable(intelligible) form?
Thanks in advance..
 
Old 12-07-2006, 12:23 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Binary files don't have the source code embedded in them (unless they are debugging versions).

Those utilities are part of the coreutils package. You can get the source right from the source (i.e., http://ftp.gnu.org/pub/gnu/coreutils...ls-6.6.tar.bz2). Also, usually your distro will have a source-package corresponding to each binary package. In this case, install the relevant package.
 
Old 12-07-2006, 12:40 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
What distro are you using?

In Ubuntu and other Debian-based distros you can request the installation of the source code for a given package using the "apt-get source <packagename>" command. This will not work on distros which are not derived from debian. To really help you, we need to know what distro you are using.

Anyhow, going on assumption that you are using Ubuntu, here's what to do to see the code for a specific program.
  1. Open a Terminal window. The following commands should be typed into the terminal window
  2. Find out what package the program belongs to:
    Code:
    dpkg -S /path/to/program/file
    In the case of /bin/cat, the package name is "coreutils"
  3. Getting the source can generate quite a few files (it can be a little messy), so we'll create a sub-directory for them, and change into it:
    Code:
    mkdir ~/src
    cd ~/src
  4. Now use apt-get to fetch the source:
    Code:
    apt-get source coreutils

Now you should have the source. It may be in an archive file, or apt-get might have expanded it for you.

Last edited by matthewg42; 12-07-2006 at 12:40 PM. Reason: typo correction
 
Old 12-08-2006, 10:14 AM   #4
mohdniyas
LQ Newbie
 
Registered: Oct 2006
Location: Bangalore
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
I m using ubuntu..


~/src $ apt-get source coreutils
gave me a message like this
Reading package lists...Done
Building dependancy tree..Done
E: you must put some source URIs in your sources.list
What it means? please..
 
Old 12-08-2006, 10:42 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Your sources.list file contains a list of repositories from which packages are fetched. Looks like you don't have the source repositories enabled.

You can enable them from the synaptic package manager - go into the repository settings (it's an option from one of the menus), and enable the source repos.

Alternatively, if you post the contents of your /etc/apt/source.list file here (in [code] tags), I can show you how to manually edit the file to enable them.
 
Old 12-08-2006, 02:21 PM   #6
mohdniyas
LQ Newbie
 
Registered: Oct 2006
Location: Bangalore
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
Hi,
1.I couldnot find Source Repository settings,to enable it in SynapticPackageManager-->Settings-->Repositories..
2.$/etc/apt/source.list gave me

"Uncomment following two lines to fetch updated software from the network #utuntu site address " kind of messages...

[I m not able to give the entire message here since
I m not able dial up to internet from Ubuntu( Mine is a Huawei wireless modem,which is not being supported by my kernel 2.6.12..I read it is supported by kernel 2.6.18 onwards only)..I have to reboot to MS OS to connect to net..I read of VMWare but i dont know whether my configuration(P4-2.4 GHz, 128Mb RAM)is supported by that..]
 
Old 12-08-2006, 02:56 PM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Which version of Ubuntu do you have? The repository handling in synaptic has change a little over the last few releases. You can find out your release by entering this command:
Code:
grep DISTRIB_DESCRIPTION /etc/lsb*
I have a screenshot from Ubuntu 6.06.1 LTS : http://porpoisehead.net/misc/synap.png

I've highlighted some example entries. Basically, go down the whole list and enable all with "(Source)" next to the name.

If you're running an older version of Synaptic, or for some reason this isn't working, you should edit the /etc/apt/sources.list, and uncomment some of the lines starting with "# deb-src", i.e.
Change this:
Code:
deb http://gb.archive.ubuntu.com/ubuntu/ edgy main restricted universe multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ edgy main restricted universe multiverse
To this:
Code:
deb http://gb.archive.ubuntu.com/ubuntu/ edgy main restricted universe multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ edgy main restricted universe multiverse
Only enable the deb-src lines where the corresponding deb line is not commented out.
 
Old 12-08-2006, 02:57 PM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Oh one more thing. In either case (editing the sources.list or doing it via Synaptic), you need to update repository information before you'll be able to get the sources:
Code:
sudo apt-get update
apt-get source ...
 
Old 12-11-2006, 10:02 AM   #9
mohdniyas
LQ Newbie
 
Registered: Oct 2006
Location: Bangalore
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
Mine is Breezy Badger, Ubuntu 5.10...
I edited /etc/apt/sources.list as you told. But again it is asking for source URIs..
Meanwhile i got a CD with MPlayer..
I tried to install it so that i can listen to mp3 songs while working..but i need to downgrade my gcc to version 3 from 4..
Thanks a lot matthew..
 
Old 12-11-2006, 10:36 AM   #10
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
If the apt-get sources is taking too much effort to configure, don't worry so much about it... I only suggested it because it's more convenient (once configured) than downloading sources manually.

I have found in the past that mplayer is a massive pain in the rear to compile. If you can get binary packages, you'll save yourself a lot of effort.
 
Old 12-11-2006, 11:29 AM   #11
mohdniyas
LQ Newbie
 
Registered: Oct 2006
Location: Bangalore
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks a lot again..Ur quick responses have multiplied my interest in Linux...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
source code of ps command sudeepghiya Linux - General 1 09-21-2006 11:35 AM
viewing kernel`s source code python302 Programming 3 04-12-2006 02:55 PM
Viewing source code for a program... ksoma Programming 3 02-27-2005 05:05 AM


All times are GMT -5. The time now is 03:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration