I am not a frequent Linux user, and really only use it for servers. I'm wondering if there would be an easy way to make the command "cd.." work as it does in Windows (going up one directory), I understand that the proper way to do this in general is to use "cd .." but when it comes down to muscle memory I find myself doing the former all the time before my brain kicks in and reminds me that it should be the latter.
I have tried creating a file at /bin/cd.. with the following contents:
#!/bin/bash
cd ../
But upon executing it does nothing, not really sure what I did wrong here so if anyone has some guidance it would be appreciated.
Thanks!
CodePudding user response:
A cd
command in a shell script does nothing to the invoking shell - that's a feature. You need to run the command in the context of the current shell, and that's what aliases are for.
Put alias "cd.."="cd .."
into your .bashrc
, that should to the trick.
CodePudding user response:
Add the alias to your bash profile at $HOME/.bash_profile
. You likely will need to restart your terminal session for the profile to be loaded. It will be there from that point forward. The $HOME/.bashrc
may not get you what you want, that is for non-interactive sessions.
# $HOME/.bash_profile
alias cd..='cd ..'
# Some other handy ones?
alias ..='cd ..'
alias ../..='cd ../..'
CodePudding user response:
Try sourcing that file
/tmp/other $ source ~/mycd.sh
/tmp $