🧠
BRIDGE Lab Documentation
  • BRIDGE Lab Documentation
  • 📘General
    • About Us
    • Onboarding
      • First Steps
      • Research Specialist Training
      • Project Coordinator Training
    • Misc
      • How to do misc things
      • Burning Scans to a Disc
      • Setting Up Meetings in the Conference Room
      • Printing
    • Imaging Glossary
  • 🖇️Admin
    • Ourday
    • Training
    • Regulatory
    • Social Media
    • REDCap
      • Archiving REDCap Projects
  • 🖥️Tech
    • Setting Up Meetings in the Conference Room
    • Effective Troubleshooting
    • Remote Work Resources
    • Arthur
    • Servers
      • Connecting to an External Server
    • Bash 101
      • What is Bash?
      • Bash Examples
      • How to add elements to your bash profile
    • git and Github
  • 🩻Image Acquisition
    • ViSTa
  • 🗃️Data Organization
    • BIDs Data Formatting
    • MRI Data Organization
  • 🖼️Image Analysis
    • Image QC
      • Raw Data QC
        • Diffusion QC
        • T1/T2 QC
        • ViSTa QC
        • Spectroscopy QC
      • PyDesigner QC
    • Project Lifecycle
    • General Concepts
    • Raw Data
    • Preprocessing
      • Denoising UNI MP2RAGE Images
      • PyDesigner
      • ViSTa
    • Native Space Analysis
      • TractSeg
        • TractSeg + Within-Subject Registration
      • Segmentation
        • LST
        • Freesurfer
        • NOMIS
    • Registration
      • DTI-TK
      • TBSS
      • Coordinate Systems
    • Other Pipelines
    • Archiving
  • 📊Data Viz and Stats
    • Plotting in R
  • 📚Imaging Library
Powered by GitBook
On this page
  1. Tech
  2. Bash 101

Bash Examples

For example, if you want to copy a file, try using cp [/path/to/file.fileextention] [/new/file/location/file.fileextension] – you will replace the first path with the current file location and the second path with location you’d like your file to be.

Other useful commands that work with similar logic are rm (which will delete a file or folder you specify) and mv (which will move a file or folder you specify). Be careful with these as they will permanently change the file you give them.

I also recommend trying to accomplish simple tasks via bash by web searching how to do the tasks. For example “how to open text files with bash” or “how to delete all files with a specific file extension in bash”, etc.

Logical loops may also be useful to you. These will allow you to carry out commands across numerous files or folders depending on specific logic.

For example, say you have a dataset of diffusion data across numerous subjects and you want to preprocess all of the subjects with a single command. You could take your base command and put it inside of a for loop. Recall the PyDesigner command example from 01_Diffusion_Image_Analysis_101. If we wanted to execute that command across numerous subjects, we could set up a for loop that looks like this:

for ID in Subj1 Subj2 Subj3 ; do

pydesigner --denoise --degibbs --mask -w --force /desktop/user/PyDesigner-

Example/${ID}/nifti/DKI.nii, /desktop/user/PyDesigner-

Example/${ID}/nifti/B0.nii -o /desktop/user/PyDesigner-

Example/${ID}/pydesigner

done

Let’s walk through this command:

The first line contains the following elements:

“for” – this indicates that the following commands are going to be executed for every unit in a list

“ID” – this is a chosen variable that will stand in for each unit in the following list; this can be whatever you want. For this example, I chose “ID” to indicate that it will stand in for a list of subject IDs

“in” – this indicates that the list of items that will be affected by the commands is about to begin

“Subj1 Subj2 Subj3” – this is an example list of my subject names; this list could theoretically be a list of any series; no commas are necessary to distinguish one unit from another, spaces will do that.

“do” – this indicates that what comes next is the actual command

The indented set of lines is the actual command that will be executed based on the for loop you’ve set up above.

The important takeaway from this is the “${ID}” element. The dollar sign and brackets around our “ID” variable name tell the command that it will be iteratively going through a list we specified (Subj1 Subj2 Subj3)

For example, the command is going to take the path we’ve given it /desktop/user/PyDesigner-Example/${ID}/nifti/DKI.nii and it will sub in each unit in our list for the “${ID}” element by looking for the following paths:

/desktop/user/PyDesigner-Example/Subj1/nifti/DKI.nii

/desktop/user/PyDesigner-Example/Subj2/nifti/DKI.nii

/desktop/user/PyDesigner-Example/Subj3/nifti/DKI.nii

This is extremely same process will be carried out for the entire command so that each subject is processed through PyDesigner using only the single command within the for loop

“done” tells the for loop to close and run the commands wrapped inside of it.

Last updated 1 year ago

🖥️