-
Notifications
You must be signed in to change notification settings - Fork 6
Command Line
An introduction to command line. Firstly, you need to identify and open your command line interface.
We recommend the following:
- Windows: we will choose to use Git bash (which was installed on your machine when you installed Git).
- nix (another way to describe Mac OS and/or Linux machines): we will use the system terminal.
Let us first let's find out the name of your computer by running:
$ whoami
Now let's find out which directory (folder) we are currently in:
$ pwd This stands for "present working directory"
Type the command in and press enter. It should list where you are currently located in your command line interface.
Seeing what is in your current location
To view the contents of the current directory:
$ ls This stands for "list"
Type the command in and press enter. You should see a list of the various files and directory in your current directory. Open your current directory in a graphical user interface and compare.
Moving to another location
If you want to enter a directory that is in your current directory type:
$ cd Try moving to your Desktop. It should be something like:
$ cd Desktop Creating a directory
To create a directory:
$ mkdir <directory_name> Experiment with creating a directory for this workshop:
$ mkdir rsd-workshop If your directory structure looked like this:
|--- home/ |--- Desktop/ |--- research |--- photos It will now look something like:
|--- home/ |--- Desktop/ |--- research |--- photos |--- rsd-workshop As an exercise move into the directory we just created:
$ cd rsd-workshop and create two further directories:
|--- rsd-workshop |--- src |--- test If you now wanted to go back to the "parent" directory:
$ cd .. Where .. is short hand for a previous directory.
Experiment with these, in combination with the command to find your current location as well as the command to list the contents of your directory.
Creating a file
To create a directory:
$ touch <file_name> Experiment with creating a file named addition.py in the directory rsd-workshop.
$ touch addition.py If you type ls you will see that the file has been created.
Copying files
To copy a file:
$ cp <new_file_directory_and_name> Experiment with copying any file.
Moving/renaming files
To move a file:
$ mv <new_file_directory_and_name> Experiment with moving any file. Note that if you want to rename a file you can do this by passing the new name in the same directory.
WARNING When using the command line interface you will not be prompted for confirmation if move/mv were to overwrite another file. Be careful.
Deleting files
To delete a file:
$ rm Copying and removing directories
To copy a directory:
$ cp -r
$ rm -r