(Again, please remember that I have used ‘sudo’ with ‘cp’ because I am copying files to a location which requires administrative privileges. Sudo cp 'untitled folder/Data backup 2.tar ' '/media/pen 2/new folder ' Let us take the same example and say that this time we need to copy it over to /media/pen 2/new folder (as you can see this path contains two names with spaces in their names and one without). If both file paths ( source and destination) contain such names (or even a mix - a file path that contains names with spaces and names without them), then you can add apostrophe pairs to each path, separately. Sudo cp 'untitled folder/Data backup 2.tar' /media/pen
![extfs terminal commands extfs terminal commands](https://res.cloudinary.com/practicaldev/image/fetch/s--qf3Nu_-_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9j4f06k34y3yi0bol2f.png)
Coming back to the above example, let us say the Data backup 2.tar file is inside a folder called untitled folder that is located on my Home folder, then I will use the below command for copying it to the same destination. You can add apostrophes separately to each name, or you can put that particular path which contains names with spaces, between two apostrophes, as a whole, which is much easier. If a path contains two or more file names with spaces … For this example, I will use the below command and the copying will be carried on without errors.Īs you see, once you add the first apostrophe, then you can type the file name freely, and when done entering the name, make sure to add another apostrophe (this is very important). So instead, you can put the file name that contains spaces, between two apostrophes. Well, you can add backslashes as mentioned before and below is the correct command using that.īut as you can see, not only it is time consuming, but since we are not that used to seeing backslashes on file names, it can be really confusing as well. In fact, if you carefully look at the output, you can see that command-line has treated the file name as three different files due to the three spaces that are present in the file name. Note: I am running ‘cp’ with ‘sudo’ (administrative) privileges.
![extfs terminal commands extfs terminal commands](https://plugins.octoprint.org/assets/img/plugins/terminalcommandsextended/screenshot_tab.png)
If I enter the below command then I will receive an error saying that there exists no such file/directory. And unless you are aware of this simple trick, it can be quite frustrating, because for each space you have to add a backslash ( \ ) when using the command-line.įor example, let us assume that I have a file called Data backup 2.tar on my Home folder, and that I need to copy it to /media/pen location using the ‘cp’ command.
![extfs terminal commands extfs terminal commands](https://wethegeek.com/wp-content/uploads/2018/09/Introduction-to-Mac-Terminal.png)
That said however, when dealing with files under command-line, say that you had to use it to backup your data because the desktop session was not working anymore, it is pretty common that one should come across files that contain spaces in their names. Most people that use the GNU/Linux operating system do not like to deal with the command-line at all, though having a basic understanding of it (such as memorizing commands for mounting devices and copying files for instance) can come in real handy sometimes.