Questions tagged [bash-alias]

An alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence. This can save a great deal of typing in the command-line and avoid having to remember complex combinations of commands and options. Use this tag for questions about using aliases with the bash shell.

Filter by
Sorted by
Tagged with
1
vote
1answer
34 views

Why fish shell does not allow function named `-`

I am trying to use fish as my default interactive shell. I was previously using bash and there was support for alias named - (ASCII hyphen, 0x2d). Why does not fish allow creation of alias or function ...
0
votes
0answers
42 views

How to escape slashes in bash alias name?

I want to make an alias like this: alias /sbin/init="/path/to/my/script/sh" However, when I try to source my .bashrc, it throws an error: -bash: alias: `/sbin/init': invalid alias name How ...
0
votes
0answers
49 views

Bash: How can I edit $@?

I'm writing a wrapper for a utility (in bash). I'd like to pass the utility every argument (including separate flags), except for the first one. I feel that I would like to take $@ and trim $1 (the ...
0
votes
1answer
24 views

How to create complex alias (start Ember, start Rails, and change directory) in Ubuntu 20.10.4

I'd like to use an alias to start my Rails/Ember app, open a new terminal tab and cd into the Ember directory. I use Ubuntu 20.10.4 and the default Terminal. This is what i have so far: alias ...
0
votes
1answer
49 views

How to get my bash alias to run when I open terminal

I setup a bash alias to run neofetch in .bash-alias but the only way to get it to run is to source it in every new terminal window. How can I get it to actually run when the terminal starts/opens? ...
0
votes
0answers
64 views

How to change java version with update-alternatives non-interactively

I regularly need to switch back and forth between using java-11 and java-8 to run different programs. I use update-alternatives --config java to do this, switching between option #0 and option #2: ...
1
vote
1answer
1k views

Alias CMD command from WSL2 shell

I'm running WSL2 on Windows 10, and I want to be able to run a CMD command from it without exiting the Linux shell. Specifically, I want to do: wmic diskdrive get Model,Manufacturer,Size,DeviceID,...
0
votes
1answer
136 views

Migrating aliases from bash to zsh

I recently moved from bash to zsh. Everything is great, I love it! Except some of my old aliases are getting confused. I have a long list of aliases like this that I've just migrated wholesale from ....
0
votes
3answers
51 views

Creating an alias that is an incomplete command

The documentation from tldp.org doesn't really specify when or how the bash interpreter replaces an aliased string. I'm looking for information on how to create an alias that is an incomplete command. ...
0
votes
1answer
52 views

Why is /bash_aliases creating this error when sourced?

I have a .bash_aliases file I've been using for a long time. Today I added some commands that are broken into multiple lines (using \). Since doing that, I can't source the file to reload it. When I ...
3
votes
3answers
400 views

Alias to source .bashrc after it's been edited?

I would like to add an alias (for convenience sake) that would allow me to edit my bashrc, and if changes were made, source it, but if no changes were made, don't source (in case I changed my mind). ...
0
votes
1answer
59 views

How to escape this command to add alias in .bashrc?

I want add alias command to .bashrc. the command like this : xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }' I am confused to escape character from that command. ...
5
votes
4answers
2k views

Space in doskey/alias for windows?

I try to run Laravel's Artisan command inside the (docker) container by defining a doskey alias. My idea was: php artisan=docker-compose exec apache php artisan $1 However it does not allow me to ...
0
votes
1answer
126 views

How to automatically add characters to the user input before command execution

I love reading on the terminal - it focuses my attention and lets me read twice the amount I used to read on browsers, etc. I wrote a script using alias for bash.bashrc that changes the working ...
1
vote
1answer
1k views

Alias file not working in Bash on WSL (Opensuse Leap 42.3)

I have my alias file set up like so in Bash in WSL: alias gvim='/mnt/d/Vim/vim81/gvim.exe' alias vim='/mnt/d/Vim/vim81/vim.exe' alias pngcrush='/mnt/c/Users/nathan/Downloads/pngcrush_1_8_11_w64.exe -...
3
votes
1answer
299 views

Alias for sudo then ssh

I am looking to write an alias for the following two command: sudo su - user ssh somewhere I've tried alias jump='sudo su - user; ssh ' and then use this as jump somewhere but this doesn't work....
3
votes
0answers
311 views

Can I create aliases with make?

Is it possible for make to create aliases? Here's what I tried: Makefile aliases: alias hello='echo world' alias holy='echo cow' It doesn't work as-is, presumably because the alias command ...
2
votes
1answer
63 views

Automatically list contents of directory when changing to it

I am a huge fan of the ~/.bash_aliases file and I am trying to get the cd command to automatically list the contents of a directory when I change to it. In my .bash_aliases file, I put alias cd='cd $...
2
votes
1answer
96 views

How to correctly do the aliasing for whois

I'm trying to get this alias to work. alias awhois='whois -h whois.cymru.com " -v $1"' But bash doesn't give the same output. # awhois 8.8.8.8 Error: no ASN or IP match on line 1. AS | IP ...
-1
votes
1answer
284 views

cd displays the list of files and folders in macOS

Recently I have updated macOS and Terminal and below is the details macOS Sierra 10.12.6 Command Line Tool Version 9.0 Now whenever I run cd in the Terminal it navigated to that directory and ...
1
vote
1answer
55 views

How does bash alias understand “$@”?

I am trying to write an alias to do 2 things $alias cde='cd "$@" && echo' but for some reason when I call it with $cde test test all that happens is it echos test: It looks like my ...
8
votes
6answers
2k views

Creating alias for Trash

I am a newbie. I set an alias in .bashrc file as follow. alias myrm='mv /home/user/Trash/*' The purpose is that when I use myrm comment, for example $myrm foo, the file "foo" has to be moved to the ...
2
votes
3answers
600 views

How to append a string to a bash command line?

I am sure this is a recurrent question but I failed to find one that had an answer that would fit my problem. What I want to do is something like this: alias disexit = " & disown & exit" ...
9
votes
2answers
3k views

Alias does not “override” PATH entries?

The last line of my .bash_profile is: alias cp=/usr/local/bin/gcp However that is being squashed by the entry in my $PATH : $which cp /bin/cp 11:54:32/OCspark $type cp cp is aliased to `/usr/local/...
5
votes
1answer
3k views

Using alias to echo backticks in bash

Apologies if this is answered elsewhere, I could not for the life of me find a solution to my particular case, which is a bit strange I admit. (Note: all the “Using” words in this post appear blue for ...
0
votes
1answer
111 views

How to create custom alias for gnuwin32 tools in Windows Powershell

I have gnuwin32 installed and appended to my environment so I run linux/unix "ls" when I type ls in the command prompt. That's not a problem for Powershell, apparently, but I'm not being able to ...
20
votes
1answer
8k views

Bash is slow to start because of this line in .bashrc. What could cause this?

My .bashrc file contains a line to this effect: alias prog="/path/to/script.sh $(find $(pwd) -name prog)" When I comment out this line, Bash starts almost instantly when I open a new terminal. With ...
8
votes
2answers
658 views

Can I make bash stop parsing and validating a certain alias?

I'm using Fedora 25, and have added the following alias to my bash profile: alias releasenotes="dnf updateinfo --refresh info `dnf check-update | cut -d '.' -f 1 | xargs` | less" (I can't use ...
82
votes
3answers
5k views

How to unalias a minus?

My morning coffee hadn't reached my brain yet when I forgot the quotes in: alias grep="grep --color=always" so instead I typed: alias grep=grep --color=always leaving me with: --color=always grep=...
2
votes
0answers
821 views

How to chain a command after sudo su?

The idea is simple, for example: alias foo='sudo su foo && cd /tmp' However, it does not execute commands after switching users. In this case, it switches users but does not cd into /tmp.
0
votes
2answers
92 views

Bash profile commands with multiple "'` issues

Good day! I'm currently trying to get the following alias to work. 'git_fetch' and 'git_tree' are custom alias so dont worry about them. alias git_workspace='osascript -e 'tell application "Terminal"...
1
vote
3answers
397 views

Want to prevent accidental shutdowns, reboot, etc by aliasing commands such as shutdown

I am trying to alias commands such as shutdown, reboot, etc. I am aware that this is not a fool proof way to block access, however this is just to prevent accidental execution. I have looked at ...
0
votes
1answer
1k views

Is it possible to setup bash aliases that work in conemu as they do in cygwin?

So I have conemu setup to use cygwin as my shell and have it using the specified home directory I setup in my .bashrc file in /home of my cygwin directory. Here is what I have setup in the ...
3
votes
1answer
7k views

Windows 10 Ubuntu Bash: Aliases not working (: command not found)

I started the Ubuntu bash on Windows that was shipped with the Anniversary Update 1607. This bash sources the .bashrc file located at /home/phil which is the home directory of the Unix user, not the ...
0
votes
0answers
446 views

how to shorten git to g by using a alias

I am running git 2.7.2.windows.1 and I have edited my .bashrc file to have this line alias g='git' but when I type g status I get an error bash: g: command not found I even tried editing my global ...
0
votes
1answer
63 views

Alias to attempt mounting multiple times doesn't work correctly

I have the following in my .bashrc alias ext='sudo mount /dev/sd'{b..d}'1 /ext/hdd || sudo' I intended the alias to mount my external hard drive without having to worry about the semi-random ...
1
vote
1answer
984 views

Why are spaces not allowed while setting up aliases in .bashrc

Coming from the Windows world, I tend to type cls to clear the console. I wanted to set up an alias so cls would still work. I read an article online that mentioned you cannot have spaces between the ...
2
votes
1answer
169 views

Bash alias/function to precede every “git diff” with “clear”

Every time I do git diff I'd like my bash to do clear & git diff instead. I tried to tweak an answer at "Bash: Spaces in alias name" like this: git() { if [[ $@ == "diff" ]]; then ...
0
votes
1answer
2k views

Bash autocomplete behaviour in Debian 8

On a new install of Debian 8 (Jessie) I have found that the autocompletion in bash, using the tab key, has changed. The test I did was: Open a terminal (in my case Konsole). Above the prompt it ...
0
votes
1answer
279 views

Is there a standard place to put my Aliases? bashhrc vs. bash_aliases

Is there a standard place to put custom aliases? If not, what are the benefits and disadvantages of .bash_aliases, .bashhrc, and .bash_profile?
0
votes
1answer
61 views

Distribute session-only git configuration on ssh login

I have a bunch of development servers (linux) that I connect to via SSH from linux workstation. On most of these servers I want to use the Git command line interface. I use a set of Git aliases that I ...
1
vote
0answers
93 views

How to automatically log-in to remote MySQL instance via ssh behind another host?

I have an alias set up to ssh to a remote machine through a proxy ... alias sshcmd='ssh -t davea@proxy ssh destmachine' but I want to set up an alias where I ssh into the remote machine and then ...
2
votes
2answers
91 views

One-line code in bashrc to edit pdf

I would like to have a one-line code in bashrc, for removing the first page of a pdf. The command to be typed in the bash prompt could of the form: cut name.pdf This command should remove the ...
0
votes
1answer
1k views

Alias to connect to AWS instance via SSH not working

I made an alias to make it easier to connect to my AWS EC2 instance. Although there is an error. Here is the code in ~/.bash_profile: alias aws_connect=‘ssh -i /path/to/keyfile.pem ec2-user@xx.xxx....
0
votes
1answer
82 views

exiting current terminal in a script

I have made alias for running certain program and i have put it in .bashrc file. I want to close current terminal inside the script. I've tried this but it is not working. alias mp='java -jar ...
-1
votes
1answer
897 views

how to escape '$' in an awk statement in shell alias

I'm trying to write an alias that will kill all running php processes.. this is the command i got in my ~/.bash_profile alias killphp="ps aux | g [p]hp | awk '{print $3}' | xargs kill -9" this ...
0
votes
1answer
533 views

Alias not working

I have an alias that does an ssh into a machine and executes 1 line of code as following: alias posts-update= 'ssh user@host.com "cd /var/www/blog/posts && git pull"' This works perfectly if ...
2
votes
2answers
3k views

Sudo doesn't work on Aliases [duplicate]

I have added alias ll='ls -la' in /etc/bash.bashrc but sudo ll is not working. Is there a way to "source" bash.bashrc? In a related post, another user suggesting creating an alias for sudo with a ...
0
votes
1answer
91 views

Trouble 'generating' bash aliases

In my ~/.shortcuts, I have symlinks to some frequently used directories. In .bashrc (OS X), I am doing this: ls -1 ~/.shortcuts | xargs -I {} alias {}="'cd -P ~/.shortcuts/{}'" When I run alias in ...
0
votes
2answers
1k views

Run bash_aliases on start

I have a separate file .bash_aliases , in the same directory as .bashrc, that I wish to be ran on start, I've added the lines: if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi to my .bashrc ...