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

Summary of practical skills commonly used in Vue projects

Table of contents Preface 1. Use $attrs and $list...

Solution to transparent font problem after turning on ClearType in IE

The solution to the transparent font problem after...

Implementing Binary Search Tree in JavaScript

The search binary tree implementation in JavaScri...

A brief explanation of the reasonable application of table and div in page design

At the beginning of this article, I would like to ...

CSS3 realizes the mask barrage function

Recently I saw a barrage effect on B station call...

Steps for Docker to build a private warehouse Harbor

Harbor Harbor is an open source solution for buil...

How to display small icons in the browser title bar of HTML webpage

Just like this effect, the method is also very si...

Introduction to the use of html base tag target=_parent

The <base> tag specifies the default address...

How to set background blur with CSS

When making some pages, in order to make the page...

Vue Beginner's Guide: Environment Building and Getting Started

Table of contents Initial Vue Building a Vue deve...

3D tunnel effect implemented by CSS3

The effect achievedImplementation Code html <d...

Weather icon animation effect implemented by CSS3

Achieve results Implementation Code html <div ...