如何编写和执行将创建目录和.txt文件的脚本

时间:2018-01-11 15:35:00

标签: linux

我正在尝试在文件夹中创建文本文件。在Linux shell中运行我的代码(Create_txt_files)时,我得到的是以下错误:

e@01:/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/study_scripts/eric_scripts$ . Create_txt_files**

bash: /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data: **Is a directory**

bash: /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL: **No such file or directory**

bash: /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1: **No such file or directory**

此错误代码还有大约9行。我知道在第一个错误代码之后的行中有“没有这样的文件或目录”,但这是因为这些目录没有被创建。我的代码如下,用于编写必要的文件夹:

# Location of Subject
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data mkdir emsintTESTFSL

# Make session1 & session2 folders
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL mkdir session1 session2

# Make control, exper1, & exper2 folders
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1 mkdir control exper1 exper2

# Create CONTROL files
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control mkdir run1 run2
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run1
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run1 touch correct.txt
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run1 touch incorrect.txt
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run1 touch missing.txt

/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run2
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run2 touch correct.txt
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run2 touch incorrect.txt
/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL/session1/control/run2 touch missing.txt

我相信我在linux shell中错误地执行了我的代码。我通过在其指定的路径中键入“.Create_txt_files”来执行它。

1 个答案:

答案 0 :(得分:1)

您希望首先“cd”到目录或将其包含在“mkdir”命令中。与“触摸”相同

cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data 
mkdir emsintTESTFSL

or

mkdir /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsintTESTFSL