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.

  • 1
    @don_crissti +1 You should write this as an answer, as this is the best answer so far.
    – dr_
    Jul 7 '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 3:45

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 
  • This is common way, but I like use only one program to do this task. :)
    – glider
    Jul 13 '15 at 3:46

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'
mkdir "$1"
cd "$1"
touch "$2"
chmod a+x mkfdile

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.