4

I know this problem can solve by use combine mkdir and touch commands. But I want to know is there any other solution only use one command.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
glider
  • 41
  • 1
  • 4
  • 1
    @don_crissti +1 You should write this as an answer, as this is the best answer so far. – dr_ Jul 07 '15 at 13:49
  • @don_crissti Why you don't write this as an answer ? I will accept this is the best answer. :D Thank you! – glider Jul 13 '15 at 03:45

2 Answers2

2

I think it's best to use a combination like this. I'm not aware that there is a special purpose command for this.

mkdir -p dict_to_create  # -p forces create of non-existent parent dirs
touch dict_to_create/foo.txt # touch to create the file,
                             # could use -f (force) Read, man touch 
X Tian
  • 10,413
  • 2
  • 33
  • 48
cb0
  • 121
  • 3
0

There are two arguments , directory name and file name. I could not think of any such command, but you can create a short script and place it in your /usr/local/bin.

cat > mkfdile  <<'EOF'
#!/bin/bash
mkdir "$1"
cd "$1"
touch "$2"
EOF
chmod a+x mkfdile

I assume you need this because you want to call this from with-in another script.

roaima
  • 107,089
  • 14
  • 139
  • 261
Aaghaz
  • 1