Monday, May 13, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 421  / 3 Years ago, mon, august 23, 2021, 2:31:26

I have a long path to some of my files and I don't want to type and/or use the Tab-key as much when using it with commands in the Terminal.

So I want to add "shortcuts" to some of them (both files and directories), e.g.



replace

ls folder1/folder2/folder3/folder4/


with something like

ls folder1234



and



replace

cat folder1/folder2/folder3/folder4/my_super_very_long_amazing_filename.txt


with something like

cat long_path_and_filename.txt (but obviously shorter :))


or if it's not possible, then with two "replace commands" like

cat folder1234/short_filename



Are any of the above possible?

Can you use the ln command or maybe the alias command?


More From » command-line

 Answers
1

Something fulfilling what you believe would work best


One way to create "shortcuts" for pathnames would be to define environment variables:


export folder1234='folder1/folder2/folder3/folder4'
export short_filename='my_super_very_long_amazing_filename.txt'

This way, you could reduce your typing to


ls $folder1234
cat $folder1234/$short_filename

While that sounds like a magnificent idea, nobody appears to do that. It indeed requires you to set up and maintain static definitions, and remember all of these artifacts. These will work the period you work on a project, but will be largely obsolete once you move to a different project.


The better workflow using standard tools


The better way to avoid long path names, is to turn into a habbit of changing to the directory where you need to do your work. This way, it takes a single


cd folder1/folder2/folder3/folder4/

(where you use autocompletion and tab) to bring you there. Next day, you will get there more quickly: instead of attempting the command again, type Ctrl+r: this starts a reverse search through your history. Type folder4 and you will quickly see your cd command again. Select it and execute it. Done.


Once inside that folder, typing the long filename is a no-brainer using the tab autocompletion.


On steroids


Install fuzzy finder. sudo apt install fzf


At the empty prompt, hit Alt+c. Fuzzy finder will pop up. Type folder4: you will see the full folder name, select it, hit enter and you are there.


Type cat then Ctrl+t. my_super_very may already reveal your file only. Hit enter to add the full path to the command line.


Alternative to the above: type ** then Tab to trigger fussy finder.


[#863] Monday, August 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eaderitable

Total Points: 368
Total Questions: 117
Total Answers: 111

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
eaderitable questions
Tue, May 24, 22, 07:37, 2 Years ago
Thu, Mar 2, 23, 23:23, 1 Year ago
Wed, Apr 6, 22, 13:20, 2 Years ago
Tue, Dec 14, 21, 16:57, 2 Years ago
Sat, Apr 30, 22, 09:06, 2 Years ago
;