How save alias for often commands in Kubuntu 18.04?

How save alias for often commands in Kubuntu 18.04?
0

Hello,
Using konsole in Kubuntu 18.04 I make alias for often commands with alias command.
But restarting OS I see that my commands are lost.
Searching in net I found a solution with
~/.bash_profile
file, but I did not find any .bash_profile file on my OS…
Have I create it it? In which format ?

Which is right way ?

Thanks!

The default .bashrc file should have these lines (if not, just add them)

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

You can then add aliases in a .bash_aliases file.

2 Likes

@PetroGromovo You can put aliases directly in your .bashrc file. However, I recommend using functions, you can do much more with a function than an alias.

Examples:
When you run ls it will run ls --color=auto.
alias ls='ls --color=auto'

Here is an example function.
Search through your Bash history.

function hg() {
    history | grep -i "$1";
}

Run it like this to search for the word “apt”:

$ hg apt

Sample output:

282    apt update
283    apt update

Re-run a previous command:

$ !282