5 Data
We saw in the previous chapter how to create and edit files. This can be useful in some cases, but most of the time we will need to transfer files or folders between our local computer and the server or the other way around.
5.1 Moving files
There are different tools that can help us transfer data between computers through ssh, the same protocol we use to connect to remote servers:
scp(secure copy). This is a command line utility found in all Linux, Mac and Windows that creates an SSH connection and tranfer the files.
- FileZilla. This is a graphical user interface that allows transfering files through different protocolos, SSH included.
5.1.1 scp
scp is a command line tool. That means that we will use the terminal to execute it. We can simply call the program without any arguments or flags to see a quick help:
victor@aula:~$ scp
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
[-i identity_file] [-J destination] [-l limit] [-o ssh_option]
[-P port] [-S program] [-X sftp_option] source ... targetRemember, you can have a more detailed explanation of all the options by executing man scp.
Let’s see how to use scp. In this example I’m going to copy a zip file from my Windows machine to the projects/CREAF/linux_course folder I created in the previous chapter.
If you want to replicate the example, change the file for one in your computer that you want to copy.
In this case we know that we need the port 2222, so we will have to use the -P flag to provide the port number. Also, we need a path to the source file in our computer and a path to the target (destination) file in the remote server.
PS C:\Users\vgranda> scp -P 2222 '.\Documents\ifn4_acoruna_tcm30-536596.zip' victor@144.76.203.10:~/projects/CREAF/linux_course/ifn_coruña.zip
victor@144.76.203.10's password:
ifn4_acoruna_tcm30-536596.zip 100% 4076KB 83.9KB/s 00:48And that’s it. We can connect to the server and list the files in the linux_course folder to see if the file is really there:
PS C:\Users\vgranda> ssh -p 2222 victor@144.76.203.10
victor@144.76.203.10's password:
victor@aula:~$ ls -la projects/CREAF/linux_course/
total 4084
drwxrwxr-x 2 victor victor 4096 Jun 29 13:41 .
drwxrwxr-x 3 victor victor 4096 Jun 24 10:16 ..
-rw-rw-r-- 1 victor victor 0 Jun 25 10:15 analysis.R
-rw-rw-r-- 1 victor victor 4173392 Jun 29 13:42 ifn_coruña.zipWhat happens when we want to copy a file from the remote server to our local computer? In this case we just simply indicate the source in the remote server and the target in our computer:
PS C:\Users\vgranda> scp -P 2222 victor@144.76.203.10:~/projects/CREAF/linux_course/ifn_coruña.zip '.\Documents\ifn_coruña.zip'To copy folders the process is the same, but we have to add the -r flag to make the copy recursive to all files and subfolders contained in the folder we want to copy:
PS C:\Users\vgranda> scp -P 2222 -r '.\Documents\project_iris' victor@144.76.203.10:~/projects/CREAF/linux_course/5.1.2 FileZilla
FileZilla (https://filezilla-project.org/) is a free and open source graphical interface to access and transfer files between computers. Is out of the scope of this course, but you can check their website to learn how to install it and use it.
5.2 Disk space
When transfering files to the server, is important to be aware of the available space in the disk. Not only the transfer will stop with an error if the disk is full, but some system process can be also affected as they can depend on having enopugh space to create temporal files.
There are two command line utilities that can help us to check the available space in disk, and also what folders and files are using that space
5.2.1 df
df is an utility to quickly check the used and available space in the disk:
victor@aula:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.2G 944K 3.2G 1% /run
/dev/md2 1.8T 2.9G 1.7T 1% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/md1 989M 202M 737M 22% /boot
tmpfs 3.2G 12K 3.2G 1% /run/user/1001The -h flag is just simply converting the space to human readable units (GB, TB, MB…)
5.2.2 du
du is another utility that analyse the disk and tell us the size of folders and files:
victor@aula:~$ du -h -d 1 /home/victor
4.0K /home/victor/.cache
4.2M /home/victor/projects
4.2M /home/victorThe -h flag is the same as before and the -d 1 flag indicates to go only 1 level deep.