Linux how to copy files to windows

Copy Files Between Windows and Linux Using Command Line

In this updated guide, I will walk you through the steps to copy files from Windows to Linux using easy-to-follow steps.

I will show you two ways to copy files from windows to Linux

  1. Using command line with pscp
  2. Using GUI FTP utility.

Copy File from Windows To Linux Using PSCP

It is not always that you will need to copy a file from Windows to Linux or vice versa.

But at times when you are automating things or trying to achieve some copy functionality using a script, it is good to have a utility to do that.

Here is where pscp comes into play. Using pscp you can copy the file to/from windows and Linux.

Step 1: Download pscp.exe from here. Select the appropriate package.

Step 2: copy the pscp.exe executable to the system32 directory of your windows machine. This folder normally exists in C:\Windows\System32 path.

Step 3: Open Windows PowerShell and use the following command to verify if pscp is accessible from the path.

You should see the following output.

Step 4: Use the following format to copy the single file from Windows to the Linux box.

Here is the explanation of the command.

  1. -pw for the password.
  2. Replace password with the Linux user password.
  3. C:\Users\Admin\Desktop\test.txt represents the path of the file that has to be copied to the Linux system.
  4. 192.168.33.10 is the IP of the Linux server.
  5. /home/vagrant is the user-accessible path in the Linux system to copy the file.

If you want to copy all the files in a directory to Linux, you need to add a start to the folder. eg. folder\* . An example is shown below.

If you are using Linux private keys for authentication, you can use -i flag instead of -pw followed by the path to the .ppk , .pem or id_rsa file.

If your key file is in pem format, you can use the puttygen command to convert it to ppk. See this ec2 server guide for the pem to ppk conversion.

Info: Learn Linux & Windows administration from Pluralsight with its 10 days free account

For Linux Private key-based authentication, the command looks like below.

Copy File From Linux To Windows Using PSCP

You can use pscp to copy files from Linux to windows. use the following command format for the same.

The above command will copy the file in Linux from the specified path to the Windows desktop.

Copy File from Windows To Linux Using FTP GUI

If you are not familiar with the Windows command line, you can use an FTP tool like Filezilla.

This tool is really helpful if you are working with Web Hosting providers to upload your website files from your local workstation.

You can download Filezilla from here –> FileZilla Download.

After download, install Filzill as you install any other windows software.

After installation, open the Filezilla app and enter the remote Linux server details as shown below. It will connect to the server and shows the remote server files in the file explorer.

To upload a file, all you have to do is do a right-click and click upload, as shown in the image below. The file will get uploaded to the remote path, which is opened in the Filezilla explorer. You can also change the remote path from Filezilla.

Читайте также:  Platform tools latest windows

Conclusion

I have shown two best and recommended ways to transfer files from Windows to Linux and vice versa.

If you face any issues while copying files, please drop the issues as a comment. I will look into it.

Источник

Copy files between Linux and Windows

This describes how to copy files over the network between a computer (or virtual machine) running Windows and another computer (or virtual machine) running Linux.

There is also an article how to access a Linux partition when running Windows and how to access a Windows partition when running Linux. You may need this if your computer is running only one operating system and having two hard disk partitions.

Contents

You are on a Linux host

You want to access a Windows drive

So you are on a Linux computer and want to access a Windows drive over the network. This explains how. In this example we assume winhost is your Windows computer’s hostname (you can check the hostname by right clicking on My Computer and selecting Properties). Go to the Windows computer and open the Explorer. Share a folder by right-clicking onto it and selecting «Sharing and security». Call it «share1». Then, on your Linux computer,

  • Open up your favorite file explorer, perhaps Konqueror or Nautilus
  • In the address bar, type smb://winhost/share1
  • You should now see the files and folders in that share. Double-click on them to open them up and view them.

troubleshooting

If that doesn’t work, then you may need to do something more complicated.

  • install the samba client software
  • try to find the share:
  • If you see the share, mount it like this:
  • after the next reboot, your mount will be lost. To make it persistant, add the following line to your /etc/fstab:

You want to share a folder

