-
Notifications
You must be signed in to change notification settings - Fork 0
Linux bash tips and tricks
Mehul Gajwani edited this page Aug 6, 2024
·
1 revision
- You should be familiar with the bash syntax discussed in Andy's Brain Book (see Linux-and-bash-scripting).
- One more important thing to add to that content is the use of wildcards. We suggest this tutorial.
- A nice cheat-sheet with reminders of simple commands can be found here
- For some more complex scripting commands, see reminders here.
Many pipelines (e.g. AFNI) require you to manually set up some information (e.g. where subject data is located or where files are installed) before they can be run. This is done by defining variables which can be easily accessed by sub-processes. Have a look at this tutorial for how export works.
Whilst using bash, you will commonly see two alternatives for running commands: > ./myscript ('executing') and > source myscript ('sourcing'). The difference is:
- When you execute the script you are opening a new shell, type the commands in the new shell, copy the output back to your current shell, then close the new shell. Any changes to environment will take effect only in the new shell and will be lost once the new shell is closed.
- When you source the script you are typing the commands in your current shell. Any changes to the environment will take effect and stay in your current shell.
- Highlighting text will copy it automatically
- Middle button of mouse will paste
- Otherwise use Edit – COPY/PASTE if you don’t have a middle button
- Or Ctrl + Shift + C to copy and Ctrl + Shift + V to paste
- Ctrl + C will cancel any code you’re currently running
- Ctrl + A will move to the start of the line, Ctrl + E to the end
- Tab key = Auto-complete (e.g., if I want to open a directory titled ‘FreeSurfer’, typing
cd Freethen pressing tab will fill incd FreeSurfer- VERY useful)- If there are multiple possible options, press the Tab key twice to see all the options
- Arrow up/down key to check previous commands (also very useful)
- Including an ampersand (
&) at the end of your command will cause that command to run in the background. Otherwise, your terminal will display the entire process as it runs and wait until the command is finished before letting you run another command. However, not including an & doesn't mean you can't open a second terminal while your command runs tethered in the first terminal.
-
forloops run everything SERIALLY- This means you need to wait for the first value in the loop to finish running before the next value will run.
- Basically, everything runs one at a time, which can be slow in some bigger datasets.
- To run everything in PARALLEL, consider using a job array in SLURM.
- Useful management command that will return the file storage quotas on kg98 or the disk usage amounts of your current directory
> user_info> du –csh
- 0.0 Home
- 0.1 Neuroscience fundamentals
- 0.2 Reproducible Science
- 0.3 MRI Physics, BIDS, DICOM, and data formats
- 0.4 Introduction to Diffusion MRI
- 0.5 Introduction to Functional MRI
- 0.6 Measuring functional and effective connectivity
- 0.7 Connectomics, graph theory, and complexity
- 0.8 Statistical and Mathematical Tidbits
- 0.9 Introduction to Psychopathology
- 0.10 Introduction to Genetics and Bioinformatics
- 0.11 Introduction to Programming
- 1.0 Working on the Cluster
- 2.0 Programming Languages
- 2.1 Python
- 2.2 MATLAB
- 2.3 R and RStudio
- 2.4 Programming Intro Exercises
- 2.5 git and GitHub
- 2.6 SLURM and Job Submission
- 3.0 Neuroimaging Tools and Packages
- 3.1 BIDS
- 3.2 FreeSurfer
- 3.2.1 Qdec
- 3.3 FSL
- 3.3.1 ICA-FIX
- 3.4 Connectome Workbench/wb_command
- 3.5 fMRIPrep
- 3.6 QSIPrep
- 3.7 HCP Pipeline
- 3.8 tedana
- 4.0 Quality control
- 4.1 MRIQC
- 4.2 Common Artefacts
- 4.3 T1w
- 4.4 rs-fMRI
- 5.0 Specialist Tools
- 6.0 Putting it all together
- 7.0 Data management