The dictation pipeline — that hidden world of computer code behind your Mac ’s pretty face — sometimes volunteer a spry way to do everyday tasks , plus it ’s just a coolheaded way to establish your technical school cred . You ’ve learned how tonavigate files and foldersas well asdelete files and folderswith the instruction line andget aid when you take it from serviceman pages . Here , I ’ll show you how to copy and move files , coarse operations that often come in handy . I ’ll also show you how to create directory ( that ’s Unix - speak for folders ) , so you may move files to fresh places .
Why bother with the command line?
It ’s certainly promiscuous 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 communication channel instead :
The difference between copying and moving files
If you ’re in the Finder , and you drop back a file from , say , your Desktop to your Documents folder , or any other pamphlet 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 puff a file from your Desktop to an outside backbreaking disk , you ’ll see that the file remains in its original location ; this file has been copied . ( You may have it away that you may replicate a filing cabinet in the Finder , even on the same hard disk , by holding down the choice key fruit when you draw it . )
The same is the grammatical case from the command melodic phrase . There are two commands for move and copying : mvandcp . The first does the same as drag in a file to a new location on the same toilsome disk . The second does what an Option - pull does , or what happens when you drag a file to a different phonograph recording or mass .
How to copy files and directories
Copying fileswith thecpcommand is simple . First , establish Terminal ( in your /Applications / Utilities booklet ) . Then , use the comply syntax to make 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 follow command in Terminal and then press Return :
If you type a file path incorrectly, Terminal will let you know with a “No such file or directory” error.
cp ~/Desktop / MyFile.rtf ~/Documents
You ’ll now have a file make MyFile.rtf on your screen background , and a copy of that Indian file in your Documents folder .
You ’ll remember from“Master the program line stemma : Navigating files and folders”that the tilde ( ~ ) symbol is a shortcut for your Home folder , which contains your Documents folder . This command train the file at the precise way you specify as the source argument , and moves it to the directory ( folder ) , which is the destination . remark that if there ’s no file there , or if you type the name incorrectly , Terminal will give you a “ No such file or directory ” error .
If you type a file way wrong , Terminal will allow you get it on with a “ No such file or directory ” misplay .
IDG
you could alsocopy directories , including all the file they check . This uses a special “ iris ” or “ option ” with thecpcommand : the - Ror recursive sword lily . When you use options with control , this additional letter — always forgo by a dash ( -)—tells the instruction to do something a bite differently . The recursive selection tells thecpcommand to re-create every point in the folder : every sub - folder , every file and folder in every sub - folder , and so one , all the way down , to the newfangled location . So you may copy a directory from your screen background to your Documents booklet like this :
cp -R ~/Desktop / MyFolder /Documents
How to move files
You ’ve probably guessed that themvcommand works in the same manner . But there are two ways you may use themvcommand . The first moves a filing cabinet to a different disk or bulk ; commemorate , just as in the Finder , re-create a filing cabinet to a dissimilar volume wo n’t delete the original , whereas go will . So you could publish this command to move a file from your background to a folder on a backup disc :
you may also move directory with themvcommand . The syntax is the same , and you do n’t need the - Rflag as you do with thecpcommand . :
mv ~/Desktop / MyFolder /Volumes / Backup
How to copy or move multiple files
One of the great things about the mastery line is the style you’re able to use wildcards to simplify command . For example , if you want to copy all the .rtf files ( Rich Text Files ) from your Desktop to your Documents folder , you could use the asterisk ( * ) wildcard :
cp ~/Desktop/*.rtf ~/Documents
you may use the same wildcard with themvcommand to move multiple files .
How to rename files
Themvcommand also lets you speedily rename files . What you do is essentially move a file to the same locating , but exchange its name . If you specify a name for its destination , themvcommand changes the data file ’s name when it moves the file . you’re able to transfer a filing cabinet name like this :
mv ~/Desktop / MyFile.rtf ~/Desktop / MyFile - old.rtf
This is a worthful cock for troubleshooting ; you’re able to use this to create a backup transcript of a data file , such as a druthers file , in case you need it again . But you’re able to also practice this renaming method simply because you want to rename a file .
you’re able to also copy a file withcpand change its name . In this case , you demand to determine not just a address directory , but also a name for the file :
cp ~/Desktop / MyFile.rtf ~/Documents / MyFile1.rtf
How to create directories (a.k.a. folders)
Here ’s one final mastery that may come in ready to hand : mkdir , themake directorycommand . This is very useful when you want to make a caboodle of folders in one fell swoop , say for a new project you ’re starting . First use thecd(change directories ) statement to move into the directory where want to make a new directory . Once you ’re there , run this statement ( in the example below , DirectoryNameis the name you require . ReplaceDirectoryNamewith your trust name ):
mkdir DirectoryName
you may use any name for the directory ( for instance , “ Hot Project ” or “ TPS Reports ” ) , and you may make multiple directories with a individual command :
mkdir MyDirectory1 MyDirectory2 MyDirectory3
With these three mere commands — mv , cp , andmkdir — you’ll be able to replicate and move file , as well as create directories to hold files anywhere in your Mac ’s single file system . As you become proficient with these commands , you ’ll see how easy they are to expend .