LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-13-2012, 05:11 AM   #1
walecole
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Rep: Reputation: Disabled
"creating and alias"


how to create an alias that will create a file and add one string 'Hello'
 
Old 12-13-2012, 05:23 AM   #2
hamlindsza
Member
 
Registered: Aug 2012
Distribution: Debian, CentOS
Posts: 74

Rep: Reputation: Disabled
Hi,

To create an alias, you will need to make an entry in /etc/bash.bashrc

alias <alias-name>="<command>"

From what i understand you want an alias which will create a file and add the string Hello to it.

alias createfile="touch /path/to/file && echo "Hello" >> /path/to/file "
 
Old 12-13-2012, 05:27 AM   #3
walecole
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
am trying to create an alias that will create a file and add one string hello to tis same file i used ls -la command but it did not work,could you help me
 
Old 12-13-2012, 05:34 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,825
Blog Entries: 1

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
If you'd like an alias placed only for a particular user, use the following file:

Code:
~/.bashrc
which expands to /home/user/.bashrc

Please note that you do not necessarily have to use touch in the above example:

Code:
alias createfile="echo 'Hello' >> /path/to/file"


---------- Post added 13th Dec 2012 at 10:35 AM ----------

Quote:
Originally Posted by walecole View Post
am trying to create an alias that will create a file and add one string hello to tis same file i used ls -la command but it did not work,could you help me
Can you give an example?
 
Old 12-13-2012, 08:37 AM   #5
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: High Sierra
Posts: 8,599
Blog Entries: 15

Rep: Reputation: Disabled
Quote:
Originally Posted by walecole View Post
how to create an alias that will create a file and add one string 'Hello'
Code:
alias walecole="touch x ; echo "Hello" > x"
...

Code:
cat x
cat: x: No such file or directory
alias walecole="touch x ; echo "Hello" > x ; cat x"
walecole
Hello
cat x
Hello
 
Old 12-13-2012, 09:38 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,900
Blog Entries: 27

Rep: Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186Reputation: 2186
Member Response

Hi,
Welcome to LQ!
Quote:
Originally Posted by walecole View Post
how to create an alias that will create a file and add one string 'Hello'
Look at this post #5 which shows you how to use '.bashrc' and '.bash_profile for your user. Adding the suggested 'alias' by above members will be easier.
Quote:
Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide
10 Linux Home Networking
11 Virtualization- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
HTH!
 
Old 12-13-2012, 09:32 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
You don't need the touch cmd; the echo cmd will create the file when it writes to it.
 
1 members found this post helpful.
Old 12-14-2012, 09:26 AM   #8
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: High Sierra
Posts: 8,599
Blog Entries: 15

Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01 View Post
You don't need the touch cmd; the echo cmd will create the file when it writes to it.
Thanks Chris!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
"creating symbolic link" "operation not permitted" wheni Linux - Newbie 3 05-08-2011 02:36 AM
Need solution to "failed to fork PTY" and "error creating the child process" problems Gnusboy Linux - Newbie 4 01-02-2010 08:54 AM
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 08:26 AM
Creating "sub-projects" and multiple "targets" like in KDevelop ... obaidmushtaq Linux - Software 4 09-18-2009 01:10 AM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 03:07 AM

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

All times are GMT -5. The time now is 09:51 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration