LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I edit a command? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-edit-a-command-913328/)

venom4u31 11-13-2011 12:30 PM

How can I edit a command?
 
Some commands (or most), as far as I know are stored inside files within the bin folder. My question is how can I edit such commands? For example, if I want to change what cd does, how can I do that?

Obviously, I don't want to change those basic commands, but I want to change custom commands that might be installed by me.

tronayne 11-13-2011 12:37 PM

Get the source, edit the source, compile the source and install it (preferably with a different name -- when you get updates for your system, they'll overwrite existing files).

The source may already be on your distribution media (Slackware is) or you'll need to find it at your distribution web site.

Hope this helps some.

sycamorex 11-13-2011 12:41 PM

I wouldn't recommend changing the original commands. You could create your own commands. This can be done in 2 ways:

a) Create an alias in ~/.bashrc

eg.
Code:

alias elisp='cd /home/sycamorex/data/projects/programming/lisp ; emacs -nw'
alias ffp="ps aux | grep firefox"


b) create a directory ~/bin and add it to your path by adding "export PATH=$PATH:~/bin" to ~/.bashrc
After that create shell scripts in ~/bin

For example, a program that lists all my aliases:
Code:

#!/bin/bash

sed -n '/^alias/ s///gp' ~/.bashrc

exit 0

Make it executable to be able to run it:
chmod +x ~/bin/name_of_the_file

venom4u31 11-13-2011 12:41 PM

Quote:

Originally Posted by tronayne (Post 4523031)
Get the source, edit the source, compile the source and install it (preferably with a different name -- when you get updates for your system, they'll overwrite existing files).

The source may already be on your distribution media (Slackware is) or you'll need to find it at your distribution web site.

Hope this helps some.

So what you're saying is that I cannot reverse engineer an installed command to its source code so I can edit it? I might not have direct access to the source.

venom4u31 11-13-2011 12:44 PM

Quote:

Originally Posted by sycamorex (Post 4523034)
I wouldn't recommend changing the original commands. You could create your own commands. This can be done in 2 ways:

a) Create an alias in ~/.bashrc

eg.
Code:

alias elisp='cd /home/sycamorex/data/projects/programming/lisp ; emacs -nw'
alias ffp="ps aux | grep firefox"


b) create a directory ~/bin and add it to your path by adding "export PATH=$PATH:~/bin" to ~/.bashrc
After that create shell scripts in ~/bin

For example, a program that lists all my aliases:
Code:

#!/bin/bash

sed -n '/^alias/ s///gp' ~/.bashrc

exit 0

Make it executable to be able to run it:
chmod +x ~/bin/name_of_the_file

I understand what you're saying. I know I can combine commands in shell scripting, but I wonder how I can change complex commands (that are separately installed).

Doc CPU 11-13-2011 12:44 PM

Hi there,

Quote:

Originally Posted by venom4u31 (Post 4523025)
Some commands (or most), as far as I know are stored inside files within the bin folder. My question is how can I edit such commands? For example, if I want to change what cd does, how can I do that?

actually, most of these "commands" like ls or cat are in fact nothing else than small programs. So how do you change them? Normally you don't.

Quote:

Originally Posted by venom4u31 (Post 4523025)
Obviously, I don't want to change those basic commands, but I want to change custom commands that might be installed by me.

Then we're talking of programs you'll have to write. You've got to learn a common programming language like for instance C, C++ or Java, you'll need the programming tools like a compiler, and a lot of knowledge of how these things work.

For simple tasks, script languages like Perl or PHP may be sufficient; these programs aren't compiled (i.e. translated into machine code), but instead remain human-readable, and the so-called interpreter translates them on-the-fly each time they're executed.

What's really suitable for you depends very much on what you want to achieve, and what programming skills and experience you already have.

[X] Doc CPU

venom4u31 11-13-2011 12:48 PM

Quote:

Originally Posted by Doc CPU (Post 4523037)
Hi there,



actually, most of these "commands" like ls or cat are in fact nothing else than small programs. So how do you change them? Normally you don't.



Then we're talking of programs you'll have to write. You've got to learn a common programming language like for instance C, C++ or Java, you'll need the programming tools like a compiler, and a lot of knowledge of how these things work.

For simple tasks, script languages like Perl or PHP may be sufficient; these programs aren't compiled (i.e. translated into machine code), but instead remain human-readable, and the so-called interpreter translates them on-the-fly each time they're executed.

What's really suitable for you depends very much on what you want to achieve, and what programming skills and experience you already have.

[X] Doc CPU

Programming languages aren't a problem. I want to know how can I reverse engineer the executables (or the sheer programs) to their source code and edit them from there.

sycamorex 11-13-2011 12:58 PM

Quote:

Originally Posted by venom4u31 (Post 4523039)
Programming languages aren't a problem. I want to know how can I reverse engineer the executables (or the sheer programs) to their source code and edit them from there.

Well, if you're at the level where you are actually skilled enough to make those modifications, I don't understand your question. Grab the sources and start coding:)

Depending on a distribution, the sources might already be installed on the system. If not, it's easy to install them.

venom4u31 11-13-2011 12:59 PM

Quote:

Originally Posted by sycamorex (Post 4523046)
Well, if you're at the level where you are actually skilled enough to make those modifications, I don't understand your question. Grab the sources and start coding:)

