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 05-08-2014, 07:33 PM   #1
ebasika
LQ Newbie
 
Registered: May 2014
Posts: 2

Rep: Reputation: Disabled
User Defined Commands in Linux


Hi! Can you please help with creating user defined commands. For example I need to get to a subdirectory $home/dev/server/tra/app/logs by just typing a user defined command ie logs . Thank you.
 
Old 05-08-2014, 07:46 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
Hello and welcome to LQ.
What you describe is in Linux called an alias. For your example you would type[code]alias logs="cd $home/dev/server/tra/app/logs" on the cxommandline. Now every time you launch the command logs you will be automatically taken to the directory you specified in the alias command. If you want to have this persistent, so that you don't have to define it every time you launch a command line, add the command to your ~/.bashrc file (or its counterpart if you use a different shell than Bash).
 
2 members found this post helpful.
Old 05-08-2014, 08:00 PM   #3
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,959

Rep: Reputation: Disabled
There are many ways to skin this cat, a little script will do it, too.
 
1 members found this post helpful.
Old 05-08-2014, 08:18 PM   #4
ebasika
LQ Newbie
 
Registered: May 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Awesome. Thanks for your swift reply.
 
Old 05-08-2014, 09:15 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,132
Blog Entries: 14

Rep: Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067Reputation: 3067
Here's a nice reference on creating an alias: http://publib.boulder.ibm.com/infoce..._cmd_alias.htm

A web search for "create alias linux" will turn up many more useful links.
 
Old 05-09-2014, 12:04 AM   #6
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Rep: Reputation: 39
Quote:
Originally Posted by Emerson View Post
There are many ways to skin this cat, a little script will do it, too.
+1 for a script as well. Scripts are easier to keep track of.
 
Old 05-09-2014, 09:36 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,399

Rep: Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486Reputation: 1486
An alias or a shell function can change the working directory of the current shell. A script invoked in the normal way runs in a subshell and cannot do a cd for the parent shell. You would have to remember to source the script to do that, or else continue running interactively in that subshell and remember to type "exit" to get back to your original shell.
 
  


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
User defined linux commands in a user defined shell Sushma05 Linux - Newbie 3 09-13-2013 07:21 AM
how to send user defined signal in linux feetyouwell Linux - Software 6 12-26-2007 04:40 AM
user defined shell commands ashley_31 Linux - Software 11 05-15-2006 03:27 AM
how to define user-defined commands in linux mannoulla Linux - General 1 04-05-2005 09:01 PM


All times are GMT -5. The time now is 09:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration