?
Solved

creating file in specified directory with one command

Posted on 2005-02-28
5
Medium Priority
?
197 Views
Last Modified: 2013-12-16
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
Comment
Question by:talktome_prashanth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 13426367
'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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 13427553
/bin/sh -c "touch '/path/to/specified directory/specified file'"
0
 
LVL 8

Expert Comment

by:marxy
ID: 13448686
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13449248
> echo > /where/you/want/file
being pedantic: this creates a non-empty file
you better use:
  cp /dev/null /where/you/want/file
0
 
LVL 8

Expert Comment

by:marxy
ID: 13449405
:-))) 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question