Sometimes some common commands or common operations can be implemented by custom commands
custom command
For example, nvidia-smi
it 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, gpu
you 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, linux
the terminal recognizes gpu
this command:
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 ditto
virtual 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
Save and exit, then assign the file executable permissions
chmod +x ditto.sh
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.
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 ditto
to directly achieve the goal.