LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unable to use the alias command (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-use-the-alias-command-4175600163/)

cyfix 02-19-2017 09:44 PM

unable to use the alias command
 
Hello world,

I am fairly new to linux and just learning how to use the terminal.

I am unable to use the {alias} command (ie: alias list = "ls -a -l -t" )
in fact when i use {whatis alias} i get the message : alias nothing appropriate

i tried {sudo apt-get install alias} but it didn't find anything.

any suggestions?

chrism01 02-19-2017 10:24 PM

No spaces allowed around '=', but for a cmd like that you will need single quotes thus
Code:

alias list='ls -a -l -t'
# OR
alias list='ls -alt'      # you can concatenate options/switches that take no args.

HTH & Welcome to LQ :)

NB: if you type that interactively, it will only persist for the current terminal session.
For permanence, add that line to your .bashrc file (ie /home/<username>/.bashrc.
PS: the 'alias' cmd with no args will list all current aliases.

Note that leading '.' at the start of a filename means its hidden from normal ls cmd; you'll need the -a option to list it.

cyfix 02-19-2017 10:45 PM

ty ty

well i know more about whats inside .bashrc and .bash_history now, but my alias still doesn't work

for example:

{alias Biglist = "ls -alt" } still wont work because my terminal does not acknowledge the command alias

also, where are the aliases saved?

Timothy Miller 02-19-2017 10:49 PM

As chrism01 said, no spaces between alias and first quote.

aka alias biglist='ls -alt'

not alias biglist = 'ls -alt'

Alias's are saved in your bash environment until you log out, unless you make them permanent as pointed out earlier.

chrism01 02-19-2017 10:50 PM

Like I said NO spaces ....
The 'alias' cmd is a built in for the bash shell.
Which shell are you using
Code:

echo $SHELL
NB: *nix is case sensitive for cmds, args filename , options etc..... so type it exactly like that.

Also, please use code tags as specified here https://www.linuxquestions.org/quest...do=bbcode#code

cyfix 02-19-2017 11:28 PM

i see

thanks brethren i figured it all out

pan64 02-20-2017 12:31 AM

glad to hear that.
Please mark the thread solved if your issue is solved. Also please tell us a few words about the solution you found.

cyfix 02-20-2017 01:28 AM

yes,

for all nooblets:

the simple way i found for using aliases is to permanently add them into the terminal using

{gedit .bashrc} then type in any alias you want and restart the terminal to take effect

Shadow_7 02-20-2017 02:43 AM

alias is part of bash, the package is bash, the executable is bash.

$ help alias

$ alias -p

$ unalias ls

$ alias ls='ls --color=auto'

alias is likely common among many shells, but it's part of the shell(s).


All times are GMT -5. The time now is 10:35 PM.