34

How can I open a folder in a dir?

say I change my current directory to: cd /root/dir/

then I list all the files there: ls folder1 folder2 folder3

Now I want to open folder1. If I try the "./" I get: ./folder1 bash: ./folder1: Is a directory

How can I do so without having to type cd again ie: cd $(pdw)/folder1

  • 1
    just type cd folder1 – Avinash Raj May 11 '14 at 13:00
  • If you want to change directory you should use cd folder1. you used ./folder1 it wont work './' is used to execute an executable file but folder is a directory. – Sudheer May 11 '14 at 13:02
  • 2
    @user280447 : Mention exact method that you want to open (CLI or GUI) and Linux os: Ubuntu or other? – Pandya May 11 '14 at 13:08
  • 3
    What do you mean by "open" it? List the contents? Open it in graphical file manager? – terdon May 11 '14 at 13:16
  • 3
    xdg-open ./folder1 – user.dz May 12 '14 at 4:03
36

If you want to open the folder via the nautilus file manager, you can move to the wanted directory like you've mentioned cd /root/dir/ , check the folders under that path using ls and then if you want to open folder1 type:

nautilus folder1
| improve this answer | |
  • 3
    I'm on debian and it's nemo instead of nautilus for me – Barry McNamara Aug 29 '19 at 16:52
15

./ is used to execute file (Not to open directory).

(In)CLI Method: You can open folder in terminal by cd folder1 or dir folder1 or ls folder1.

(To)GUI Method: If you want to open with file-manager (ex:nautilus) then typenautilus folder1 (for Ubuntu nautilus is default file-manager)

| improve this answer | |
7

I have found that simply typing gnome-open "any-oject" opens any folder or file in the default program on Ubuntu. If this happens to be a folder, it uses your default folder-explorer :)

| improve this answer | |
  • gnome-open /path works for Redhat (RHEL) as well. – Ivan Chau Aug 22 '17 at 4:06
  • kd-open /path is the equivalent for Kubuntu. – BrianD Jul 1 '18 at 14:25
3

zsh shell can do that with the AUTO_CD option.

bob@tp ~ % setopt AUTO_CD
bob@tp ~ %
bob@tp ~ % ./Documents
bob@tp ~/Documents % 
bob@tp ~/Documents % pwd
/home/bob/Documents 

Just put setopt AUTO_CD in your .zshrc file (start zsh one time first to create the zsh environment files). You can invoke directly zsh at the terminal prompt to start a zsh session or you can change your default shell to be zsh with the chsh command.

Btw this is not a strange feature, crossable directories do have the "execute" attribute so it makes sense to able to execute a directory like any standard commands.

| improve this answer | |
1

You could specify the directory using ls, it will give you a list of that contents without moving from your directory

ls -al /path/to/directory
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.