-
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.
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.
If you want to enter a directory that is in your current directory type:
$ cd <directory>
Try moving to your Desktop. It should be something like:
$ cd Desktop
To create a directory:
$ mkdir <directory_name>
Experiment with creating a directory for this workshop:
$ mkdir euroscipy2024
If your directory structure looked like this:
|--- home/
|--- Desktop/
|--- research
|--- photos
It will now look something like:
|--- home/
|--- Desktop/
|--- research
|--- photos
|--- euroscipy2024
Move into the directory we just created:
$ cd euroscipy2024
Let's create one further directory src
. You can navigate in the new folder with:
$ cd src
If you now wanted to go back to the parent directory:
$ cd ..
Where ..
is short hand for a previous directory.
To create a file:
$ touch <file_name>
Experiment with creating a file named README.md
in the directory euroscipy2024
.
$ touch README.md
If you type ls
you will see that the file has been created.
To copy a file:
$ cp <file> <new_file_directory_and_name>
Let's copy README.md
to src
:
$ cp README.md src
To move a file:
$ mv <file> <new_file_directory_and_name>
Having two README.md
files could cause some confusion. So let's rename the copy we created by using the mv
command.
$ mv src/README.md src/index.md
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.
To delete a file:
$ rm <file>
To copy a directory:
$ cp -r <dir> <target>
To remove a directory:
$ rm -r <dir>