Move all files to one folder linux

How to Move Files Using Linux Commands or File Managers

Learn how to move files with Linux commands in this tutorial from our archives.

There are certain tasks that are done so often, users take for granted just how simple they are. But then, you migrate to a new platform and those same simple tasks begin to require a small portion of your brain’s power to complete. One such task is moving files from one location to another. Sure, it’s most often considered one of the more rudimentary actions to be done on a computer. When you move to the Linux platform, however, you may find yourself asking “Now, how do I move files?”

If you’re familiar with Linux, you know there are always many routes to the same success. Moving files is no exception. You can opt for the power of the command line or the simplicity of the GUI – either way, you will get those files moved.

Let’s examine just how you can move those files about. First we’ll examine the command line.

Command line moving

One of the issues so many users, new to Linux, face is the idea of having to use the command line. It can be somewhat daunting at first. Although modern Linux interfaces can help to ensure you rarely have to use this “old school” tool, there is a great deal of power you would be missing if you ignored it all together. The command for moving files is a perfect illustration of this.

The command to move files is mv . It’s very simple and one of the first commands you will learn on the platform. Instead of just listing out the syntax and the usual switches for the command – and then allowing you to do the rest – let’s walk through how you can make use of this tool.

The mv command does one thing – it moves a file from one location to another. This can be somewhat misleading, because mv is also used to rename files. How? Simple. Here’s an example. Say you have the file testfile in /home/jack/ and you want to rename it to testfile2 (while keeping it in the same location). To do this, you would use the mv command like so:

mv /home/jack/testfile /home/jack/testfile2

or, if you’re already within /home/jack:

mv testfile testfile2

The above commands would move /home/jack/testfile to /home/jack/testfile2 – effectively renaming the file. But what if you simply wanted to move the file? Say you want to keep your home directory (in this case /home/jack) free from stray files. You could move that testfile into /home/jack/Documents with the command:

mv /home/jack/testfile /home/jack/Documents/

With the above command, you have relocated the file into a new location, while retaining the original file name.

What if you have a number of files you want to move? Luckily, you don’t have to issue the mv command for every file. You can use wildcards to help you out. Here’s an example:

You have a number of .mp3 files in your

/ – is an easy way to represent your home directory – in our earlier example, that would be /home/jack/) and you want them in

/Music. You could quickly move them with a single command, like so:

That command would move every file that ended in .mp3 from the Downloads directory, and move them into the Music directory.

Should you want to move a file into the parent directory of the current working directory, there’s an easy way to do that. Say you have the file testfile located in

/Downloads and you want it in your home directory. If you are currently in the

