Using the shell
Aims
- Create a local project directory
- Create and edit
README.md
file
Learning outcomes
- Build confidence in navigating the filesystem, creating, deleting and editing files and folders
The shell
Here we recall very briefly why we use the shell environment and how normal operations are typically performed. These topics have already been covered in the previous term.
The shell allows you to interact with a computer without the need of a graphical user interface (GUI). This has three main advantages:
- it allows you to operate on files and folders programmatically
- it allows you to interact easily with remote machines, e.g. the High Performance Computing facilities of the University of Bristol
- it allows to have more direct access to low-level operations of your machine (installing and fine-tuning software, libraries and various components)
Important
It is essential to learn how to use the shell properly in order to understand and develop more advanced scientific computing tools.
Basic shell usage
- List files and directories: Displays the contents of the current directory.
ls
- Change directory: Moves to a different directory.
cd /path/to/directory
- Create a new directory: Creates a new folder.
mkdir new_folder
- Remove a file: Deletes a specific file.
rm file.txt
- Remove a directory: Deletes a directory and its contents.
rm -r directory_name
- Move or rename a file: Moves a file to a new location or renames it.
mv old_file.txt new_location/
- Copy a file: Copies a file to a new location.
cp file.txt /path/to/destination/
- Create a new file: Creates an empty file.
touch newfile.txt
- Edit a file: Opens a file in a text editor like
nano
for editing.
nano file.txt
- View the contents of a file: Displays the contents of a file in the terminal.
cat file.txt
- Search for text in a file: Searches for specific text in a file.
grep "search_term" file.txt
- Show current directory path: Displays the full path of the current working directory.
pwd
- Copy a directory: Copies a directory and its contents.
cp -r source_directory/ destination_directory/
- Move back one directory: Moves up one directory level.
cd ..
- Display disk usage: Shows the disk usage of files and directories.
du -sh *
To-dos
Now that we know how to manipulate folder and files, we start our project by creating
- a dedicated directory
- a
README.md
file to contain the project documentation