Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

creating file in specified directory with one command

Hi,

Just by using one single step or command can we create a file in a specified directory?

The only command we have access is /bin/sh and is running as a root but (there is a sideway that /bin/bash can use scripts--note scripts NOT in separate file but scripts  like typed after /bin/bash command )


eg:

#/bin/sh        blah blah blah                      ------------------ this must create a specified file in a specified directory.


Thank You,
Prashanth
0
talktome_prashanth
Asked:
talktome_prashanth
  • 2
  • 2
1 Solution
 
jlevieCommented:
'touch /path-to/some-file' will create an empty file.

cat >/path-to/some-file <<EOF
First line
Second line
...
EOF

will place "First line", "Second line", etc in the file.
0
 
ahoffmannCommented:
/bin/sh -c "touch '/path/to/specified directory/specified file'"
0
 
marxyCommented:
To create a file not using another commands You can use 'echo' of shell.

Example:
   echo > /where/you/want/file

echo is not a utility. that's a shell command. and it doesn't need something else but /bin/sh
0
 
ahoffmannCommented:
> echo > /where/you/want/file
being pedantic: this creates a non-empty file
you better use:
  cp /dev/null /where/you/want/file
0
 
marxyCommented:
:-))) LOL ahoffman

cp is an external command
that's at first.

nobody said about empty.
that's at second.

using echo is an exact solution.
that's at third.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now