So you are on a Linux computer and want to share a folder so that also Windows machines can access it over the network. To do this, you run the SAMBA service on your computer. To enable sharing to Windows machines, right click on a folder in Nautilus; the menu should have an item called «Sharing Options». Click it and pick the name for your share. If you don’t have Windows folder sharing enabled yet, Nautilus will ask you for a password and install the service, after which you will need to log out and back in. The share should now be available on the Windows computer.

You are on a Windows host

You want to access a Linux drive

Use WinSCP. Choose the SFTP protocol; the login and password are the same as those you use when logging in locally. If it does not work, look at your Linux computer: Try to shut down your firewall and install the openssh service.

You want to share a folder

You can share files with Linux using normal Windows sharing mechanisms. The Linux host will be able to access these files using samba.

Источник

Copy Files to Windows Subsystem for Linux WSL2 with SSH

In working with Windows Subsystem for Linux, you will undoubtedly want to work with files with your WSL Linux distribution. You may wonder how you can work with files effectively. This includes copying files both to and from Windows Subsystem for Linux distributions. This is much easier for large file edits and other configurations that lend themselves to a GUI text editor of sorts. Additionally, if you want to copy files back and forth between environments for development, it is important to be able to do this uninhibited. This post will take a look at how to copy files to Windows Subsystem for Linux WSL2 with SSH and see how to configure this.

Ways to copy files to Windows Subsystem for Linux WSL

By default, Windows Subsystem for Linux automatically mounts the C$ drive on the Windows 10 host system which allows you to see the files on the local hard drive. However, this is a one-way view. With WSL2, you can’t see the mounted file system as it is abstracted by way of the transparent Hyper-V utility VM that is used to house the WSL instance.

Читайте также:  Директ 12 для windows 10 что это

With that being said, you can certainly copy files from the mounted drive from the Windows 10 host and we will see how that is possible. However, most are familiar and used to working with Linux environments and file movement by way of SSH, SCP, SFTP, etc. So, we will take a look at how this can be enabled within the WSL/WSL2 Linux image.

Using the built-in /mnt for the host filesystem

As mentioned, by default, the Windows Subsystem for Linux automatically mounts the Windows 10 host C drive. With this being the case, you have automatic access to be able to copy files from the Windows 10 host to the Windows Subsystem for Linux WSL.

Below is a screenshot from a WSL Ubuntu 20.04 LTS image running. If you look at the mounts that have been provisioned, you will see the C drive for the Windows 10 host has been mounted and you can enumerate the files and folders on the Windows 10 host.

