I've created a custom copy function to help me manage file paths more easily. Sometimes, I need to copy files to a directory that has a really long path. Instead of typing out that lengthy path every time I use the 'cp' command, I made a clipboard folder and a corresponding paste function. The workflow goes like this: I'll use 'pushd' to navigate to the long-path directory, copy the desired file or folder, then 'popd' back to my original location and finally paste the file in my current directory. While it's a series of short commands, it feels like a lot of operations. Am I overcomplicating things?
7 Answers
If you're already in your destination directory, why not just use relative paths? For example, if you're in `/some/long/path/that/is/file/destination/`, just use `cp /some/file ./`
Have you tried using the "tab" key for auto-completion? It can save you a lot of typing.
No, I hadn't thought of that! Thanks for the tip.
Just a thought: if you're in a long path, consider using `cd` with a shortcut to make it faster to navigate around. It could simplify your process even more!
How about using `cd` in combination with other commands like `oldpwd` to switch back quickly?
Reading up on bash keyboard shortcuts can really streamline your workflow. For instance, `alt-.` puts the last argument from the previous command, and `!!` re-runs the last command. You should definitely explore these options!
I don't see how that's relevant to copying files between directories.
Also, remember that if tab completion stops, tapping it again can reveal more options.
Honestly, if your function works for you and saves time, that's what matters. We all have our own ways of doing things, and if it suits your style, go for it!
If it serves a purpose and helps you save time, it's not silly at all! Sounds like a clever solution to me.
Another option is to store the long path in a variable, switch directories, and then use that variable for copying. You could set up a stack for copy-paste actions right in your bashrc. It might take some setup, but it could be worth it!
You could also just use `realpath .` or `pwd` to quickly grab your current directory's path.

Well, I made it this way because I never know if the source or destination will be long or not. Sometimes I use an alias to return to long paths, but I can’t use that in a cp command.