Depending on a distribution, the sources might already be installed on the system. If not, it's easy to install them.

Unfortunately I only have the programs, not the sources. I wanted to ask if I can generate the sources from the installed programs.

Doc CPU 11-13-2011 01:03 PM

Hi there,

Quote:

Originally Posted by venom4u31 (Post 4523039)
Programming languages aren't a problem. I want to know how can I reverse engineer the executables (or the sheer programs) to their source code and edit them from there.

why? If we're talking about GNU/Linux, you do have access to the source code. So why make it harder than necessary?
Besides, yes, it is possible to reverse-engineer the machine code and reconstruct the source to a certain extent. But you have no identifiers (symbols, variable or function names) because they're left behind during compilation. You have no comments that tell you how a few lines of code are supposed to work.

So that hard work isn't worth the effort, unless you're talking about closed-source software and you have a very strong motivation to disclose how it works.

[X] Doc CPU

sycamorex 11-13-2011 01:04 PM

Which distro are you using and what programs are we talking about?
If these are not open-source programs then you've got a problem:)

tronayne 11-13-2011 01:53 PM

Quote:

Originally Posted by venom4u31 (Post 4523035)
So what you're saying is that I cannot reverse engineer an installed command to its source code so I can edit it? I might not have direct access to the source.

Why in the world would you want to reverse-engineer instead of just getting the blasted source and edit from there? You, in fact, do have access to everything in Linux, the kernel source, all the programs and utilities source; it's free and open source.

If you're trying to reverse-engineer a proprietary package, well, that's different (and you're on your own for that one -- don't be naughty).

The key phrase is "free and open source;" that literally means you can get the source for anything that is free and open source, just go look for it (Google is your fiend here). You've obviously got internet access: Want the source code for VirtualBox -- go download it; what the source for LibreOffice -- go download it; want the source for cd -- go download it.

Hope this helps some.

venom4u31 11-13-2011 01:55 PM

Quote:

Originally Posted by tronayne (Post 4523082)
Why in the world would you want to reverse-engineer instead of just getting the blasted source and edit from there? You, in fact, do have access to everything in Linux, the kernel source, all the programs and utilities source; it's free and open source.

If you're trying to reverse-engineer a proprietary package, well, that's different (and you're on your own for that one -- don't be naughty).

The key phrase is "free and open source;" that literally means you can get the source for anything that is free and open source, just go look for it (Google is your fiend here). You've obviously got internet access: Want the source code for VirtualBox -- go download it; what the source for LibreOffice -- go download it; want the source for cd -- go download it.

Hope this helps some.

It does. Thanks. I didn't fully understand how this system works.

Stephen Morgan 11-14-2011 05:25 AM

I believe cd is a shell built-in command, rather than a programme with its own source code.

MTK358 11-14-2011 07:41 AM

Quote:

Originally Posted by Stephen Morgan (Post 4523502)
I believe cd is a shell built-in command, rather than a programme with its own source code.

I don't know why anyone marked this as unhelpful, because it's true.

In fact, it's impossible to create a separate program that changes the current directory of the shell, since each process (including the shell and command) has its own separate current directory.

tronayne 11-14-2011 08:59 AM

Quote:

Originally Posted by Stephen Morgan (Post 4523502)
I believe cd is a shell built-in command, rather than a programme with its own source code.

Well, duh! Yup, cd is definitely part of the shell -- of course, one could modify the source to change the behavior of cd but that may be equivalent to those little dancing dogs you see in the circus: the question is not how well but rather why at all, methinks.

venom4u31 11-14-2011 02:31 PM

Quote:

Originally Posted by MTK358 (Post 4523583)
I don't know why anyone marked this as unhelpful, because it's true.

In fact, it's impossible to create a separate program that changes the current directory of the shell, since each process (including the shell and command) has its own separate current directory.

Relax, it's not that unhelpful. I was only asking about reverse engineering the code from the executable (in the case of compiled programs), which I believe that most of the installed programs are.

frieza 11-14-2011 02:51 PM

there are two different types of commands
'internal' and 'external' commands
internal commands are part of the shell
external commands are separate binaries that are executed by the shell
a lot of the basic commands that are not internal commands (such as ls) can be found in the 'coreutils' package

chrism01 11-15-2011 07:15 PM

The thing to be clear on, is that whether the cmd is part of the shell, or 'external', Linux is FOSS (Free & Open Src SW).
This means that the src code should be available from your normal repos. Most distros don't install the src code by default, because most people don't want/need it.

Note that some distros also give access to non-open SW.
That would involve reverse engineering, which is likely illegal ... depending on jurisdiction/reason for doing so etc.

What Sw do you want to see the src for?

opensourcewj 11-15-2011 07:48 PM

"man alias" you will get what you want.

Roken 11-15-2011 08:17 PM

On the off chance that anyone does want to modify a shell built in function, you can get the source for the shell and modify to your hearts content. As has been said many times in this thread, FOSS (Free open source software) is exactly what it says on the tin, open source. If the source hasn't been made readily available, and if you know it's covered by the gnu license, ask the package author for the source (he'll supply it under the terms of the license).

As has also been said, you hit a problem with closed source propriety stuff (which most of GNU/linux isn't) but beyond that the world is your oyster.


All times are GMT -5. The time now is 05:32 PM.