/Downloads directory, you can move it up one folder (to

Читайте также:  Добавление переменной среды windows 10 через командную строку

The “../” means to move the folder up one level. If you’re buried deeper, say

/Downloads/today/, you can still easily move that file with:

Just remember, each “../” represents one level up.

As you can see, moving files from the command line, isn’t difficult at all.

There are a lot of GUIs available for the Linux platform. On top of that, there are a lot of file managers you can use. The most popular file managers are Nautilus (GNOME) and Dolphin (KDE). Both are very powerful and flexible. I want to illustrate how files are moved using the Nautilus file manager (on the Ubuntu 13.10 distribution, with Unity as the interface).

Nautilus has probably the most efficient means of moving files about. Here’s how it’s done:

Open up the Nautilus file manager.

Locate the file you want to move and right-click said file.

From the pop-up menu (Figure 1) select the “Move To” option.

When the Select Destination window opens, navigate to the new location for the file.

Once you’ve located the destination folder, click Select.

This context menu also allows you to copy the file to a new location, move the file to the Trash, and more.

If you’re more of a drag and drop kind of person, fear not – Nautilus is ready to serve. Let’s say you have a file in your home directory and you want to drag it to Documents. By default, Nautilus will have a few bookmarks in the left pane of the window. You can drag the file into the Document bookmark without having to open a second Nautilus window. Simply click, hold, and drag the file from the main viewing pane to the Documents bookmark.

If, however, the destination for that file is not listed in your bookmarks (or doesn’t appear in the current main viewing pane), you’ll need to open up a second Nautilus window. Side by side, you can then drag the file from the source folder in the original window to the the destination folder in the second window.

If you need to move multiple files, you’re still in luck. Similar to nearly every modern user interface, you can do multi-select of files by holding down the Ctrl button as you click each file. After you have selected each file (Figure 2), you can either right-click one of the selected files and the choose the Move To option, or just drag and drop them into a new location.

The selected files (in this case, folders) will each be highlighted.

Moving files on the Linux desktop is incredibly easy. Either with the command line or your desktop of choice, you have numerous routes to success – all of which are user-friendly and quick to master.

Источник

Move all files with a certain extension from multiple subdirectories into one directory

I have a bunch of .zip files in several directories:

How would I do move them all to a common base folder?

7 Answers 7

Go to the toplevel directory of the tree containing the zip files ( cd … ), then run

This works out of the box in zsh. If your shell is bash, you’ll need to run shopt -s globstar first (you can and should put this command in your

/.bashrc ). If your shell is ksh, you’ll need to run set -o globstar first (put it in your

Alternatively, use find , which works everywhere with no special preparation but is more complicated:

If you want to remove empty directories afterwards, in zsh:

and repeat as long as there are empty directories to remove. Alternatively, in any shell

If you only want to move the .zip files, you could do something like

If you’re using bash version 4 or higher or zsh you can also use recursive globbing:

This will move ONLY the files and not their relative paths, so collisions might occur.

This one is safe when moving data and error free which supported most of all distro regardless versions. This command will scan subdirectories and then move or copy to your new destination directory.

  • Run this command at the main directory that contains sub-directories with the files you wish to move.
  • Where you can change *.flac to anything like *.zip in your case. Or *.doc just any extension works.
  • and mv is the command to move files, or you can use cp to copy data instead of moving.
  • ./flac/ is the destination directory that I want to move all FLAC files to. You can also give it a full path like /home/myid/flac/
Читайте также:  Portrait pro ��� mac os

Full example. (in this case, there are many subdirectories with music artist name at /home/myid/Music/ and then FLAC files are all over different subdirectories level. Since I don’t need artist folders but want to have all FLAC files into one directory at /home/myid/Music/flac/

Источник

How to move all files and folders via mv command [duplicate]

How can I move all files and folders from one directory to another via mv command?

7 Answers 7

(D) to include dot-files.

This works for me in Bash (I think this depends on your shell quite a bit. )

This works for me in Bash 4.2.46, it moves all files and folders including hidden files and folders to another directory

Notice that .[^.]* means all hidden files except . and ..

I’d say it’s a bit boring, but really bullet-proof (GNU) way is:

cd /SourceDir && find ./ -maxdepth 1 -mindepth 1 -exec mv -t /Target/Dir <> +

P. S. Now you can possibly see why lots of people do prefer Midnight Commander, though.

If you only want to do a cut and paste-like action there is a simple way that worked for me:

It will move the folder named dir_source located in /media to the directory $HOME/Documents/

yet another way just for the heck of it (because I love convoluted ways to do things I guess)

the -Q and the -A are not POSIX, however the -A is fairly prevalent, and to not use the -Q you need to change the IFS (which then means you don’t need the eval but need to quote the variable)

Not the answer you’re looking for? Browse other questions tagged linux command rename or ask your own question.

Linked

Hot Network Questions

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

How do I move all files from one folder to another using the command line?

I would like to know how could I move all files from a folder to another folder with a command line.

Let’s say I’m in my Downloads folder and there are a 100 files that I would like to move to my Videos folder, without having to write all the files name.

12 Answers 12

Open a terminal and execute this command:

It will move all the files and folders from Downloads folder to Videos folder.

To move all files, but not folders:

If you are interested in moving all files (but not folders) from Downloads folder to Videos folder, use this command

To move only files from the Download folders, but not from sub-folders:

If you want to move all files from the Downloads folder, but not any files within folders in the Download folder, use this command:

here, -maxdepth option specifies how deep find should try, 1 means, only the directory specified in the find command. You can try using 2 , 3 also to test.

See the Ubuntu find manpage for a detailed explanation

/Videos/») won’t move dot files.

/Videos can be more efficiently done with -exec mv -t

/Videos/ does not work for hidden files

It will move all the files including subfolders in the directory you want to mv . If you want to cp (copy) or rm (remove) you will need the -r (recursive) option to include subfolders.

/ in the prefix of the folder names doesn’t always work (doesn’t work on bash and git atleast)

For the simple case:

If you want to move dot (hidden) files too, then set the dotglob shell option.

This leaves the shell option set.

For one time dotglob use, run the commands in a subshell:

/Videos) only moves (cuts) the contents (including the hidden files). In this case, both the origin and destination folders must exist already. At the end, the origin directory becomes empty.

It’s possible by using rsync , for example:

-a , —archive : Archive mode; equals -rlptgoD (no -H , -A , -X ).

-u , —update : Skip files that are newer on the receiver.

—remove-source-files This tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side.

Читайте также:  Bios как настроить для установки windows с диска

If you’ve root privileges, prefix with sudo to override potential permission issues.

To move a directory with or without content to its new name just like how you would use the mv command to rename a file:

  • -T treats the destination as a normal file
  • dir1 is the original name of the directory
  • dir2 is the new name of the directory

NB: dir2 doesn’t have to exist.

I hope this saves someone a lot of time, as a noob, before this, I would create a directory with the new name and then move the contents of the directory to the directory created earlier.

Источник

How do I move files and directories to the parent folder in Linux?

In Linux (Ubuntu), how do you move all the files and directories to the parent directory?

13 Answers 13

this will move hidden files as well.

You will get the message:

when it tries to move . (current directory) but that won’t cause any harm.

I came here because I’m new to this subject as well. For some reason the above didn’t do the trick for me. What I did to move all files from a dir to its parent dir was:

Type this in the shell:

That moves ALL the files one level up.

The character * is a wildcard. So *.deb will move all the .deb files, and Zeitgeist.* will move Zeitgeist.avi and Zeitgeist.srt one folder up, since, of course, .. indicates the parent directory.

To move everything including folders, etc, just use * instead of *.*

It can’t be more simple than:

To also move hidden files:

mv is a command to move files, * means all files and folders and ../ is the path to the parent directory.

In bash you can use shopt -s dotglob to make * match all files and move them simply by

This is not the best solution since the setting is permanent for the shell until you change it by

but I think it’s good to know.

Assuming all your hidden files begin with dot followed by a letter or a number (which they should), you could use

The .[A-Za-z0-9]* part is to make sure you don’t try to move . or .. along, which would fail.

A method which causes no errors and works every time:

I used a variation of above to move all the files from subfolders into the parent.

I’d got data in folders by year, but found by using metadata I could have them all in the same folder which made it easier to manage.

There is no need to change directories. Just include * at the end of path:

Above only moves non hidden files. To move only hidden files use .*

Above two can be combined in to one command:

It’s simple to move all files and folders to the parent directory in Linux.

Go to that folder and use this command:

For example, if your files and folders are as follows:

Go to that folder via cd:

All your files and folders will move to the abcuser folder (parent directory).

There’s a lot of answers to this question, which proves the flexibility of Bash commands. However, to me a very simply solution that does the trick nicely is this one:

mv move; * select all files and folders; .[^.]* collects up the hidden files, with one dot at the start of their name; . * will select files that start with two dots followed by other characters; .. is the destination, which in this case is the parent folder.

Note, using .[^.]* and . * will ensure you only select those files with a single dot followed by something other than a dot, and those with two dots followed by other characters.

If you’d like to avoid trying to remember this, I suggest setting up an alias, such as, alias mvallup=»mv * .[^.]* . * ..» . Add this to

/.bash_aliases . Now you can just type mvallup and it’s a done deal.

A shorter version of this was suggested by William Edwards, but it didn’t include hidden files. He gave an example for also moving hidden files, but that was not exampled as simply as it could have been ( mv /path/subfolder/<.,>* /path/ ) hence why I’m posting this very simple option.

Источник

Оцените статью