LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-13-2011, 12:30 PM   #1
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Rep: Reputation: Disabled
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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-13-2011, 12:37 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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.
 
1 members found this post helpful.
Old 11-13-2011, 12:41 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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
 
1 members found this post helpful.
Old 11-13-2011, 12:41 PM   #4
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tronayne View Post
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.
 
Old 11-13-2011, 12:44 PM   #5
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sycamorex View Post
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).
 
Old 11-13-2011, 12:44 PM   #6
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by venom4u31 View Post
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 View Post
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
 
Old 11-13-2011, 12:48 PM   #7
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Doc CPU View Post
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.
 
Old 11-13-2011, 12:58 PM   #8
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by venom4u31 View Post
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.
 
Old 11-13-2011, 12:59 PM   #9
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sycamorex View Post
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.
 
Old 11-13-2011, 01:03 PM   #10
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by venom4u31 View Post
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
 
1 members found this post helpful.
Old 11-13-2011, 01:04 PM   #11
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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
 
1 members found this post helpful.
Old 11-13-2011, 01:53 PM   #12
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by venom4u31 View Post
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.
 
2 members found this post helpful.
Old 11-13-2011, 01:55 PM   #13
venom4u31
Member
 
Registered: Oct 2011
Distribution: Debian 6
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tronayne View Post
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.
 
Old 11-14-2011, 05:25 AM   #14
Stephen Morgan
Member
 
Registered: Feb 2011
Location: England
Distribution: Slackware
Posts: 164

Rep: Reputation: 18
I believe cd is a shell built-in command, rather than a programme with its own source code.
 
1 members found this post helpful.
Old 11-14-2011, 07:41 AM   #15
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Stephen Morgan View Post
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.
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Command Verbal Kint Linux - Software 2 06-13-2007 11:37 PM
How do I edit files in command line sweb74 Linux - Newbie 13 01-27-2004 10:53 PM
Edit from Command Prompt Paul Mon Linux - General 4 09-22-2003 08:20 PM
how to edit a file when not in X (ie from the command line) ludwig W Linux - Newbie 12 04-22-2003 04:00 AM
what is the command to edit ultravox Linux - General 5 04-06-2003 05:49 PM

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

All times are GMT -5. The time now is 03:49 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