LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 11-20-2012, 10:15 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
How to read shell built-in commands?


Hello Friends!
How can I read content of a shell built-in command? Since such commands are not simple text files, but executable C language codes, so how can I know that code.
Thanks in advance!
 
Old 11-20-2012, 10:20 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
You'd look at the source code I guess. Is that what you mean? I don't see why a built in command is any different to understanding any other command written in C
 
Old 11-20-2012, 10:44 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Hi Chris,
I just want to check content of any simple shell built-in cmd such as "ls" or "cat".
Can we read or find it's full content in a way like we read a simple text file i.e.
Code:
cat /usr/bin/ls
Although using cat will not give any result because /usr/bin/ls isn't a simple text file. Then how can I read that?
 
Old 11-20-2012, 10:52 AM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,622
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
...because /usr/bin/ls isn't a simple text file. Then how can I read that?
Neither is it a shell built-in

Code:
strings /usr/bin/ls
 
Old 11-20-2012, 10:54 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Those are NOT built in commands. they're just commands. read the source code.

Can I ask why you want to in the first place??
 
Old 11-20-2012, 11:25 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Alright, how can we read source-code of any command available in Unix such as ls, cat, cd, ps etc.?
Quote:
Can I ask why you want to in the first place??
Chris, what do you mean, sorry I didn't understand you question?
 
Old 11-20-2012, 11:48 AM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
first of all if you can list them in the filesystem, they are NOT 'internal' (built in) commands, internal commands would be functions within the code of the shell.
second, they are binary files, not text files.
if you want to find out how the programs do what they do, as mentioned you would have to find the source code.
if you are looking at how to USE the command, then run it's man page
Code:
$ man {command}
 
Old 11-20-2012, 11:56 AM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
I think my question is not clear.
I want to read source code of Unix commands such ls, cat, ps etc.
I am not concerned about their usage i.e. using man <command>.
 
Old 11-20-2012, 12:49 PM   #9
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
fair enough
I believe those commands are part of the package 'coreutils'
http://ftp.gnu.org/gnu/coreutils/
 
Old 11-21-2012, 01:13 AM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Try the suggestions here http://www.thegeekstuff.com/2010/02/...linux-command/
 
Old 11-21-2012, 04:56 AM   #11
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,441

Rep: Reputation: 81
Quote:
Originally Posted by shivaa View Post
Hello Friends!
How can I read content of a shell built-in command? Since such commands are not simple text files, but executable C language codes, so how can I know that code.
Thanks in advance!
The latest bash as of right now seems to be 4.2.

http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz

There is the code.

Many distributions support a feature like this:

Code:
apt-get source bash
This will get the source code and everything else used to create the package in a Debian/Ubuntu/Mint based distro.

So you can go to the homepage of the software and look for a download link to source code or use a command for your distro like the one I gave above.
 
Old 11-21-2012, 05:02 AM   #12
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,441

Rep: Reputation: 81
Also, to find out what package a command belongs to:

Debian/Ubuntu:

dpkg -S /bin/ls

Redhat/Fedora:

rpm -qf /bin/ls

I tested this on my machine running CentOS.

[bullshark@alpha ~]$ rpm -qf /bin/ls
coreutils-8.4-19.el6.x86_64
[bullshark@alpha ~]$

Now you know what package that command belongs to, you can use another command provided by your distro to download the source code, or go find it on the homepage from the web.
 
Old 12-07-2012, 01:05 PM   #13
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Thanks everyone!
 
  


Reply

Tags
command, shell


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
best way to automate shell commands - shell script or python scripts or something els parangsaraf Linux - Newbie 11 08-08-2012 07:17 PM
Ubuntu 11.10 can't read built-in webcam on HP 9sp7ky3 Linux - Software 3 03-28-2012 11:22 PM
how to write a shell script to simulate the built-in linux commands? linuxFreshMan Linux - General 3 11-09-2010 08:22 AM
gnuplot - do multiple plots from data file with built-in commands Meson Linux - Software 2 07-30-2008 04:52 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM


All times are GMT -5. The time now is 09:08 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration