2022 Developer Survey is open! Take survey.

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
0 votes
1 answer
23 views

Aliases for going to directory of a file and executing command in that directory

I am trying to write two command aliases one to take a file not directory path and cd into its directory. My attempt below is. alias godir='cd $(dirname $1)' however this leads to bash cd: {file path}...
user avatar
  • 338
0 votes
2 answers
30 views

Bash recognizes function argument as a program

I'm pretty new to the syntax of bash and I have a piece of code in my '.bash_aliases' file. It either gets an integer as an argument or the letter 'c', when it gets an integer, it puts that integer in ...
user avatar
2 votes
1 answer
296 views

How to use alias inside another alias in ZSH?

Let's say I have the following alias definition in my ZSH config file: alias myalias="cd /" how can I use myalias inside another alias? ie: alias myaliasone="myalias && cd /usr&...
user avatar
  • 321
0 votes
1 answer
23 views

Can no longer open terminal after editing my bash_aliases

I edited my bash_aliases to have a new alias (stars block out my email for privacy sake): alias t_cluster="u*******@notchpeak.chpc.utah.edu" I then mistakenly added this to my bash_aliases (...
user avatar
1 vote
2 answers
68 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 ...
user avatar
  • 219
0 votes
0 answers
167 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 ...
user avatar
0 votes
1 answer
28 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 ...
user avatar
  • 107
0 votes
1 answer
129 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? ...
user avatar
2 votes
1 answer
3k 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,...
user avatar
  • 10.3k
1 vote
1 answer
192 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 ....
user avatar
0 votes
3 answers
100 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. ...
user avatar
0 votes
1 answer
93 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 ...
user avatar
3 votes
3 answers
484 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). ...
user avatar
0 votes
1 answer
77 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. ...
user avatar
  • 103
5 votes
4 answers
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 ...
user avatar
  • 239
0 votes
1 answer
196 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 ...
user avatar
1 vote
1 answer
2k 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 -...
user avatar
3 votes
1 answer
391 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....
user avatar
  • 173
4 votes
0 answers
608 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 ...
user avatar
  • 141
2 votes
1 answer
64 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 $...
user avatar
2 votes
1 answer
115 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 ...
user avatar
  • 23
-1 votes
1 answer
357 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 ...
user avatar
  • 219
1 vote
1 answer
59 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 ...
user avatar
8 votes
6 answers
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 ...
user avatar
2 votes
3 answers
649 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" ...
user avatar
10 votes
2 answers
4k 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/...
user avatar
5 votes
1 answer
4k 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 ...
user avatar
  • 153
0 votes
1 answer
132 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 ...
user avatar
  • 145
20 votes
1 answer
9k 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 ...
user avatar
  • 303
8 votes
2 answers
685 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 ...
user avatar
  • 333
83 votes
3 answers
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=...
user avatar
  • 930
2 votes
0 answers
921 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.
user avatar
0 votes
2 answers
102 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"...
user avatar
1 vote
3 answers
432 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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
4 votes
1 answer
8k 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 ...
user avatar
  • 1,704
0 votes
0 answers
453 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 ...
user avatar
  • 153
0 votes
1 answer
71 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 ...
user avatar
1 vote
1 answer
1k 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 ...
user avatar
  • 113
2 votes
1 answer
179 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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
0 votes
1 answer
298 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?
user avatar
  • 253
0 votes
1 answer
63 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 ...
user avatar
  • 1
1 vote
0 answers
95 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 ...
user avatar
  • 25
2 votes
2 answers
93 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 ...
user avatar
  • 21
0 votes
1 answer
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....
user avatar
0 votes
1 answer
85 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 ...
user avatar
  • 103
-1 votes
1 answer
970 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 ...
user avatar
  • 1,052
0 votes
1 answer
548 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 ...
user avatar
2 votes
2 answers
4k 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 ...
user avatar
  • 315