linux – Where to save your functions for the terminal?


I have to work with different servers on linux, I connect via ssh.
And often you have to do various routine work through the console.

I created a working file (.sh) for myself, where I collected the written functions.
Here is the simplest example:

cdl() { 
   cd "$@" && ls -la; 

and this file with functions, I throw it into the working directory from project to project, and before connecting to the project, I always run this file so that the functions are connected.

Is it possible to write these functions somewhere in the kernel or somewhere else so that I don’t have to run this file every time, but simply write these functions into some file that will automatically see my functions?


if it's just a bash program and only interactive sessions, then ~/.bashrc would be the right place for your own functions.

you can either add the function code directly to this file:

$ cat ~/мои.функции | ssh пользователь@машина 'cat >> ~/.bashrc'

or add only a call to this file (copying the file itself):

$ scp ~/мои.функции пользователь@машина:
$ ssh пользователь@машина 'echo "if [ -f ~/мои.функции ]; then . ~/мои.функции; fi" >> ~/.bashrc'
Scroll to Top