Reputation: 12796
Does linux have commands allow me to push my regularly used commands into a stack or something so that I can easily fetch them from it and jump among the most frequently used commands as much as I want.
I know we can create alias for commands, but that's not what I am looking for here. My case is more like I have a few horrible long directories, I need to be able to switch between them quickly and frequently. eg.
cd /pathA/pathB/pathC/pathD/
cd /pathE/pathF/pathG/pathH/
vim /pathA/pathB/pathC/pathD/test.txt
.......
I don't really want to create alias for each command here because the paths vary quite often as well, I don't want to constantly update my alias.
Upvotes: 2
Views: 944
Reputation: 200
If you feel the command will be used frequently you could add a tag
command #useful
Then
[ctrl+r]
#useful
Upvotes: 1
Reputation: 5034
Also check out the CDPATH variable, that can hold a list of common directories that you want to jump into - eg :
export CDPATH=/pathA/pathB/pathC
cd pathD
# now you're at /pathA/pathB/pathC/pathD
Upvotes: 1
Reputation: 143082
Well, there's the history feature of your shell that would allow you to recall previous commands.
A quick command for going back and forth between the last 2 directories is
cd -
As far as more directories are concerned, I use this set of aliases in my .tcshrc
to keep track of them. If I am in a directory I want to remember I just say
keep
or
keep2
and then later I can get back there by simply typing
cd $k
or
cd $k2
If I want to see the directories I have "saved" I type
ks
I can also use these variable for other operations such as cp/mv
(and quite frequently this is what I do to save on typing long path names).
You didn't specify your shell, so this is using the tcsh
but could be easily adapted to any other shell as long as you know how to set up equivalent aliases. This allows me to save up to 6 different directories, you can decide how many you set up.
This is my own "homegrown" solution that has served me well for the last 10+ years, there might be others, perhaps "built-in". At this point I use these automatically and so regularly that I don't even think of them as aliases.
alias keep 'set k=`pwd`'
alias keep2 'set k2=`pwd`'
alias keep3 'set k3=`pwd`'
alias keep4 'set k4=`pwd`'
alias keep5 'set k5=`pwd`'
alias keep6 'set k6=`pwd`'
alias ks 'echo $k; echo $k2; echo $k3; echo $k4; echo $k5; echo $k6'
Upvotes: 2
Reputation: 3990
Write your 'long path' once and fetch it next time by pressing "Ctrl + r"
.
You need to press "Ctrl + r"
first. Then start typing your 'long path' it will start showing you the path you have already typed.
To find existence of more old records (of the same text you have typed) keep pressing "Ctrl + r"
and it will show you the old records.
Upvotes: 1
Reputation: 5147
Regarding directories, you can push the paths on stack
pushd path_you_want_to_store
popd
Upvotes: 3