Today’s article should be a fairly short article, where I take the chance to show you how to move a file to multiple directories – at the same time. It’s a pretty simple process, albeit a bit weird. If you want to move files to multiple directories, this is the article for you!
I’ve done a lot of articles about file management. This is another one. We usually manage files in the terminal here on Linux Tips. We’ll be doing that again this time around. We’ll be managing files in the terminal!
The tool we’ll be using is the tee command. I covered that recently.
The task we’ll be doing is showing you how to move a file to multiple directories – at the same time and in the Linux terminal. It’s a pretty handy skill to have, though there’s some tee weirdness along the way.
Move A File To Multiple Directories:
You’ll need an open terminal for this, as the intro suggested. You can find a terminal application in your GUI file manager. You can often open your default terminal by pressing
With your terminal open, let’s just run through some exercises to ensure we’re all on the same page and ready to move a file.
First, let’s make a directory:
1 | mkdir temp |
Next, let’s move to that directory:
1 | cd temp |
Next, let’s make that file that we’ll copy to multiple directories:
1 | touch foo |
I suppose we’ll need a few folders next, so let’s create them:
1 | mkdir one two three |
Now, let’s move the file foo to multiple directories:
1 | tee ./one/foo ./two/foo ./three/foo & |
The syntax is:
1 | tee <directory>/<file_name> <directory>/<file_name> <directory>/<file_name> & |
We throw the & in so that the tee command doesn’t hang, awaiting further input. You’ll get an extra message or two, but that’s fine and can be ignored.
Now, we can verify them:
1 | cd one |
The following command will show you that the file exists:
1 | ls |
That should show the file, like so:
1 2 | $ ls foo |
Now, you can check the other folders.
1 | cd ../two && ls |
And, of course:
1 | cd ../three && ls |
Each of those should show you that the foo file exists in each directory.
Now, we can clean up after ourselves with this command:
1 | cd ../.. && rm -rf temp |
Tada! Now there shouldn’t be any remains left behind and we’ve covered how to move a file to multiple directories at the same time and in the Linux terminal.
Pretty easy and pretty short!
Closure:
You never know when you’ll want to move a file to multiple directories but now you know how to do so. It isn’t a very difficult exercise, warranting only a short article. This seemed like good fodder for a short article and a handy tip to share with my readers.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
Last Updated on April 12, 2024 by KGIII