How to open a folder in linux via terminal? [closed]

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

6

5 Answers

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
1

./ 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)

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 :)

2

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.

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

You Might Also Like