Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
DarkRuskov

Modify a linux command

Recommended Posts

Posted · Original PosterOP

Hi guys,

 

is anyone aware of a method to modify a linux command to change its functionality (like adding a feature) ?

 

Have a nice day !

Link to post
Share on other sites
8 minutes ago, DarkRuskov said:

is anyone aware of a method to modify a linux command to change its functionality (like adding a feature) ?

You download the source-code, add your changes, then recompile it.


Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to post
Share on other sites
Posted · Original PosterOP
20 minutes ago, WereCatf said:

You download the source-code, add your changes, then recompile it.

Ok thanks, and where would one find source code for basic commands such as ls or poweroff ?

Link to post
Share on other sites
2 minutes ago, DarkRuskov said:

Ok thanks, and where would one find source code for basic commands such as ls or poweroff ?

Find out the package it belongs to and then search for that package's source code. Basic things like ls are part of the GNU coreutils package, for example: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src

There you can find, for example, ls: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c


Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | Storage: 250 GB Crucial BX100 SSD + 2 TB Seagate HDD + 1TB WD Green + 3TB WD Red | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9360 | CPU: i5 7200U | RAM: 8 GB

Link to post
Share on other sites
4 minutes ago, DarkRuskov said:

Ok thanks, and where would one find source code for basic commands such as ls or poweroff ?

If you're on a Debian-based OS, you could e.g. find which package the file belongs to:

dpkg -S /bin/ls

Which will reply that it belongs to coreutils. Then you can use apt-cache show coreutils to find out the package's homepage and source-code. Alternatively, you can use apt to download the package's source-code like e.g. here: https://askubuntu.com/questions/28372/how-do-i-get-and-modify-the-source-code-of-packages-installed-through-apt-get

 


Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to post
Share on other sites
52 minutes ago, DarkRuskov said:

Hi guys,

 

is anyone aware of a method to modify a linux command to change its functionality (like adding a feature) ?

 

Have a nice day !

What exactly do you want to change? Depending on that there are simpler ways of changing basic functionality... for instance you could alias "ls" to your own script or parameters or to an alternative program like exa.

 

Changing and recompiling the program isn't really advised because you lose access to updates for that program and for something as essential as ls it might break parts of your system.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
Posted · Original PosterOP
15 minutes ago, Sauron said:

What exactly do you want to change? Depending on that there are simpler ways of changing basic functionality... for instance you could alias "ls" to your own script or parameters or to an alternative program like exa.

 

Changing and recompiling the program isn't really advised because you lose access to updates for that program and for something as essential as ls it might break parts of your system.

I have a raspberry pi and I want it to show a message on a nokia screen right before powering off to know when it's safe to unplug it. The problem is that showing this image before executing the command won't cut it since in the case where the poweroff command takes too much time the user could unplug it without it being safe. There is a method to show the PI's status with an LED and GPIO pins but it isn't acceptable in my case.

 

My thinking was to run the script once the bulk of the shutting down was done. If you think of a better way I'm all ears because I agree with you, mine is extremely janky...

This is necessary since the screen stays on/doesn't clear once the pi shuts down.

Link to post
Share on other sites
24 minutes ago, DarkRuskov said:

I have a raspberry pi and I want it to show a message on a nokia screen right before powering off to know when it's safe to unplug it. The problem is that showing this image before executing the command won't cut it since in the case where the poweroff command takes too much time the user could unplug it without it being safe. There is a method to show the PI's status with an LED and GPIO pins but it isn't acceptable in my case.

 

My thinking was to run the script once the bulk of the shutting down was done. If you think of a better way I'm all ears because I agree with you, mine is extremely janky...

This is necessary since the screen stays on/doesn't clear once the pi shuts down.

You could use a systemd service. The ExecStop option allows you to run a script when the service stops and if you start that service first it will be stopped last, meaning that that script will be the last thing the pi executes before shutdown. I'm assuming this is on raspbian of course - if you aren't using a systemd distribution then you'll need to look up how to do something similar with your init system.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
Posted · Original PosterOP
2 minutes ago, Sauron said:

You could use a systemd service. The ExecStop option allows you to run a script when the service stops and if you start that service first it will be stopped last, meaning that that script will be the last thing the pi executes before shutdown. I'm assuming this is on raspbian of course - if you aren't using a systemd distribution then you'll need to look up how to do something similar with your init system.

I am indeed on raspbian. Thanks a lot, it seems much cleaner ! My question then is what's the best way to order how services start ?

Link to post
Share on other sites
7 minutes ago, DarkRuskov said:

I am indeed on raspbian. Thanks a lot, it seems much cleaner ! My question then is what's the best way to order how services start ?

I *think* it's enough to enable the service, since systemd has parallel initialization most services should be started together and stopped more or less together - the delay between when this service stops and the others do should be minimal anyway. A lot of larger services need to wait for other services to start so a custom service with no dependencies should be among the first to start. I'm not aware of a simple way of making it the absolute first to start without manually changing the dependencies for all other services to include it, which I wouldn't advise unless it's absolutely necessary. Since it does basically nothing I would expect it to start and stop in a matter of milliseconds, probably less time than your screen takes to update.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
Posted · Original PosterOP
15 minutes ago, Sauron said:

I *think* it's enough to enable the service, since systemd has parallel initialization most services should be started together and stopped more or less together - the delay between when this service stops and the others do should be minimal anyway. A lot of larger services need to wait for other services to start so a custom service with no dependencies should be among the first to start. I'm not aware of a simple way of making it the absolute first to start without manually changing the dependencies for all other services to include it, which I wouldn't advise unless it's absolutely necessary. Since it does basically nothing I would expect it to start and stop in a matter of milliseconds, probably less time than your screen takes to update.

OK thank you very much, I'm going to test this, seems very promising !

Link to post
Share on other sites

You can create a bash file with the same name as the program and export a path to it before all your other paths. That essentially will execute your bash script instead of the actual program. It wont add any new features though unless you are going to reinvent the wheels and implement everything it does and more in the script. 


Sudo make me a sandwich 

 

Check out my guide on creating your own private cloud storage

 

Link to post
Share on other sites
Posted · Original PosterOP
On 11/19/2019 at 5:28 PM, wasab said:

You can create a bash file with the same name as the program and export a path to it before all your other paths. That essentially will execute your bash script instead of the actual program. It wont add any new features though unless you are going to reinvent the wheels and implement everything it does and more in the script. 

I see, thanks ! But I think the other methods are more aligned with what I want to do :)

Link to post
Share on other sites
On 11/19/2019 at 5:28 PM, wasab said:

You can create a bash file with the same name as the program and export a path to it before all your other paths. That essentially will execute your bash script instead of the actual program. It wont add any new features though unless you are going to reinvent the wheels and implement everything it does and more in the script. 

This is a somewhat dangerous option because you're changing the behaviour of a linux command which might be used in other scripts you use.  Since you're changing the behaviour of the program, you're maybe breaking.  Luckily, most shells have an alias command.  If you do

 

alias ls="ls -C"

you'll get the different behaviour for interactive console use, but scripts will still use the default behaviour.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×