How to enter directory/folder in Linux without using CD command

How to enter directory/folder in Linux without using CD command

As we all know, without the cd command, we cannot switch directories in Linux. That's true, but we have a built-in Linux command called shopt that can help us solve this problem.

shopt is a shell builtin command that is used to set and unset various bash shell options, and since it is already installed, we do not need to install it again.

Yes, we can switch directories without using cd command after enabling this option.

We’ll show you how in this article. It's a small tweak, but very useful for those new to Linux who are migrating from Windows.

This is not useful for Linux administrators because we will not change to that directory without cd command as we are experienced with it.

If you try to switch directories/folders in Linux without the cd command, you will see the following error message. This is very common in Linux.

$ Documents/
bash: Documents/: Is a directory

To do this, we need to append the following value in the user .bashrc.

What is .bashrc ?

.bashrc is a shell script that is run every time a user opens a new shell in interactive mode.

You can add any commands you would enter at the command prompt in this file.

The .bashrc file itself contains a series of configurations for the terminal session. Includes setting up and enabling: coloring, completion, shell history, command aliases, etc.

$ vi ~/.bashrc

Add this line:

shopt -s autocd

Run the following command for the changes to take effect.

$ source ~/.bashrc

We have completed all the configuration. Simply test this to confirm that this works.

$ Documents/
cd --Documents/
$ daygeek/
cd -- daygeek/
$ /home/daygeek/Documents/daygeek
cd -- /home/daygeek/Documents/daygeek
$ pwd
/home/daygeek/Documents/daygeek 

Yes, it works fine as expected.

Also, it works fine in fish shell without any changes to .bashrc.

If you want to do this temporarily, use the following commands (to set or unset). When you reboot the system, it will disappear.

# shopt -s autocd
# shopt | grep autocd
autocd on
# shopt -u autocd
# shopt | grep autocd
autocd off

shopt command provides many other options, if you want to verify those options, run the following command.

$ shopt
autocd on
assoc_expand_once off
cdable_vars off
cdspell on
checkhash off
checkjobs off
checkwinsize on
cmdhist on
compat31 off
compat32 off
compat40 off
compat41 off
compat42 off
compat43 off
compat44 off
complete_fullquote on
direxpand off
dirspell off
dotglob off
execfail off
expand_aliases on
extdebug off
extglob off
extquote on
failglob off
force_fignore on
globalbasciiranges on
globstar off
gnu_errfmt off
histappend on
histreedit off
histverify off
hostcomplete on
huponexit off
inherit_errexit off
interactive_comments on
lastpipe off
Lithist off
localvar_inherit off
localvar_unset off
login_shell off
mailwarn off
no_empty_cmd_completion off
nocaseglob off
nocasematch off
nullglob off
progcomp on
progcomp_alias off
promptvars on
restricted_shell off
shift_verbose off
sourcepath on
xpg_echo off

Besides, I found some other programs which can help us switch directories in Linux faster than cd command.

These are pushd, popd, the up shell script, and the bd tool. We will cover these topics in the following articles.

via: https://www.2daygeek.com/navigate-switch-directory-without-using-cd-command-in-linux/

Summarize

The above is the method I introduced to you on how to enter the directory/folder in Linux without using the CD command. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of Linux LCD driver writing
  • Detailed explanation of cd command usage in Linux
  • How to configure a CDN cache server using Squid reverse proxy in Linux
  • Build your own CDN with DNSPod and Squid (Part 3) Install CentOS Linux
  • How to reduce the use of cd command in Linux through autojump command

<<:  JavaScript implements page scrolling animation

>>:  Detailed graphic and text instructions for installing MySQL 5.7.20 on Mac OS

Recommend

MySQL data type selection principles

Table of contents Small but beautiful Keep it sim...

How to create, save, and load Docker images

There are three ways to create an image: creating...

Design Theory: Ten Tips for Content Presentation

<br /> Focusing on the three aspects of text...

MySQL trigger simple usage example

This article uses examples to illustrate the simp...

Detailed steps to install mysql5.7.18 on Mac

1. Tools We need two tools now: MySQL server (mys...

CSS uses radial-gradient to implement coupon styles

This article will introduce how to use radial-gra...

Understand the principle of page replacement algorithm through code examples

Page replacement algorithm: The essence is to mak...

How to use CSS style to vertically center the font in the table

The method of using CSS style to vertically cente...

JavaScript to achieve product magnifying glass effect

This article shares the specific code of JavaScri...

How to use Nginx to realize the coexistence of multiple containers in the server

background There is a Tencent Linux cloud host, o...

Summary of basic knowledge and operations of MySQL database

This article uses examples to explain the basic k...

CSS imitates Apple's smooth switch button effect

Table of contents 1. Code analysis 2. Source code...

js to achieve a simple carousel effect

This article shares the specific code of js to ac...