5.2 Copying files from linux and Mac OSX machines with scp
Copying files between different linux, MacOSX or UNIX servers can be done with scp command. Thus you can use scp to transport data between CSC and your local environment or between different file systems at CSC.
The basic syntax for copying data from a local machine to a remote machine is:
scp file_to_copy firstname.lastname@example.org:/path/to/location
And correspondingly the syntax to copy files from a remote machine to a local machine is:
scp email@example.com:/path/location/file_name file_name
For example user kkayttaj could copy the file data.txt from his/her local computer to his/her home directory in taito.csc.fi server with command:
scp data.txt firstname.lastname@example.org:
In the command above, no path or file name is defined in the second argument. This means that the file will be copied to the users home directory with the same name as in the local machine (data.txt). If you would like to use other locations or file name, these values can be defined after the : sign. For example the following command would copy the file data.txt to a directory data_files (a sub directory in the CSC home directory) and name the copied file as data_a2.txt
scp data.txt email@example.com:data_files/data_a2.txt
To copy complete directories you should use scp command with option -r. For example the command below copies a directory data_dir and all its content to Taito. In this case a directory data_dir will be created to directory /wrk/kkayttaj. The content of the data_dir in Taito will be the same as in the local computer including all the subdirectories.
scp -r data_dir firstname.lastname@example.org:/wrk/kkayttaj/
Directory /wrk/kkayttaj is the work directory of user kkayttaj.
Copying the data from CSC environment to local computer is done in the same way. If for example file data.txt locates in the home directory of user kkayttaj it can be copied to the local machine with command:
scp email@example.com:data.txt ./
But if the file locates in the work directory it should be copied with command:
scp firstname.lastname@example.org:/wrk/kkayttaj/data.txt ./
You can check the explicit locations of different directories by first logging in to a server in CSC and then giving command
In the commands above, files and directories have been copied one at a time. However, scp can copy several files at a time:
scp data1.txt data2.txt data3.txt email@example.com:
You can also use wild cards when defining the files to be copied. For example to copy all files with extension .txt in the current directory to Taito, you could use command
scp *.txt firstname.lastname@example.org:
By default the copied files are treated as new files, but if you add option -p to the scp command, then the copied file will inherit the date and access mode information from the original file.
|Previous chapter||One level up||Next chapter|