LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-19-2023, 05:15 AM   #1
Tricia279
LQ Newbie
 
Registered: Sep 2023
Location: Munich
Distribution: RedHat RHEL 9.1
Posts: 3

Rep: Reputation: 0
Lightbulb how to see the bash script of a linux command


Well,
I will it explain it by an example:

Lets take the command ps -eLf
it shows a lot of system admin stuff.

So if I am on the command line.

How can I see the program lines of this command and where is this command located in the structure ?

Many thanks.

-------------------------------------------------------------------------------------------------------------------------

Okay, one part of my question is good summarized by chrism01.
Thank you.

But my main question is still missing:
If in the path /usr/bin/ps the file respectively command "ps" could be found, I want to see the source code of "ps".
How I can get it in linux ? It is still open source ;-)

Many thanks.

Last edited by Tricia279; 09-21-2023 at 03:29 AM.
 
Old 09-19-2023, 06:47 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Scroll the console buffer up with Shift+PgUp. Works in most terminals.
 
1 members found this post helpful.
Old 09-19-2023, 07:00 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,327
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Or you could pipe the output through a pager like less or more.

Code:
ps -eLf | less
Then you can search with /, ?, !, &, or &! to limit what is show. See the manual page, "man less", for how each of those are used.
 
Old 09-19-2023, 07:58 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,614

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by Tricia279 View Post
How can I see the program lines of this command and where is this command located in the structure ?
There's several possible ways to interpret this.

The above answers assume you're referring to reading long output, and other interpretations might suggest pstree, or type -a ps, or other things.

I'm wondering if you're maybe asking how to see the source code of "ps", and how specifically it implements the three options you provided?

Not sure about RHEL, but for Debian, I start by going to the online man page (i.e. //manpages.debian.org/ps), then following the "package tracker" link (in this case it's //tracker.debian.org/procps) and on that page there's a "browse source code" link (where we can see the ps command is written in C, not Bash).

Navigating source code to discover how things are implemented can sometimes be simple and other times be more complex - there's no single approach that always works, and not much point going on if this turns out to not be what you're asking about...

 
1 members found this post helpful.
Old 09-19-2023, 08:18 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,327
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by boughtonp View Post
I'm wondering if you're maybe asking how to see the source code of "ps", and how specifically it implements the three options you provided?

Not sure about RHEL, ...
A long time ago that would have been by installing the Source RPM (.srpm) from the repository and examining the resulting files and directories. Either way it is now time to get your money's worth out of your expensive support contract with Red Hat and contact them about RHEL.
 
Old 09-19-2023, 09:48 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Do you want its path and its source?

If you want to see where it’s located in the filesystem, it’s “which ps”.
 
1 members found this post helpful.
Old 09-19-2023, 10:53 AM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,614

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by dugan View Post
If you want to see where it’s located in the filesystem, it’s “which ps”.
By default, "which COMMAND" only searches the path, it ignores aliases and built-ins, and (depending on the version of which used) may or not support the -a/--all option.

Using "type COMMAND" will identify when the command would execute a file or something else - compare "which ls" and "which echo" to "type -a ls" and "type -a echo"; in many cases type will identify echo as a shell builtin and show an alias for ls (in addition to the path to the executable).

 
Old 09-20-2023, 12:10 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As others have noted, it's not clear whether you are interested in the output of ps or it's source code.

There are various ways, but on eg Centos 7.9
Code:
# find it
which ps  

/usr/bin/ps

# what filetype is it
file /usr/bin/ps

/usr/bin/ps: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=36fb21d67d92790800dc4212bd9f610602e3dc08, stripped
so its a binary executable and (most likely) written in C.
As above if you're on RHEL as per your sig, you could install the SRPM (source RPM), but the code is likely complex.

HTH
 
2 members found this post helpful.
Old 09-20-2023, 08:35 PM   #9
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,141
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
https://gitlab.com/procps-ng/procps
https://gitlab.com/procps-ng/procps/...ref_type=heads
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [SOLVED] bash script: can echo command, command works if I type, but command doesn't work in script ... why? hopeless_n00b Linux - Newbie 10 07-12-2018 05:57 AM
Bash script - command works directly in command line but not in script raoulcousins Linux - Newbie 6 08-21-2013 07:43 PM
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 12:05 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Cannot see files on GNOME desktop? while I can see it using 'ls' command renshao Fedora 1 03-11-2006 06:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:18 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
Open Source Consulting | Domain Registration