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   index.rst             tests
file-system.ipynb     pipes-filters.ipynb
grep-find.ipynb       shell-variables.ipynb

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       pipes-filters.ipynb
file-system.ipynb     index.rst             shell-variables.ipynb

Transfering files#

wget#

[13]:
!wget https://dvc.org/deb/dvc.list
--2023-07-19 17:00:21--  https://dvc.org/deb/dvc.list
Auflösen des Hostnamens dvc.org (dvc.org)… 2606:4700:3036::6815:51cd, 2606:4700:3033::ac43:a44c, 172.67.164.76, ...
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]
--2023-07-19 17:00:21--  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)… 52.219.100.82
Verbindungsaufbau zu s3-us-east-2.amazonaws.com (s3-us-east-2.amazonaws.com)|52.219.100.82|: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

2023-07-19 17:00:22 (1,13 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 supresses 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    251      0 --:--:-- --:--:-- --:--:--   254