<!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG-spv-->{"id":1936291,"date":"2021-07-01T09:15:00","date_gmt":"2021-07-01T07:15:00","guid":{"rendered":"http:\/\/nhub.news\/?p=1936291"},"modified":"2021-07-01T11:04:14","modified_gmt":"2021-07-01T09:04:14","slug":"master-the-macos-command-line-how-to-copy-and-move-files-through-terminal","status":"publish","type":"post","link":"http:\/\/nhub.news\/ru\/2021\/07\/master-the-macos-command-line-how-to-copy-and-move-files-through-terminal\/","title":{"rendered":"Master the macOS command line: How to copy and move files through Terminal"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>The command line\u2014that hidden world of code behind your Mac\u2019s pretty face\u2014sometimes offers a quicker way to do everyday tasks, plus it\u2019s just a cool \u2026<\/b><br \/>\nThe command line\u2014that hidden world of code behind your Mac\u2019s pretty face\u2014sometimes offers a quicker way to do everyday tasks, plus it\u2019s just a cool way to establish your tech cred. You\u2019ve learned how to navigate files and folders as well as delete files and folders with the command line and get help when you need it from man pages. Here, I\u2019ll show you how to copy and move files, common operations that often come in handy. I\u2019ll also show you how to create directories (that\u2019s Unix-speak for folders), so you can move files to new places. It\u2019s certainly easy to copy and move files in the Finder, but there are a number of reasons why you might want to do this from the command line instead: If you\u2019re in the Finder, and you drag a file from, say, your Desktop to your Documents folder, or any other folder on the same disk or volume, you move the file. The file is no longer on the Desktop, and is found only in the Documents folder. However, if you drag a file from your Desktop to an external hard disk, you\u2019ll see that the file remains in its original location; this file has been copied. (You may know that you can copy a file in the Finder, even on the same hard disk, by holding down the Option key when you drag it.) The same is the case from the command line. There are two commands for moving and copying: mv and cp. The first does the same as dragging a file to a new location on the same hard disk. The second does what an Option-drag does, or what happens when you drag a file to a different disk or volume. Copying files with the cp command is simple. First, launch Terminal (in your \/Applications\/Utilities folder). Then, use the following syntax to create your command: cp source destination For example, to copy a file named MyFile.rtf from your Desktop folder to your Documents folder, you would type in the following command in Terminal and then press Return: cp ~\/Desktop\/MyFile.rtf ~\/Documents You\u2019ll now have a file named MyFile.rtf on your Desktop, and a copy of that file in your Documents folder. You\u2019ll remember from \u201cMaster the command line: Navigating files and folders\u201d that the tilde (~) symbol is a shortcut for your Home folder, which contains your Documents folder. This command takes the file at the precise path you specify as the source argument, and moves it to the directory (folder), which is the destination. Note that if there\u2019s no file there, or if you type the name incorrectly, Terminal will give you a \u201cNo such file or directory\u201d error. If you type a file path incorrectly, Terminal will let you know with a \u201cNo such file or directory\u201d error. IDG You can also copy directories, including all the files they contain. This uses a special \u201cflag\u201d or \u201coption\u201d with the cp command: the -R or recursive flag. When you use options with commands, this additional letter\u2014always preceded by a hyphen (-)\u2014tells the command to do something a bit differently. The recursive option tells the cp command to copy every item in the folder: every sub-folder, every file and folder in every sub-folder, and so one, all the way down, to the new location. So you can copy a directory from your Desktop to your Documents folder like this: cp -R ~\/Desktop\/MyFolder \/Documents You\u2019ve probably guessed that the mv command works in the same way. But there are two ways you can use the mv command. The first moves a file to a different disk or volume; remember, just as in the Finder, copying a file to a different volume won\u2019t delete the original, whereas moving will. So you could issue this command to move a file from your Desktop to a folder on a backup disk: You can also move directories with the mv command. The syntax is the same, and you don\u2019t need the -R flag as you do with the cp command.: mv ~\/Desktop\/MyFolder \/Volumes\/Backup One of the great things about the command line is the way you can use wildcards to simplify commands. For example, if you want to copy all the.rtf files (Rich Text Files) from your Desktop to your Documents folder, you can use the asterisk (*) wildcard: cp ~\/Desktop\/*.rtf ~\/Documents You can use the same wildcard with the mv command to move multiple files. The mv command also lets you quickly rename files. What you do is essentially move a file to the same location, but change its name. If you specify a name for its destination, the mv command changes the file\u2019s name when it moves the file. You can change a file name like this: mv ~\/Desktop\/MyFile.rtf ~\/Desktop\/MyFile-old.rtf This is a valuable tool for troubleshooting; you can use this to create a backup copy of a file, such as a preference file, in case you need it again. But you can also use this renaming method simply because you want to rename a file. You can also copy a file with cp and change its name. In this case, you need to specify not just a destination directory, but also a name for the file: cp ~\/Desktop\/MyFile.rtf ~\/Documents\/MyFile1.rtf Here\u2019s one final command that may come in handy: mkdir, the make directory command. This is very useful when you need to make a bunch of folders in one fell swoop, say for a new project you\u2019re starting. First use the cd ( change directories) command to move into the directory where want to create a new directory. Once you\u2019re there, run this command (in the example below, DirectoryName is the name you want. Replace DirectoryName with your desired name): mkdir DirectoryName You can use any name for the directory (for instance, \u201cHot Project\u201d or \u201cTPS Reports\u201d), and you can make multiple directories with a single command: mkdir MyDirectory1 MyDirectory2 MyDirectory3 With these three simple commands\u2014 mv, cp, and mkdir \u2014you\u2019ll be able to copy and move files, as well as create directories to hold files anywhere in your Mac\u2019s file system. As you become proficient with these commands, you\u2019ll see how easy they are to use. Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our affiliate link policy for more details.<\/p>\n<script>jQuery(function(){jQuery(\".vc_icon_element-icon\").css(\"top\", \"0px\");});<\/script><script>jQuery(function(){jQuery(\"#td_post_ranks\").css(\"height\", \"10px\");});<\/script><script>jQuery(function(){jQuery(\".td-post-content\").find(\"p\").find(\"img\").hide();});<\/script>","protected":false},"excerpt":{"rendered":"<p>The command line\u2014that hidden world of code behind your Mac\u2019s pretty face\u2014sometimes offers a quicker way to do everyday tasks, plus it\u2019s just a cool \u2026 The command line\u2014that hidden world of code behind your Mac\u2019s pretty face\u2014sometimes offers a quicker way to do everyday tasks, plus it\u2019s just a cool way to establish your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1936290,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1936291"}],"collection":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/comments?post=1936291"}],"version-history":[{"count":1,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1936291\/revisions"}],"predecessor-version":[{"id":1936292,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/1936291\/revisions\/1936292"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media\/1936290"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media?parent=1936291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/categories?post=1936291"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/tags?post=1936291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}