LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2020, 09:10 PM   #1
justin12
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Rep: Reputation: Disabled
How to create files in a shell script


Hello I am new to linux and was wondering how i would create files from a script. I created a shell script using nano. And i am trying to add different files inside the script.What would the command look like. I have used touch ../..filename and have got no success.
 
Old 10-10-2020, 09:19 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
First, review a tutorial or two on paths so you know where you are putting the file(s). Then you can use redirection to steer the output from one program, or chain of programs, into a file.

What does your script look like so far? Please use [code] [/code] tags to preserve indentation as you post it.
 
Old 10-10-2020, 09:42 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
What is with the ../.. part?

https://phoenixnap.com/kb/how-to-create-a-file-in-linux

Use these ideas in inside script but remember that not all commands can come and go out of a script.
 
Old 10-10-2020, 09:44 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by justin12 View Post
I have used touch ../..filename and have got no success.
This creates a file with the rather unusual name ..filename in the parent directory. What do you mean by "no success" - was there an error message? What did you do to check success? Note that files whose names start with a dot are not listed by the ls command, unless you add the -a option.
 
1 members found this post helpful.
Old 10-10-2020, 09:44 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by justin12 View Post
I have used touch ../..filename and have got no success.
This creates a file with the rather unusual name ..filename in the parent directory. What do you mean by "no success" - was there an error message? What did you do to check success? Note that files whose names start with a dot are not listed by the ls command, unless you add the -a option.
 
1 members found this post helpful.
Old 10-11-2020, 03:25 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by justin12 View Post
I have used touch ../..filename and have got no success.
Show us the actual code, what you want to achieve, and why/how it fails.
Use CODE tags for code (see my signature).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Create a Shell Script from Other Shell Script? prravin1 Programming 3 03-29-2012 03:29 PM
Need to create a shell script that copies all files owned by a user BrainOfSweden Linux - Newbie 9 09-28-2011 07:22 AM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 03:05 AM
Help: Create a shell script to move only files wich has stopped growing proxmity Linux - Newbie 8 07-28-2009 12:40 PM
How to create/delete temp/backup files through a shell script ? Sid2007 Programming 4 10-17-2007 01:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration