# PC987 Day 2 (20201215) 1. Make sure you have installed Python in your local machine (https://www.anaconda.com/products/individual) 2. Make sure you have your git installed. (https://gitforwindows.org/) 3. Configure your git id if you not already done so. ```bash git config --global user.email "your email goes here" git config --global user.name "your name goes here" ``` 3. Git clone or fork the following repo "https://gitlab.com/goh.yongkheng/pc987.git" - fork will allow you to own a copy of your project, that means you can change it and push it back to your own git account - clone is just download a copy of the project ## Bash shell commands 1. listing of files and content: `cat`, `ls`, `head` 2. redirection: ```bash= $ ls scripts/* > filelist.log ``` 3. piping: ```bash= $ ls scripts/* | grep pdf$ ``` 4. aliasing commands ```bash $ alias ll="ls -lh" ``` to add the alias permanantly to your shell, add the above line to the file `.bash_aliases` in your home directory. 5. Creating a bash script: open a file and adding the commands. For example, add the following line to `myscript.sh`. ```bash= #!/usr/bin/bash ls scripts/* | grep pdf$ | xargs -i cp {} backup/ ``` 6. Different state of a process in Linux - running: foreground (`fg`) or background (`bg`) - suspend(`^z`): your process is waiting for instruction, ie not running - use `jobs` to list the processes currently running/waiting - to start a process in background directly ```bash= $ python3 processor_temp.py > output.log & ``` - display current processes ```bash= $ ps -f $ ps -u dummy $ ps -aux ``` - use nice number to control process priority ```bash= $ renice 10 <process ID> ``` - to stop/kill a job ```bash= $ kill -9 <process ID> ``` ## Python virtual environment - We setup virtual environment for - separate user python with os python - clean environment - capture the python dependencies of your project - in case of venv is not install, do this: ```bash= $ sudo apt install python3-venv ``` - to create a virtual env ```bash= $ python3 -m venv <name of your virtual env> $ source <name of your virtual env>/bin/activate (env) $ deactivate # to deactive the virtual env ``` - create dependency requirements ```bash= $ source env/bin/activate (env) $ pip install markdown (env) $ pip freeze > requirements.txt ``` in the new virtual env or new server ```bash= (another env) $ pip install -r requirements.txt ```