3/27/2020

Python : How to copy files from one location to another using shutil.copy()

Just check the example code

..

import shutil
# Copy file to another directory
newPath = shutil.copy('sample1.txt', '/home/varung/test')
print("Path of copied file : ", newPath)
#Path of copied file :  /home/varung/test/sample1.txt

#Copy a file with new name
newPath = shutil.copy('sample1.txt', '/home/varung/test/sample2.txt')
print("Path of copied file : ", newPath)
#Path of copied file :  /home/varung/test/sample2.txt

# Copy a symbolic link as a new link
newPath = shutil.copy('/home/varung/test/link.csv', '/home/varung/test/sample2.csv')
print("Path of copied file : ", newPath)
#Path of copied file :  /home/varung/test/sample2.csv

# Copy target file pointed by symbolic link
newPath = shutil.copy('/home/varung/test/link.csv', '/home/varung/test/newlink.csv', follow_symlinks=False)
print("Path of copied file : ", newPath)
#Path of copied file :  /home/varung/test/newlink.csv
..

How to delete a file or folder? (python code)

Use os or shut library
os.remove() removes a file.
os.rmdir() removes an empty directory.
shutil.rmtree() deletes a directory and all its contents.


EX)
import os
os.remove("/tmp/<file_name>.txt")
os.rmdir("/tmp/")

import shutil
shutil.rmtree("/tmp/")


ex2)
if os.path.isdir('./runs/ex'):
    shutil.rmtree('./runs/ex')
os.mkdir('./runs/ex')

3/23/2020

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
...


simple solutin :
ssh-keygen -R <host>

Ex)
ssh-keygen -R 192.168.3.10
ssh-keygen -R ubuntu@ec2-30.30.30.eu-west-1.compute.amazonaws.com





3/22/2020

use docker without sudo

1.Create the docker group.
> sudo groupadd docker

2.Add your user to the docker group.
> sudo usermod -aG docker $USER

3.Log out and log back in so that your group membership is re-evaluated.
> newgrp docker 

4.Verify that you can run docker commands without sudo.
>docker run hello-world