Is My Copy Function Actually Efficient?

0
17
Asked By CuriousCat123 On

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

Answered By WhatAboutPaths96 On

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

CuriousCat123 -

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.

Answered By TechieTim On

Have you tried using the "tab" key for auto-completion? It can save you a lot of typing.

CuriousCat123 -

No, I hadn't thought of that! Thanks for the tip.

Answered By FileFinder On

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!

CuriousCat123 -

How about using `cd` in combination with other commands like `oldpwd` to switch back quickly?

Answered By BashBuddy On

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!

ConfusedUser -

I don't see how that's relevant to copying files between directories.

HelpfulHarry -

Also, remember that if tab completion stops, tapping it again can reveal more options.

Answered By SillySally On

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!

Answered By EasyPeasy On

If it serves a purpose and helps you save time, it's not silly at all! Sounds like a clever solution to me.

Answered By VariableVictor On

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!

TechSavvySophie -

You could also just use `realpath .` or `pwd` to quickly grab your current directory's path.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.