首页 > 系统相关 >PSYCH 727 shell 实现

PSYCH 727 shell 实现

时间:2023-04-27 15:22:27浏览次数:36  
标签:shell course cd will 727 PSYCH file directory


LAB 1 (S1, 2023)
OUTLINE FOR THIS LAB
The purpose of this laboratory session is to familiarise you with the Linux
environment and the shell, MATLAB, and the data we are working with (fMRI
images).
Today we will cover:
1. Setting Up Remote Access to the Lab VM
2. Linux file structure
3. Introduction to Linux and the Shell
4. Introduction to MATLAB
5. Introduction to MRI data
1. SETTING UP REMOTE ACCESS TO THE LAB VM
To begin, we have to access the Virtual Machine (VM) we have set up for storing and analysing
data in this course. To do so, follow these steps:
Open x2go
Enter the following settings for your session
o Host = fospsychprd01.its.auckland.ac.nz
o Session type = XFCE
Log into your session with your UoA password
2
Open a Terminal Window (look for the computer screen icon at the top of your VM
session)
2. LINUX FILE STRUCTURE
/ (root)
bin course home
rrob042 jblo001
At the top of the file structure in Linux is the root directory that holds everything else. We refer
to it using a slash character / on its own; this is the leading slash in for instance the following
path: /home/rrob042.
The home directory path looks different on different operating systems. On Linux it looks like
e.g. /home/rrob042, whereas on Windows it would be C:\Users\rrob042. When you start
the shell, you are in your home directory by default, but for this course we will actually not
work in our home directories (we will work in /course, see below).
Inside the root directory are several other directories, such as bin, which is where some built-
in programs are stored. We have created another directory called course to store all course
materials.
/
(root)
bin course home
Data Software UserFolders
3
$
$ whoami
rrob042
dadd001 rrob042
In course there are several folders: Data, install, Software, and UserFolders. Inside
UserFolders you will find a directory that is named after your UPI; this is the directory in which
you will be working during this course. So instead of e.g. /home/rrob042 we will be working
in /course/UserFolders/rrob042.
3. INTRODUCTION TO THE LINUX SHELL
Linux is an open source operating system that was developed in the mid-1990s. It is a
powerful tool as you can do complex things with a few keystrokes. It is very useful for
neuroimaging where we have thousands of files per participant (e.g., you can rename all files
with one command).
The “shell” (also known as “bash”) is the way in which the user communicates with the
computer. We type commands into the shell, the shell “translates” these commands and orders
the computer to execute the command (usually to run a programme or “script”). It is called a
“shell” because it encases the complexities of the operating system so it is easier to interact
with.
Basic Shell Commands: Navigation
The part of the operating system responsible for managing files and directories is called the
file system. It organizes our data into files, which hold information, and directories (also
called “folders”), which hold files or other directories.
Several commands are used to create, inspect, rename, and delete files and directories.
To start exploring them, we will use a shell window:
The dollar sign (or another character) is a prompt, which shows us that the shell is waiting
for input; your shell may also add information (e.g., your user name) before the prompt. When
typing in commands listed here, do not type the prompt, only the commands that follow it.
Type the command whoami, then press the Enter key to send the command to the shell. The
command’s output is the ID of the current user, i.e., it shows us who the shell thinks we are:
When we type whoami, the shell:
finds a program called whoami,
runs that program,
displays that program’s output, then
displays a new prompt to tell us that it’s ready for more commands.
4
$ pwd
/Users/rrob042
$ ls
Desktop media
$ cd Desktop
$ cd rrob042
-bash: cd: rrob042: No such file or directory
$ cd ..
$ pwd
/Users/rrob042
Next, let’s find out where we are by running a command called pwd (which stands for “print
working directory”). At the moment, our current working directory is our default directory, i.e.,
the home directory. Here, the computer’s response is /Users/rrob042, which is my home
directory:
Now let’s learn the command that will let us see the contents of our own filesystem. We can
see what’s in our home directory by running ls, which stands for “listing”:
Now we can change our location to a different directory, so we are no longer located in our
home directory. The command to change locations is cd followed by a directory name to
change our working directory. cd stands for “change directory”, which is a bit misleading:
the command doesn’t change the directory, it changes the shell’s idea of what directory we
are in.
Let’s say we want to move to the Desktop. We can use the following command to get there:
We now know how to go down the directory tree: how do we go up? We might try:
Why do we get this error? With our methods so far, cd can only see sub-directories inside your
current directory. There are different ways to see directories above your current location; we’ll
start with the simplest.
There is a shortcut in the shell to move up one directory level that looks like this:
As mentioned above, .. is a special directory name meaning “the directory containing this one”,
or more succinctly, the parent of the current directory. If we run run cd .. and then type pwd,
we’re back in /Users/rrob042:
So far, when specifying directory names we have been using relative paths. When you use a
relative path with a command like ls or cd, it tries to find that location from where we are,
rather than from the root (beginning) of the file system. However, it is possible to specify
the absolute path to a directory by including its entire path from the root directory, which is
indicated by a leading slash (see section 2). The leading / tells the computer to follow the path
5
$ cp -r /course/labs/Lab1 /course/UserFolders/UPI
from the root of the file system, so it always refers to exactly one directory, no matter where
we are when we run the command.
Now we will copy a directory for this lab into our won personal directories in
/course/UserFolders. This directory contains a single anatomical MRI image that we will be
using in this lab.
6
$ matlab
Current working directory
Workspace
(variable list)
Contents of
current directory
History of
commands
Command window
cd /course/UserFolders/UPI
spm fmri
INTRODUCTION TO MATLAB
To start MATLAB just type matlab into the shell:
In the Command Window or shell we can run and debug our code. You can use all the basic
shell commands from section 1 (cd, ls, etc.) in the MATLAB shell.
INTRODUCTION TO MRI DATA
Let’s explore some real brain data.
Running SPM
Make sure you are in the right directory (in this case, the directory containing anat.nii is
probably a good place, but it might the directory for the subject or the study):
Open SPM:
7
A note about image file types.
DICOM (Digital Imaging and Communications in Medicine) format. Raw data from the scanner;
must be converted to Analyze or nifti format for analysis.
Analyze format. Each image has two files: .hdr (header file containing metadata) and .img (the
actual image).
Nifti (Neuroimaging Informatics Technology Initiative) format. In this format, images can be
stored in the two file presentation (.hdr/.img) or a one file presentation (.nii). A critical advance over
Analyze format is that nifti files store the orientation of the image in an unambiguous manner.
Moreover, time can be included as a fourth dimension.
For more information, see https://brainder.org/2012/09/23/the-nifti-file-format/
8
A note about xyz coordinate systems.
xyz coordinates refer to the location of any given voxel (3D pixel) or element in the 3D image/matrix.
However, there are two types of “spaces” or coordinate systems when dealing with MRI images:
voxel space and world space (or mm space). Below is a 2D example of each coordinate system.
You will notice that all the values in voxel space are positive, while world space includes positive and
negative values (relative to the “origin” or the coordinate, 0 0 0).
Display
In the GUI (Graphics User Interface) for SPM, click
on ‘Display’, and select the ‘anat.nii’ file to view the
structural image. You should see the following
image:
Exercise:
Images are actually just 3D matrices of numbers: each value in the matrix corresponds to an
intensity value of a voxel in the brain.
If you click anywhere on the image, you will see that below the coordinates will update as well
as the intensity value. Using this knowledge, complete the following table:
Coordinates (world space) Intensity Value Observations
31 -19 -17
-32 -59 14
31 41 -46
-60 41 66
5 11 7
9
Linux Commands
Command Operation Performed Example
. Current location
.. Up 1 directory from current location
--help provides info about a certain command cd--help
cd Change directory cd spm/subject1
cd ../ Change directory one up cd ../subject2
pwd Present working directory
ls List contents of current directory
ls -l List contents with details of all files
ls | more List contents at a user specified rate
cp Copy file to another directory cp input_file new location
cp 001.img ../subject2
Copy but give another name cp input_file output_file
cp 001.img func.img
Copy file to another directory AND give it
another name
cp input_file new
location/output_file
cp 001.img ../subject2/func.img
cp -r Copy whole directory cp -r input_dir output_dir
cp -r subject2 subject2_backup
mv Move a file (can be used to rename file) mv input_file output_file
mv 001.img func.img
Move file to another directory (i.e. "Cut and
paste" file)
mv input_file new location
mv 001.img ../subject2
more View the contents of a file more timings.txt
rm Remove file (delete) rm 001.img
rm -r (or rmdir) Remove directory rm -r subject1
cat Create a file (e.g. a text file) cat file_name.txt
cat timings.txt
* Wildcard *.* = all files e.g. cp *.*
*.img = all files with img as
extension
subj* = all files starting with
string "subj"
top Lists current users and activity on server
df -k
Gives memory capacity remaining on your
dir
emacs Opens a text editing program
emacs *.txt
Opens a text editing program with a file
name
emacs file_name.txt
emacs Timing_Files.txt
^c Cancel
exit Exit
mkdir mkdir (in current location) mkdir new_dir_name
rename Renaming rename test subj1_test
Renaming multiple files if needed rename test subj1_test test*
More linux commands are available here: http://linuxcommand.org/

 WX:codehelp

标签:shell,course,cd,will,727,PSYCH,file,directory
From: https://www.cnblogs.com/mondayw/p/17359006.html

相关文章

  • Linux shell regular expression All In One
    LinuxshellregularexpressionAllInOneLinuxshell正则表达式demos(......
  • Powershell 日常
    0x01环境变量#listPS>lsenv:#setPS>$env:_JAVA_LAUNCHER_DEBUG=1#unsetPS>delenv:_JAVA_LAUNCHER_DEBUG0x02Profile~$$profileC:\Users\xxx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1~$type$profile#Truncateho......
  • 代码区添加shellcode
    //p44.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include<windows.h>#include<malloc.h>#defineShellCodeIen0x12#defineMessageBoxAdder0x77D507EABYTEShellCode[]={0x6A,00,0x6A,00,0x6A......
  • MSSQL2K - SQL Injector - Query String Parameter Attack结合netcat获得反向cmdshell
    fasttrack操作:root@bt:~#cd/pentest/exploits/fasttrack/root@bt:/pentest/exploits/fasttrack#./fast-track.py-i******************************************************Performingdependencychecks...******************************************************......
  • MSSQL2K - SQL Injector - Query String Parameter Attack获得反向cmdshell
    上次没有成功获得cmdshell,因为fasttrack没有这方面的代码,这次编写了server.py。importsocketHOST=''PORT=4444s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.bind((HOST,PORT))s.listen(1)conn,addr=s.accept()cmd="\n"try:whileTrue:......
  • shell脚本开机自启动运行
    准备需要启动执行的shell。例如:-PC:~$sudoviauto-start-shell.sh#!/bin/bashecho"系统启动shell自动运行时间:$(date)">>/home/{用户名}/Desktop/ceshi/cs.txtexit方案1:1、创建脚本启动文件。-PC:~$sudoviauto-start-shell.desktop[DesktopEntry]Encoding=......
  • shell脚本找出不过期的redis key
    1#!/bin/bash2#Redis通过scan找出不过期的key3#SCAN命令是一个基于游标的迭代器(cursorbasediterator):SCAN命令每次被调用之后,都会向用户返回一个新的游标,用户在下次迭代时需要使用这个新游标作为SCAN命令的游标参数,以此来延续之前的迭代过程。4#注意:当S......
  • 40 个简单又有效的 Linux Shell 脚本示例 转载
    1.HelloWorld程序员经常通过学习helloworld程序来学习新语言。这是一个简单的程序,将字符串“HelloWorld”打印到标准输出中。然后,使用vim或nano等编辑器创建hello-world.sh文件,并将以下行复制到其中。#!/bin/bashecho "Hello World"保存并退出文件。接下来,您需要......
  • Kali系统 连接 Xshell
    1>进入kali系统,修改ssh配置文件:vi/etc/ssh/sshd_config2>将PermitRootLoginwithout-password修改为:PermitRootLoginyes快速查找::setnumber/PermitRootLogin3>找到#PasswordAuthenticationyes把#的注释去掉快速查找::setnumber/PasswordAuthentication......
  • shell编程总结
    一,执行shell程序文件有三种方法(1)#shfile(2)#.file(3)#sourcefileshell常用的系统变量$#:保存程序命令行参数的数目$?:保存前一个命令的返回码$0:保存程序名$*:以("$1$2...")的形式保存所有输入的命令行参数$@:......