Appearance
Creating & Managing Files
Now that you know how to navigate through directories in the terminal, the next step is learning how to create, edit, and manage files effectively. This skill is essential when working in WSL (Ubuntu) or macOS, where you’ll often handle Python scripts, simulation input files, and data directly through the terminal.
Creating New Files
There are several ways to create files in the terminal — depending on whether you just want to make an empty file or open one for editing.
| Command | Description | Example |
|---|---|---|
touch filename | Create an empty file | touch beam_simulation.py |
code filename | Open the file in Visual Studio Code | code notes.txt |
echo "text" > filename | Create a file with initial text | echo "Initial parameters" > params.txt |
Tip: If a file already exists, using
>will overwrite it, while>>will append text to the end. Example:echo "Added a new note" >> notes.txt
Viewing Files
To check the contents of a file directly from the terminal, you can use one of these commands:
| Command | Description | Example |
|---|---|---|
cat filename | Display the entire file content | cat params.txt |
less filename | Open a scrollable view of the file | less results.log |
head filename | Show the first 10 lines | head simulation.log |
tail filename | Show the last 10 lines | tail simulation.log |
tail -f filename | Continuously monitor the file (useful for live logs) | tail -f output.log |
Tip: Use the arrow keys to scroll in
less, and pressqto quit.
Copying, Moving, and Renaming Files
When organizing your project folders, you’ll often need to duplicate, move, or rename files.
| Command | Description | Example |
|---|---|---|
cp file1 file2 | Copy a file | cp mesh.py mesh_backup.py |
cp -r folder1 folder2 | Copy folders recursively | cp -r results/ archive_results/ |
mv file new_location | Move a file to another folder | mv beam.py /mnt/d/simulations/ |
mv oldname newname | Rename a file | mv params.txt parameters.txt |
Deleting Files
Be cautious when deleting files — once removed, they can’t be easily recovered.
Deleting Files
Be cautious when deleting files — once removed, they can’t be easily recovered.
| Command | Description | Example |
|---|---|---|
rm filename | Delete a file | rm temp.log |
rm -r folder | Delete a folder and its contents | rm -r old_study |
rm -rf folder | Force delete a folder (use with caution) | rm -rf backup_old |
Warning: The
rm -rfcommand will permanently delete files and folders without any confirmation. Double-check your command before pressing Enter!
Useful Shortcuts
- Use Tab for filename auto-completion.
- Combine
&&to chain commands (e.g.,touch a.txt && nano a.txt). - Use Ctrl + C to stop an active process.
- Use Ctrl + D to exit the terminal or Nano editor.
Summary
Creating and managing files directly from the terminal makes your workflow faster, especially when handling simulations and automation scripts. You now know how to:
- Create, view, and edit files using commands like
touch,cat, andnano. - Copy, move, and rename files for better organization.
In the next section, we’ll explore how to manage file permissions and ownership, which is particularly useful when sharing projects or running simulation scripts on servers.