Skip to content

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.

CommandDescriptionExample
touch filenameCreate an empty filetouch beam_simulation.py
code filenameOpen the file in Visual Studio Codecode notes.txt
echo "text" > filenameCreate a file with initial textecho "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:

CommandDescriptionExample
cat filenameDisplay the entire file contentcat params.txt
less filenameOpen a scrollable view of the fileless results.log
head filenameShow the first 10 lineshead simulation.log
tail filenameShow the last 10 linestail simulation.log
tail -f filenameContinuously monitor the file (useful for live logs)tail -f output.log

Tip: Use the arrow keys to scroll in less, and press q to quit.

Copying, Moving, and Renaming Files

When organizing your project folders, you’ll often need to duplicate, move, or rename files.

CommandDescriptionExample
cp file1 file2Copy a filecp mesh.py mesh_backup.py
cp -r folder1 folder2Copy folders recursivelycp -r results/ archive_results/
mv file new_locationMove a file to another foldermv beam.py /mnt/d/simulations/
mv oldname newnameRename a filemv 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.

CommandDescriptionExample
rm filenameDelete a filerm temp.log
rm -r folderDelete a folder and its contentsrm -r old_study
rm -rf folderForce delete a folder (use with caution)rm -rf backup_old

Warning: The rm -rf command 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, and nano.
  • 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.