Mac os terminal copy directory

Move and copy files in Terminal on Mac

In Terminal, you can move and copy files locally or remotely using the mv , cp and scp command-line tools.

Tip: It’s easier to move and copy files using the Finder. See Organise files in folders.

Move a file or folder locally

In the Terminal app on your Mac, use the mv command to move files or folders from one location to another on the same computer. The mv command moves the file or folder from its old location and puts it in the new location.

For example, to move a file from your Downloads folder to a Work folder in your Documents folder:

You can also change the name of the file as it’s moved:

Copy a file or folder locally

In the Terminal app on your Mac, use the cp command to make a copy of a file.

For example, to copy a folder named Expenses in your Documents folder to another volume named Data:

The -R flag causes cp to copy the folder and its contents. Note that the folder name does not end with a slash, which would change how cp copies the folder.

Copy a file or folder remotely

In the Terminal app on your Mac, use the scp command to copy a file or folder to or from a remote computer.

scp uses the same underlying protocols as ssh .

For example, to copy a compressed file from your home folder to another user’s home folder on a remote server:

You’re prompted for the user’s password.

The -E flag preserves extended attributes, resource forks and ACL information.

The -r flag, which isn’t used in this example, causes scp to copy a folder and its contents.

Источник

kwcto / mac-file-transfer-via-command-line.md

Mac File Transfer via Single User Mode / Command Line

  • Start in Single User Mode by holding down Command-S when starting the Mac.
  • Commands can also be typed via Terminal app when OS X is running.

Terminal Command Workflow

  1. Type diskutil list to view available drives
  2. Type diskutil mount /dev/disk1s2 (Disk 1, Partition Scheme 2 — may be different on your Mac) to gain read/write access on that disk.
  3. Type cd /Volumes to switch current folder to Volumes where Mac OS lists all mounted drives.
  4. Type ls to list contents of Volumes folder.
  5. Type mkdir to create a new folder (on the USB drive)
  6. The cp -a command copies files/folders from one path to another.

Start in Single-User Mode by holding Command-S as mentioned above You type -> diskutil list

