I created a shortcut via "make link" option. When I enter to this shortcut's folder I can't see any folders above it so I can't easily navigate to them.
Is there a way to go one folder up in the GUI? Maybe a hotkey? (Can't do cd ..
this time ^__^ ).
In Windows for example I am indeed able to navigate in the way I describe, here is a Win10 image that explains it:
Best Answer
Why this is a challenging question
The question has a few challenges:
nautilus
does not communicate directly from the command line, to get the currently active directory for example, nor can you "send" the currently opened folder (-window) to another directory from the command line."NAUTILUS_SCRIPT_CURRENT_URI"
, Nautilus does not return the real path to the current folder, but "sees" the link as if it was an actual folder.The solution therefore is as dirty as it gets; we need to find workarounds. Below four options to solve the issue.
1. right- click to go one level up
To get the real path to the current directory, we have to retrieve information from the link. We can do that either by using
ls -l
on the link, which will output e.g.:where the section after
->
is the real path inside the symlink, or, usingpython
:Using this in a
nautilus
script, we can indirectly get the real path to the current file or folder.Then if we have the path, how do we make nautilus move one level up?
Again, we cannot solve this and keep our hands clean. To move one level up, we first edit the found path a bit, from:
into
then, using
xdotool
to simulate Ctrl+L (the GUI shortcut to insert a path into a nautilus window, since there is no cli option to move to another directory using the current window), and subsequently makexclip
paste the edited path + Enter, we have a working solution!In practice
We are in a folder, opened from a link ("Link to Telegram") on my Desktop. The real folder is a sub folder of my
Downloads
folder:Then if we right- click on any of the files inside the folder to run the script:
Automatically, the path to the superior directory is inserted:
And, also automatically, Return is pressed, and we move one directory level up:
The script
How to set up
The script needs both
xdotool
andxclip
:create, if it doesn't exist already, the directory
Copy the script above into an empty file, save it as
level_up
(no extension) in~/.local/share/nautilus/scripts
, and make it executableNow you should be able to run the script by right- click on a file (any) > scripts > level_up:
[EDIT] I changed the script above to paste the path into the
nautilus
window, instead of makingxdotool
type it. Itneeds
xclip
to be installed, but it is a major improvement, especially on very long paths.2. Alternatively, open a new nautilus window in the superior directory
You could avoid using
xdotool
, by making the script open a new nautilus window, in the parent's directory. The script would then be even shorter:In this case, you wouldn't need to install
xdotool
. We could even extend the script by closing the original window and placing the new window exactly in the same position (& size).The downside is that the history of the original window is lost this way.
3. An additional solution: alternative way to (automatically) create links
Not relevant to existing links, but when used from the GUI, a nautilus script to automatically create executable
.desktop
files on right-click might be helpful:right-click on the directory to create a shortcut (behaving as a link)
Unlike symlinks, these links will take you to the actual folder, without behaving as a folder itself:
The script
How to use
make_link
(no extension) in~/.local/share/nautilus/scripts
, and make it executable.desktop
file will be created in the same directory, move it elsewhere if you need to; the linked path is absolute.Give the link an distinguishing icon
You could give the alternative link a distinguishing icon. If you search inside the directory
/usr/share/icons
for "folder", numerous valid options pop up.If in the script the line
"Icon=folder",
is replaced byIcon=stock_folder-copy,
(use the icon name without extension), the result on my system is:Of course you can use your own custom icon as well, but if you use full paths (don't use
~
), you should include the icon's extension.4. Move to the superior directory with a short cut key
Probably the most convenient option; with the nautilus window in front, press a short cut key to move one directory up.
The script
To use
For this solution, both
xclip
andxdotool
Need to be on your system.Copy the script into an empty file, save it as
level_up.py
(anywhere).Add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
NB The shortcut options are a bit limited in this case, since the script itself will simulate Ctrl+L, and Ctrl+Alt+L will make you log out... Ctrl+\ worked fine on my system.
Explanation
This script also simulates Ctrl+L, but instead of using nautilus'
"NAUTILUS_SCRIPT_CURRENT_URI"
, it usesxclip
to copy the automatically selected path in the nautilus window. Like option 1, the script then calculates the real path and derives the superior directory.This option might be useful if you prefer the keyboard to using right- click.