Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
As of course you can see i am new to all this. But my knowledge is growing as i learn more and more . My issue here is, i want to be able to make a command. For example i want to say make a command that does the same as clear but instead of typing clear, i can just type cls. Another example is run more than one command after another. Say rn the uptime command and than the netstat command. Can someone show me how to do this? thanks
The first is a simple alias. It gives one command a new name so you can type the alias to do the same thing. Under bash:
Then you can just type 'cls' and it will run clear.
This only lets you alias a single command though (afaik), for more complicated shortcuts you will have to create a script file.
Open a new text file and enter the following:
# This is a comment line
The first line tells linux to use the bash interpreter to read this file.
Save the file, named 'cls'
You now have to change the permissions so that it is executable:
chmod u+x cls
now you can type 'cls' and will execute that file. If you want to be able to execute it from anywhere, you have to copy it to somewhere that appears in your PATH variable.
Thats about it..... of course the script files can be as big as you like, and can take arguments and options just like all the regular command line programs. Script files are used in the linux system for all kinds of goodness, including the boot sequence etc etc.
If you mean you wrote the file, try './cls' if the current directory isn't on the path, either as 'current directory' or the full path. (And this assumes you remembered to make it executable.) If you created the alias from the prompt, I dunno what's wrong, unless you tried it in another xterm or terminal. To make the alias take effect generally, it needs to be in the bash configs. My ~/.bash_profile has
and ~/.bashrc is a symlink to it.
-- Oh, you can always do ctlrl-l in character mode and usually in a terminal emulator if that'd be easier.
instead, then it should work, if the executable permissions have been set. (Use ls -l to see the permissions.)
If this works, then the problem was that your PATH variable does not include the current directory, so it could not find the file.
to see the list of directories that will be searched, seperated by semicolons. You could try adding the current directory to the path variable:
and then try cls again (without the ./ in front) and it should find it.
Yeah - and not that it's that big of a deal but you might choose not to add the current directory to your path (marginal security issue) but create a directory to hold your scripts and put that on the path. I do that just so I can find them more easily if I need to edit them and keep up with what's what and so on.
Thanks for the help, i am guessing any scrips made in a directory other than the ones being searched have to have ./name in order for it to work, but as well as be in the directory of that script? I just made the script and than copied that script to the /usr/bin directory. The command you gave about the export PATH=$PATH, does that alow me to add a directory with all my scripts in there to be searched?
Well, . (a period by itself) to the shell is a
reference to the current directory ... so, if
you want to call the script using ./ you need
to be in the same directory ... you can, however,
reference it with ~/<name> if it lives in your
home, and it should work from where ever you
called it ...
.., btw, is a parent directory ... so if you were
in /usr/local/bin, and the script your're calling
were in /usr/bin you could do ../../bin/<name> :}