LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09:15 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 09:20 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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, 09:44 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 09:52 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

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, 09:54 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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, 10:25 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 10: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,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
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, 10:56 AM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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, 11:49 AM   #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,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
fair enough
I believe those commands are part of the package 'coreutils'
http://ftp.gnu.org/gnu/coreutils/
 
Old 11-21-2012, 12:13 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try the suggestions here http://www.thegeekstuff.com/2010/02/...linux-command/
 
Old 11-21-2012, 03:56 AM   #11
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
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, 04:02 AM   #12
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
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, 12:05 PM   #13
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800

Original Poster
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Thanks everyone!
 
  


Reply

Tags
command, shell



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:25 PM.

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
Open Source Consulting | Domain Registration