Create, update and delete files and directories

Creates a new directory test and then checks this with ls:

[1]:
!mkdir tests
[2]:
!ls
create-delete.ipynb           grep-find.ipynb.license
create-delete.ipynb.license   index.rst
dvc.list                      pipes-filters.ipynb
dvc.list.1                    pipes-filters.ipynb.license
file-system.ipynb             shell-variables.ipynb
file-system.ipynb.license     shell-variables.ipynb.license
grep-find.ipynb               tests

Then we create the file test_file.txt in this directory.

[3]:
!touch tests/test_file.txt
[4]:
!ls tests
test_file.txt

Now we change the suffix of the file:

[5]:
!mv tests/test_file.txt tests/test_file.py
[6]:
!ls tests
test_file.py

Now we make a copy of this file:

[7]:
!cp tests/test_file.py tests/test_file2.py
[8]:
!ls tests
test_file.py  test_file2.py

A directory with all the files it contains is also possible recursively with the -r option:

[9]:
!cp -r tests tests.bak
[10]:
!ls tests.bak
test_file.py  test_file2.py

Finally, we delete the directories tests and tests.bak again:

[11]:
!rm -r tests tests.bak
[12]:
!ls
create-delete.ipynb           grep-find.ipynb.license
create-delete.ipynb.license   index.rst
dvc.list                      pipes-filters.ipynb
dvc.list.1                    pipes-filters.ipynb.license
file-system.ipynb             shell-variables.ipynb
file-system.ipynb.license     shell-variables.ipynb.license
grep-find.ipynb

Transferring files

wget

[13]:
!wget https://dvc.org/deb/dvc.list
--2024-10-28 17:22:50--  https://dvc.org/deb/dvc.list
Auflösen des Hostnamens dvc.org (dvc.org)… 2606:4700:3036::6815:51cd, 172.67.164.76, 104.21.81.205, ...
Verbindungsaufbau zu dvc.org (dvc.org)|2606:4700:3036::6815:51cd|:443 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 303 See Other
Platz: https://s3-us-east-2.amazonaws.com/dvc-s3-repo/deb/dvc.list [folgend]
--2024-10-28 17:22:51--  https://s3-us-east-2.amazonaws.com/dvc-s3-repo/deb/dvc.list
Auflösen des Hostnamens s3-us-east-2.amazonaws.com (s3-us-east-2.amazonaws.com)… 3.5.130.80, 52.219.92.209, 52.219.106.105, ...
Verbindungsaufbau zu s3-us-east-2.amazonaws.com (s3-us-east-2.amazonaws.com)|3.5.130.80|:443 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 51 [binary/octet-stream]
Wird in »dvc.list« gespeichert.

dvc.list            100%[===================>]      51  --.-KB/s    in 0s

2024-10-28 17:22:51 (1,52 MB/s) - »dvc.list« gespeichert [51/51]

  • -r recursively crawls other files and directories

  • -np avoids crawling to parent directories

  • -D targets only the following domain name

  • -nH avoids creating a subdirectory for the websites content

  • -m mirrors with time stamping, time stamping, infinite recursion depth, and preservation of FTP directory settings

  • -q suppresses the output to the screen

cURL

Alternatively, you can use cURL, which supports a much larger range of protocols.

[14]:
!curl -o dvc.list https://dvc.org/deb/dvc.list
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    85  100    85    0     0     79      0  0:00:01  0:00:01 --:--:--    79