G
G
ganbatte2020-03-28 04:50:36
bash
ganbatte, 2020-03-28 04:50:36

How to create your own command in linux? for example writing helper + tab shows commands and these commands execute bash commands?

I simply don’t remember many commands, and I have to look all over again on the Internet, for example, I use this command very often, docker stop $(docker ps -a -q)I can’t and don’t want to remember it, I just want to helper docker stop all like this. And all commonly used commands want to do so. How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2020-03-28
@ganbatte

You can learn the basics of bash and write your own scripts with commands and options.
You can use aliases.
Write :

alias docker_stop_all="docker stop $(docker ps -a -q)"

And when necessary, write
docker_stop_all
In this case, even auto-completion will work.
You can save this alias in .profile or .bashrc in your home directory, then it will be available as soon as you logged into the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question