Operating the HPC05 cluster requires you to operate a computer by the command line. On Mac or Linux, this programme is called "terminal". On Windows it is called "command prompt". However, the Windows system uses a different coding language to conduct operations. As we are unfamiliar with this format - and all our instructions are written assuming a Linux/Mac-like terminal - we recommend installing one of the following programmes: [WSL Ubuntu](https://www.microsoft.com/store/productId/9NBLGGH4MSV6) [https://www.cygwin.com/](https://www.cygwin.com/) This will provide you with a "Terminal" mimic in a sense in which you can do all the same things as you can on Mac or Linux. ## How to run Python command line When writing a Python code and executing it you probably use some convenient editor that has some kind of auto-completion and user interface allowing you to easily run the script. This is obviously the most pleasant way of doing things. However, when operating the HPC05 cluster you will not be able to see the screen. So how do I know run Python? The answer is to open the command prompt/terminal and 'give the computer the instructions by hand'. When doing the above, you will notice your computer started Python. You can now type as if you would do with any other script. Obviously, typing things in the terminal is not pleasant at all and is therefore not something you will be doing (ever :P). Still, this shows you what the terminal does: You told your computer to start the programme called "Python" ``` python script.py ``` will execute the Python code written in script.py (and is therefore the equivalent of clicking on the "play button" in many graphical interface based interpreters). ## Allowing for command line arguments in Python Say I have simulation that takes in two parameter values that I want to be varying using the cluster's computer power. I first will need to allow my computer to understand that "script.py" takes in these two global input parameters for the code. The following structure in any Python code will allow you to run the script.py via the command line using additional/variable input parameters. ```python import sys def main(argv): parameter1 = float(argv\[1\]) parameter2 = int(argv\[2\]) return if \_\_name\_\_ == "\_\_main\_\_": main(sys.argv) ``` If this code is saved as 'script.py' , it can be run command line using ``` python script.py param1 param2 ``` In combination with the above structure of your Python code, it is equivalent of now running the function called 'main()' (by default), to which the following list will be given as input ``` argv = \['script.py', 'param1' ,'param2'\] ``` Hence, when unpacking the parameters inside your Python code note the following: 1\. The command line is interpreted as a 'string' (text). Hence if I type the value 32, I must tell the Python code to convert it into either a floating point number of integer number (depending on its usage). 2\. Therefore, If my code takes the name of a output file as input, no conversion is needed as a file name should be a string-value anyways. 3\. I started by unpacking value argv\[1\], not 0. The first argument of the argv list by convention will equal the name of the script itself. (argv is the list of input arguments given to the 'python' call on your command line) ## Useful commands on Terminal (Bash) Perhaps the most useful of them al: 'the TAB key' enables autocompletion. To navigate from folder to folder ``` cd Documents/... ``` Navigate one folder up (backwards) ``` cd .. ``` Back to the start/reset to folder I started my Terminal session from ``` cd ``` To see al files present in the folder you are in ``` ls ``` also show 'hidden files' (for instance any file name that starts with a '.' ) ``` ls -a ``` To make a new folder/directory ``` mkdir DirectoryName ``` To make a directory in some different folder ``` mkdir Location/DirectoryName ``` To move a file to a different directory ``` mv MoveThisFile ToThisLocation ``` To copy a file ``` cp NameOfFile CopyIntoThisFolder ``` To operate on all files within a folder: ``` cp Directory/\* CopyIntoThisFolder ``` Or to operate on all .txt files in that folder ``` cp Directory/\*.txt CopyIntoThisFolder ``` To delete (remove) a file (**NOTE: You will not get a warning and anything you delete is also NOT present in your thrash bin.** ) ``` rm file ``` To remove all files in a folder (and its subfolders) add the 'recursive flag' ``` rm -r Directory/\* ``` To remove the file folder itself ``` rmdir Directory ``` 'Oops I made a mistake, please stop this line of command and give me a new empty line' ``` 'CNTRL + C' ``` Clear the screen (move to the top of screen) ``` clear ``` 'What was that previous command I used again? I know it started with a "d" ' ``` 'CNTRL + R' 'Type a 'd' and the latest command starting with this 'd' should appear'. Use another 'CNTRL +R' to view the second to last option and so forth ``` A simple text editor ``` nano filename ``` Using an non-existing file name will create a new (empty file), whereas using this 'nano' to open any existing file allows you to edit it. Quit this programme (it will then ask you to save the file you created/edited) ``` 'CNTRL + Q' ``` Quickly see the content of a file without the need of editing it ``` more filename ```
{"description":"Operating the HPC05 cluster requires you to operate a computer by the command line. On Mac or Linux, this programme is called “terminal”. On Windows it is called “command prompt”.","title":"Commands in terminal (needed for HPC05 cluster)","contributors":"[{\"id\":\"a046edb1-7fd5-4edf-a55a-e951b5c3b774\",\"add\":5505,\"del\":0}]"}
Expand menu