Below, I have created a testfile.txt file on the Windows 10 host C drive. Running the same ls/mnt/* command, we see the testfile.txt file listed. With this being the case, we can now simply run a Linux cp command to copy a file from the Windows C drive to a folder in the Windows Subsystem for Linux environment.

Copy Files to Windows Subsystem for Linux WSL2 with SSH

As you can imagine, it can get cumbersome to have to “sneakernet” files from your Windows host to your Windows Subsystem for Linux WSL environment. A much better way would be to have SSH access to your WSL Linux environment to allow easily moving files back and forth, editing WSL files directly, and other processes. Before you can use SSH to move files back and forth between the Windows 10 host and the Windows Subsystem for Linux environment, you need to enable SSH in your WSL Linux instance.

Enable SSH in Windows Subsystem for Linux WSL

For the most part, enabling SSH in the WSL environment follows suit with most Linux installations. However, there are a couple of quirks to note. The first, to have a clean slate with a working SSH configuration, the first thing to do is uninstall the openssh server that is installed by default. I had issues configuring the default installation of openssh. A quick Google saw others having issues as well. A quick uninstall and install of openssh resolves these.

After uninstalling the openssh server, reinstall it.

After reinstalling openssh-server, edit the sshd_config file to allow password authentication.

If you want to allow root to be able to login as well, you can allow this with the PermitRootLogin configuration.

After editing your sshd_config file, restart your SSH service using the following command:

Now that you have the SSH service properties edited and the SSH service restarted, we can gather the information to connect. Find the IP address for your WSL installation.

Below, I have ran the ifconfig command and see the configured IP address.

Now, we can use something like WinSCP to connect to the WSL installation.

After connecting, we see the filesystem and are now in a position to start copying files to Windows Subsystem for Linux WSL and back to the Windows host if needed. Also, you can edit files directly.

Wrapping Up

Hopefully this primer on how to copy files to Windows Subsystem for Linux WSL2 with SSH will help any who may be struggling to effectively access their WSL or WSL2 Linux installations. WSL is a great tool for development and other IT operations tasks by giving quick access to a Linux environment to run Linux tools, utilities, and applications.

Источник

How to Copy Files and Directories in Linux

Home » SysAdmin » How to Copy Files and Directories in Linux

This guide will show you how to copy files and directories in Linux by executing commands from the command line. Furthermore, the commands listed below detail how to create system-wide backups or filter out and copy only specific files.

Note: These Linux commands can only be run from a terminal window. If your version of Linux boots to a desktop graphical interface, launch a terminal window by pressing CTRL-ALT-F2 or CTRL-ALT-T.

Using the cp Command to Copy Files and Directories in Linux

The cp command is the primary method for copying files and directories in Linux. Virtually all Linux distributions can use cp . The basic format of the command is:

Читайте также:  Операционные системы основные характеристики операционных систем операционная система windows

This Linux command creates a copy of the my_file.txt file and renames the new file to my_file2.txt.

By default, the cp command runs in the same directory you are working in. However, the same file cannot exist twice in the same directory. You’ll need to change the name of the target file to copy in the same location. Some users will add _old, some will add a number, and some will even change the three-letter extension (e.g., .bak instead of .txt).

You may not get a warning before Linux overwrites your file – be careful, or see below for the –i option.

Additional Options

Additional options can be used in combination with the cp command:

  • –v verbose: shows the progress of multiple copied files
  • –ppreserve: keeps the same attributes, like creation date and file permissions
  • –f force: force the copy by deleting an existing file first
  • –i interactive: prompts for confirmation, highly advised
  • –Rrecursive: copies all files and subfolders in a directory
  • –u update: copy only if source is newer than destination

Note: The -p (preserve) option forces the system to preserve the following source file attributes: modification time, access time, user ID (UID), group ID (GID), file flags, file mode, access control lists (ACLs), and extended attributes (EAs).

How to Copy File to Another Directory in Linux

To copy a file from the directory you’re working in to a different location, use the command:

You don’t need to rename the file unless there’s already one with the same name in the target directory.

To specify a path for the source file:

This lets you copy without having to change directories. The cp command will create the /new_directory if it doesn’t exist.

To rename and copy a file to a different path:

This option is useful for creating backups of configuration files, or for copying data to a storage device.

Note: Learn how to move directories in Linux.

Copy Multiple Files from One Directory to Another in Linux

You may need to copy more than one file at a time.

List each file to be copied before the target directory:

This example created a copy of all three files in the /new_directory folder.

Use a wildcard to specify all files that share a string of characters:

This would find all the files with the .jpg extension in the /pictures directory, and copy them into the /new_directory folder.

To copy an entire folder and its subfolders and files, use the –R option:

–R stands for recursive, which means “everything in that location.” This would copy all the files, as well as all the directories, to the /new_directory folder.

Copy Using rsync Command

The rsync command in Linux is used to synchronize or transfer data between two locations. Usage is similar to cp , but there are a few key differences to note.

To copy a single file, enter the following into a terminal:

  • The –a option means all, and is included with rsync commands – this preserves subdirectories, symbolic links, and other metadata.
  • Replace the my_file.txt file in the working directory.
  • Replace /new_directory/ with the destination.
  • Using my_file_backup.txt as the target indicates the file will be renamed during the copy.

To copy a directory with rsync, enter the following:

This copies the contents of the /etc/docker/ directory to /home/backup/docker/. Make sure to keep the slashes. Omitting the slash on the source directory will copy the contents into a subdirectory.

To omit files from being copied, check out our guide on how to exclude files and directories in data transfer using rsync command.

Other Options

The ls command is a handy partner to the cp command in Linux.

To list the contents of a directory enter the command:

The example above displays all the files in /directory. Use this command after copying to verify the files were copied successfully.

To change directories, use cd and the name of the directory. For example:

The command prompt will change to display that you’ve changed directories.

Now you understand how to copy files in Linux. The cp command is a versatile and powerful tool for managing and backing up files.

Источник

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