/dev/disk0 (Physical Disk #1: Macintosh HD)

/dev/disk1 (Physical Disk #2: PIZZA_PIZZA_256GB)

You type -> diskutil mount /dev/disk1s2

You type -> cd /Volumes

You type -> ls

You type -> cd /Volumes/PIZZA_PIZZA_256GB
You type -> mkdir RecoveredFiles
You type -> cd RecoveredFiles
You type -> cp -a

Which should copy the entire Mac Photos folder to /Volumes/PIZZA_PIZZA_256GB/RecoveredFiles/Photos

  1. An empty line after running the cp command indicates success
  2. Copy folder and contained files together using cp -a /Source/FolderName /Destination/FolderName
  3. Copy single files without the -a using cp /Source/file.jpg /Destination/file.jpg

/Photos is the same as /Users/alex/Photos

More copying examples

You type -> cp

/Photos/myphoto.jpg Photos/myphoto.jpg
You type -> cp -a

/Documents /Volumes/PIZZA_PIZZA_256GB/RecoveredFiles/Documents
You type -> cp -a

Источник

Question: Q: using Terminal to copy files from external usb drive to another external hdd

New to using Terminal so be gentle. I keep my lightroom catalog on a little external thumbdrive on my macair. Now the thumbdrive does not appear in the Finder but it is present in Disk Utility and in Terminal. So I want to copy my lightroom catalog as well as the few photos saved to this thumbdrive to another external hd so I can attempt to reformat this drive, which may solve the Finder issue.

My question is, I am very new to Terminal and all I know is that I want to COPY the files not MOVE the files. I don’t know how to properly write the command lines to tell Terminal where my Directories are and where I want to send them (so i don’t know how to indicate paths) and i don’t know the proper Terminal to execute a Copy Directory.

MacBook Air, iOS 10.1.1

Posted on Jan 5, 2017 4:10 AM

Helpful answers

Restore will not erase the Source. It will erase the destination. I’m not sure where you got that idea from.

I gave you one Finder option which will work if the drive is visible in Terminal. The rest are just other GUI options

cp -R source_dir target_directory

Don’t put a trailing / on source_dir so it will copy that folder also.

That’s the best I can offer since you didn’t give the rest of the information.

Now, not knowing anything about a Lightroom catalog structure, there may be other options required in the copy command to pull it over correctly. If the catalog contains hard links, then you can’t use copy.

Jan 5, 2017 5:40 AM

The paths in Terminal should be

in each case. If there is a space in a name it should be preceded by a backslash — \

If you have more than directory at root level you could presumably just leave that bit off. You mentioned in your first post that you wanted to format the thumb drive — you are aware that this will erase its contents?

Jan 5, 2017 6:36 AM

There’s more to the conversation

Loading page content

Page content loaded

Before going into Terminal, in the Finder look at menu Finder>Preferences; select ‘Sidebar’ and under ‘Devices’ make sure ‘External Disks’ are checked. Then open a Finder window and see if your thumb drive appears in the sidebar.

Jan 5, 2017 4:13 AM

everything is checked, the other external drive i’m trying to transfer to appears in Finder.

Jan 5, 2017 4:18 AM

Open Terminal and type man cp . You will need to keep hitting the return key to see more of the article. It looks as if cp -R may be the instruction you need but read the manual to check.

Jan 5, 2017 4:27 AM

man cp is tmi for someone who only ever used Terminal to disable Apple Photos from launching and I only did that by literally copying and pasting code. Which is what I’m looking for here.

Jan 5, 2017 4:41 AM

In Disk Utility make sure the drive is mounted. You may also want to verify the drive. If you can get it mounted and displayed I would just use Finder to copy the files. Dragging from one drive to another copies files, not move.

Jan 5, 2017 4:47 AM

He says that the drive doesn’t appear in the Finder, though it does in Disk Utility and Terminal, thus making simple drag and drop impossible.

loosecaboose — have you tried ‘Repair disk’ in Disk Utility?

Jan 5, 2017 4:50 AM

i’m looking for a solution using Terminal. OS X ie Finder is not an option and Disk Utility repair says there is nothing wrong with the drive and I see the data is on the drive. I need lines of code in Terminal to pull the data off the drive and transfer it to another drive so I can reformat my drive.

Jan 5, 2017 4:57 AM

man cp is tmi for someone who only ever used Terminal to disable Apple Photos from launching and I only did that by literally copying and pasting code. Which is what I’m looking for here.

Use another GUI tool to copy the disk, then. If it shows in Disk Utility and is accessible in Terminal, there is no reason short of some setting that is preventing it from showing in the Finder (Go Computer, perhaps).

Carbon Copy Cloner or SuperDuper would likely be able to see it if it is mounted.

Or, use the Restore function in Disk Utility to copy one to the other. Select the empty drive in Disk Utility and click the Restore button. Set the source disk in the popup menu. That will completely replace the contents of the destination drive with the contents of the source drive. The destination would have to be at least as big as the source.

If you only know how to copy and paste «some code,» then you will likely end up wiping out your drive instead of copying it. Then, you’d just blame us.

We’d have to know the name of each of the volumes as shown in /Volumes to provide the necessary code for you to copy and paste.

Источник

Copy the Current Path from Terminal to the Clipboard in Mac OS X

While it’s fairly easy to copy a folder path from the Mac GUI and Finder, or even to copy the path into the Terminal with a drag & drop trick, going the other direction and getting the current path from the command line and then having it accessible to the broader OS X clipboard is a little trickier… well, at least until you know this handy little tip.

This trick is quite simple in function, using the pwd command (short for present working directory) and the pbcopy command (a command line interface to the copy to clipboard function in OS X), at it’s most simple it works like this:

This will instantly copy the present working directory to the clipboard of OS X.

If you’re already familiar with the command line, you’re good to go, but for those who aren’t as knowledgable about the command line, let’s review this command sequence a bit more so that it makes more sense.

If you want to follow along, just launch Terminal app. First, we’ll want to be at the location within the command line to copy the path for. For the purpose of this walkthrough we’ll choose “/System/Library/CoreServices/Resources/” because it’s a deep(ish) system path that is universal on all Macs. Now at the command prompt, enter the following command:

Hit the Return key and you’ll be in that folder, let’s verify it by using the aforementioned ‘pwd’ command:

Again, hit return, and you should see output like this:

Now that you know you’re in the right place, let’s copy that directory path to the clipboard, but without having to manually select it using the mouse cursor and hitting Command+C, by using pbcopy instead:

How this works is simple: the ‘pwd’ command executes, then uses what’s called a ‘pipe’ to redirect the output of pbcopy into the next command, which in this case is ‘pbcopy’. As mentioned, pbcopy is a command line interface to the Mac OS X clipboard, thus by piping command output there, that data gets stored in the Macs clipboard. Not sure about that? Just open any text document, or even stay at the terminal prompt, and hit Command+V… you’ll see “/System/Library/CoreServices/Resources/” as the output. Excellent huh? You can also use the other end of pbcopy, pbpaste, to reveal the stored clipboard data.

If you plan on using this often, you could always make an alias for it within your profile by adding a line like this to .bash_profile:

With that saved in bash_profile, you can just type ‘copypath’ and achieve the same effect.

This trick makes retrieving a current path simple, and eases going from the terminal to the GUI considerably. Remember, Mac users can also go the other way – from the GUI to the terminal – with an excellent drag & drop trick to automatically type out a full item path or file name from the Finder into the command prompt.

Источник

Quickly Copy a File or Folder Path to the Clipboard in Mac OS X

There are a few ways to retrieve a file or folders full path from Mac OS X, and we’ll cover the two easiest methods here, and also a third option that utilizes a Service to instantly copy any path to the clipboard. First, we’ll use the Get Info panel to pull any items complete path, and then we’ll use another trick that utilizes an under appreciated feature of the Terminal to retrieve any directory or files path. The optional Automator Service provides yet another option to copy file and folder paths, which is then quickly accessible through the right-click menu from the OS X Finder.

Just to clarify, we are looking to copy the path to a file or folder to the clipboard so that it can be pasted elsewhere. This is different from showing the path, which can be made visible in any Finder window through an optional window bar or even in the title bar using a defaults trick.

Let’s get to copying complete paths so that you can use them elsewhere.

Copy a File / Directory Path from the OS X Get Info Window

Perhaps the easiest and most user friendly method, you can easily retrieve any file or folders path from the Get Info window by doing the following:

  • Select the file or folder in the OS X Finder, then hit Command+i to summon Get Info
  • Click and drag alongside “Where” to select the path, then hit Command+C to copy the full path to the clipboard

Get Info can also be accessed by the control-click and right-click menus. For most use cases and for occasional complete path access, the Get Info trick is simple, fast, efficient, and should fit the bill for most people.

Dragging and dropping anything into the OS X Terminal outputs the full path to that item.

  • Launch Terminal then drag and drop any item from the Finder into the Terminal window to instantly print the full path
  • Select and highlight the path to copy it to the clipboard as usual

This trick is great if you are looking to use the path in the Terminal, otherwise it may not be as easy as the Get Info tip because it requires opening another app.

Create a “Copy Path” Service for the Right-Click Menu

If you find yourself frequently needing to copy and paste file and folder paths, creating an Automator Service will make your life easier because the service then becomes accessible from the OS X Right-Click contextual menu, accessible from anywhere in the Finder. This is an excellent trick from CNet and is very easy to set up yourself:

  • Launch Automator and create a new “Service”
  • Use the search function to look for “Copy to Clipboard” and drag that into the rightside panel of the Service
  • Set ‘Service recieves selected’ to “files or folders” and ‘in’ to “Finder” as shown in the screen shot below
  • Save the Service with a name like “Copy Path”

Now go anywhere in the Finder, select anything in the filesystem be it a directory or a file, then right-click to reveal the “Copy Path” service item as created.

Choosing that option will instantly copy the chosen items path to the clipboard, which you can then paste elsewhere.

What is a path anyway?

For the unfamiliar, you can think of an items path as it’s address in the file system, pointing to exactly where it resides on the computer. For example, a file named “Testfile.txt” that resides on your user account desktop would have a complete path that would resemble something like this:

For items in the user directories, you can user a tilde to shorthand the path like so:

That shorthand does not work with system files, or for accessing other user files, thus a complete path would be needed. All of the methods we’re sharing will access and copy the complete path, not the short hand, even if the file or directory in question is in the user folders.

Источник

Читайте также:  Планшет операционная система windows или андроид
Оцените статью