How do I prevent 'cd' command from going to home directory?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.
e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory
command-line
New contributor
add a comment |Â
up vote
1
down vote
favorite
The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.
e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory
command-line
New contributor
2
If youcd
somewhere by accident, usecd -
to return to your previous location -- bash keeps the$OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
â glenn jackman
1 hour ago
1
If you truly wantcd
to do nothing, you can write a function namedcd
that does nothing when no arguments are given, otherwise callbuiltin cd "$@"
â glenn jackman
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.
e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory
command-line
New contributor
The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.
e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory
command-line
command-line
New contributor
New contributor
New contributor
asked 2 hours ago
vinicius de novaes
61
61
New contributor
New contributor
2
If youcd
somewhere by accident, usecd -
to return to your previous location -- bash keeps the$OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
â glenn jackman
1 hour ago
1
If you truly wantcd
to do nothing, you can write a function namedcd
that does nothing when no arguments are given, otherwise callbuiltin cd "$@"
â glenn jackman
1 hour ago
add a comment |Â
2
If youcd
somewhere by accident, usecd -
to return to your previous location -- bash keeps the$OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
â glenn jackman
1 hour ago
1
If you truly wantcd
to do nothing, you can write a function namedcd
that does nothing when no arguments are given, otherwise callbuiltin cd "$@"
â glenn jackman
1 hour ago
2
2
If you
cd
somewhere by accident, use cd -
to return to your previous location -- bash keeps the $OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cdâ glenn jackman
1 hour ago
If you
cd
somewhere by accident, use cd -
to return to your previous location -- bash keeps the $OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cdâ glenn jackman
1 hour ago
1
1
If you truly want
cd
to do nothing, you can write a function named cd
that does nothing when no arguments are given, otherwise call builtin cd "$@"
â glenn jackman
1 hour ago
If you truly want
cd
to do nothing, you can write a function named cd
that does nothing when no arguments are given, otherwise call builtin cd "$@"
â glenn jackman
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
Use gedit ~/.bashrc
and insert these lines at the bottom:
cd()
[[ $# -eq 0 ]] && return
builtin cd "$@"
Open a new terminal and now when you type cd
with no parameters you simply stay in the same directory.
add a comment |Â
up vote
1
down vote
Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -
, equivalent to cd $OLDPWD
is a better solution.
From my ~/.bashrc
:
# from the "xttitle(1)" man page - put info in window title
update_title()
[[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"
cd()
[[ -z "$*" ]] && builtin cd $HOME
[[ -n "$*" ]] && builtin cd "$*"
update_title
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Use gedit ~/.bashrc
and insert these lines at the bottom:
cd()
[[ $# -eq 0 ]] && return
builtin cd "$@"
Open a new terminal and now when you type cd
with no parameters you simply stay in the same directory.
add a comment |Â
up vote
2
down vote
Use gedit ~/.bashrc
and insert these lines at the bottom:
cd()
[[ $# -eq 0 ]] && return
builtin cd "$@"
Open a new terminal and now when you type cd
with no parameters you simply stay in the same directory.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Use gedit ~/.bashrc
and insert these lines at the bottom:
cd()
[[ $# -eq 0 ]] && return
builtin cd "$@"
Open a new terminal and now when you type cd
with no parameters you simply stay in the same directory.
Use gedit ~/.bashrc
and insert these lines at the bottom:
cd()
[[ $# -eq 0 ]] && return
builtin cd "$@"
Open a new terminal and now when you type cd
with no parameters you simply stay in the same directory.
answered 20 mins ago
WinEunuuchs2Unix
37.8k1060139
37.8k1060139
add a comment |Â
add a comment |Â
up vote
1
down vote
Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -
, equivalent to cd $OLDPWD
is a better solution.
From my ~/.bashrc
:
# from the "xttitle(1)" man page - put info in window title
update_title()
[[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"
cd()
[[ -z "$*" ]] && builtin cd $HOME
[[ -n "$*" ]] && builtin cd "$*"
update_title
add a comment |Â
up vote
1
down vote
Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -
, equivalent to cd $OLDPWD
is a better solution.
From my ~/.bashrc
:
# from the "xttitle(1)" man page - put info in window title
update_title()
[[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"
cd()
[[ -z "$*" ]] && builtin cd $HOME
[[ -n "$*" ]] && builtin cd "$*"
update_title
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -
, equivalent to cd $OLDPWD
is a better solution.
From my ~/.bashrc
:
# from the "xttitle(1)" man page - put info in window title
update_title()
[[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"
cd()
[[ -z "$*" ]] && builtin cd $HOME
[[ -n "$*" ]] && builtin cd "$*"
update_title
Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -
, equivalent to cd $OLDPWD
is a better solution.
From my ~/.bashrc
:
# from the "xttitle(1)" man page - put info in window title
update_title()
[[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"
cd()
[[ -z "$*" ]] && builtin cd $HOME
[[ -n "$*" ]] && builtin cd "$*"
update_title
answered 50 mins ago
waltinator
21.1k74168
21.1k74168
add a comment |Â
add a comment |Â
vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.
vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.
vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.
vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1086161%2fhow-do-i-prevent-cd-command-from-going-to-home-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
If you
cd
somewhere by accident, usecd -
to return to your previous location -- bash keeps the$OLDPWD
variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cdâ glenn jackman
1 hour ago
1
If you truly want
cd
to do nothing, you can write a function namedcd
that does nothing when no arguments are given, otherwise callbuiltin cd "$@"
â glenn jackman
1 hour ago