Linux Custom Commands - Simplify Your Work

Sometimes some common commands or common operations can be implemented by custom commands

custom command

For example, nvidia-smiit takes too long to check the running status of the GPU each time, and it is very troublesome to input each time. You can modify it in the following way.

After that, gpuyou can view it every time you enter it.

The operation is as follows:

vim ~/.bashrc

Add a sentence at the end of the text:

alias gpu='nvidia-smi'

Then: wq save and launch, and then source:

source ~/.bashrc

At this time, linuxthe terminal recognizes gputhis command:
insert image description here
this is where the real power lies. The simplest example is shown below.

automated operation

For example, every time I enter the server, the first thing I do is activate a dittovirtual environment called conda, and then enter a folder called ditto. Such an operation that must be repeated every time can be written into a shell file.

vim ditto.sh

insert image description here
Save and exit, then assign the file executable permissions

chmod +x ditto.sh

insert image description here
When the file turns green, it means it is executable.

After entering the server each time, you can pass

source ditto.sh

Directly implement the operations implemented in the shell script.
insert image description here

Going one step further, if you want to save trouble, just use instructions.

edit in the same way.bashrc

vim ~/.bashrc

After entering, add the following line:

alias ditto='source ~/ditto.sh'

Click after saving and exiting source.

source ~/.bashrc

Then, enter it in the terminal dittoto directly achieve the goal.
insert image description here

Guess you like

Origin blog.csdn.net/He_r_o/article/details/127677412