cp
The cp command can be used to upload, download and copy files within BatchX. This command will always use two inputs: a source pattern and a target path. At least one of the must correspond to a BatchX file (start with bx://).
BatchX does not allow replacing local files. If you attempt to download a file with an existent local filename you will obtain the following message: Target file <file> already exists.
In similar way, BatchX won't allow you to replace files within your BatchX filesystem, either when updating or copying a file. If you attempt to replace a file you will get an ALREADY_EXISTS error. To replace a file you will first need to remove it using the bx rm command.
Usage
bx cp [--help] <source> <target>
Parameters and inputs
- Parameters
- Inputs
| Shorthand | Long version | Description |
|---|---|---|
--help | Show this help message and exit |
| Input | Description | Required |
|---|---|---|
<source> | Source filepattern | true |
<target> | Target path | true |
Examples
Upload a file to BatchX
Create a local file with the content "My travelling file"
$ echo "My travelling file" > upload.txt
Upload the file to BatchX using the bx cp command as follows:
$ bx cp upload.txt bx://travelling/upload.txt
traveller.txt [=================================================>] 100 %%
Notice that upload.txt is a local file while the target path is preceded by bx:// which refers to the target path in the BatchX file-system, so this is interpreted as an upload.
You can check by using the bx ls command that the file is indeed there:
$ bx ls travelling
travelling/upload.txt Mon Dec 16 08:46:10 CET 2019 19 B david
info
The bx cp command will dynamically create directories in BatchX that haven't been previously created.
Download a file from BatchX
Continuing with the previous example, use the bx cp command to download the file we have just uploaded:
$ bx cp bx://travelling/upload.txt download.txt
upload.txt [=================================================>] 100 %%
Notice noew that the source file is preceded by bx:// __ indicating that the file is stored in BatchX while the target destination download.txt file is the name we want to use to store it locally.
You can check by running the ls command that the file is indeed in your local file-system:
$ ls ll
-rw-r--r-- 1 dcrevil dcrevil 19 dic 16 08:44 upload.txt
-rw-r--r-- 1 dcrevil dcrevil 19 dic 16 08:53 download.txt
Copy a file within BatchX
Continuing with the previous examples, use the cp command to make a copy of the upload.txt __within the BatchX filesystem.
$ bx cp bx://travelling/upload.txt bx://travelling/copy.txt
Use the ls command to list again the contents of the travelling/ directory.
$ bx ls travelling
travelling/upload.txt Mon Dec 16 08:46:10 CET 2019 19 B david
travelling/copy.txt Mon Dec 16 08:55:40 CET 2019 19 B david
info
Copying files within the BatchX filesystem will actually not create a new copy of the file. Instead the cp command will create a new reference to the same file.
Directories
In the same way BatchX allows you to operate with individual files, you are also able to copy, download and upload whole directories maintaining their internal structure.
In this example we will upload a directory along with two sub-folders to BatchX.
First, create two local files, one with the content "hello" and other with the content "goodbye".
$ echo hello > hello.txt
$ echo goodbye > goodbye.txt
Create the following directories and move these files to their respective sub-folder.
$ mkdir beatles_songs beatles_songs/hello beatles_songs/goodbye
$ mv hello.txt beatles_songs/hello/
$ mv goodbye.txt beatles_songs/goodbye/
Your local directory structure should look like this.
$ tree beatles_songs
beatles_songs
├── goodbye
│ └── goodbye.txt
└── hello
└── hello.txt
2 directories, 2 files
Use the bx cp command to upload the beatles_songs directory to BatchX. This will upload the directory and all its contents.
$ bx cp beatles_songs bx://beatles_songs
beatles_songs [==================================================>] 100 %
You can verify that the internal file structure has been preserved using the bx tree command.
$ bx tree /beatles_songs
beatles_songs
├── goodbye
│ └── goodbye.txt
└── hello
└── hello.txt
File patterns
Source path can point to a file or folder like we swa in the previous examples, but it can also be a file pattern, that would allow to copy the a set of files (those matching the pattern).
See file pattern examples for more details.