Keeps typing CLS instead of clear? Well here is your fix...
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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Keeps typing CLS instead of clear? Well here is your fix...
if your a frequent windows user than you know what im talking about.
this a better way (and 'permanant') than alias cls="clear" (which only lasts one time).
open termianl and:
sudo gedit
type: clear
and save as cls to the bin directory
If we put following line in /home/user/.bashrc file or in /etc/rc.local file, will it work every time?
Code:
alias cls="clear"
Um I have heard that /.bashrc will store aliases, but I have never tried it my self...
I know if you do it my way than your less likely to overwrite/screw up an important file, and it ALWAYS WORKS with any user (root/guest/XXX etc...) just type "cls" (if your a newbie) I have screwed up my last Ubuntu by editing root read-only files before so.....
Last edited by Master_CAPS; 03-08-2012 at 02:27 PM.
You should probably be using .bashrc or .bash_profile for things like this. It's much easier to change, it requires no root access, and it doesn't force every user on the system to follow the same rules. What if another user on your system wants "cls" to do something different, such as "clear; ls"?
Just stick "alias cls='clear'" into your ~/.bashrc or ~/.bash_profile and you're done.
why are you making it bit more complex when there is already an easy solution?
And why are you posting this, without actually telling us what the easy solution is???
Even easier, just make a system-wide symlink: "ln -s clear cls". Creating a one-line shell script and doing a chmod on it is making it much more complex than it needs to be.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
Quote:
Originally Posted by TB0ne
And why are you posting this, without actually telling us what the easy solution is???
Even easier, just make a system-wide symlink: "ln -s clear cls". Creating a one-line shell script and doing a chmod on it is making it much more complex than it needs to be.
The easy way is using .bashrc
This may sound more complicated but it is doing it correctly and only for the user[s] you chnage it for. It also means that if/when you upgrade your system as long as you keep your home partition you'll still have the workaround in place. Added to that, if you ever decided to work with Linux for a living this would be the right way to do it as it doesn't need root access (in case you're not root) and doesn't mess things up for other users.
bashrc and the other startup files are simply collections of shell commands that are executed during initialization. Everything stored in them is, and has to be, just a command that could also be run directly in the shell.
The startup files load in a particular order, as detailed in the INVOCATION section of the bash man page. Generally the system-wide /etc files load first, followed by your own home directory counterpart of the same file. This allows you to override or modify any system defaults with the desired settings for your own user.
Most users usually end up making at least some minor modifications to their startup files, starting with some aliases and personalized prompts. There have been some threads here discussing what people have added to theirs. I personally have a long, highly modified bashrc with a large selection of aliases, a couple of dozen shell functions, a number of shell option settings, and some other tweaks to make things work for me.
So don't be afraid to make modifications, as the only thing you can really mess up is the file itself. The worst case scenario is that you'll end up with an unusable shell session, which isn't much of a problem if you make sure you keep a second working shell open until you get everything working, and have backups to revert to if necessary. Just make sure you understand the basics of shell scripting before doing anything major.
One more thing many people like to do is set up all of their aliases in a separate file, then add a single command to your bashrc to source that into it. This way you don't have to worry about constantly modifying the main file; just add any new aliases to that "alias" file.
Just add this to your bashrc (or similar), pointing to your alias file:
Code:
if [[ -f /path/to/aliasfile.txt ]]; then
. /path/to/aliasfile.txt
fi
The easy way is using .bashrc
This may sound more complicated but it is doing it correctly and only for the user[s] you chnage it for. It also means that if/when you upgrade your system as long as you keep your home partition you'll still have the workaround in place. Added to that, if you ever decided to work with Linux for a living this would be the right way to do it as it doesn't need root access (in case you're not root) and doesn't mess things up for other users.
I DO work with Linux/Unix for a living, thanks. I do the link command on systems I'm the administrator for, which is the ONLY way you can do it, since the clear command is "/usr/bin/clear"; standard users can't write to /usr/bin.
And how does it "mess things up for other users", by creating that symlink?? Doesn't affect the clear command in any way, and makes users who type in "cls" now, have it to work with, without having to remember anything. If you've got 200 users on a server, and you don't push out the same .bashrc to them, and the cls command works for SOME of the users, and not for others....you'll have lots of fun dealing with them. And if you DO put the changes into default profile/template profile, that essentially does the same thing as the "ln -s" command...ALL users get a cls alias.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
As long as your the only admin and you remember then of course it doesn't matter. It's also a very minor and practically rick free change. It seems like a strange thing to advise though since people may not want 'cls' aliased to 'clear' and if another admin comes along they may well break it anyhow.
The reason I advocate bashrc (or typing 'clear' 20 times) is because, to me at least, this is a personal preference and it would make me uncomfortable to recomend anyone make system wide chnages for preferences unless they knew what they were doing well enough to have worked it out for themselves.
Go ahead, do it, but don't expect the machine at the training centre, or the place you're visiting, or a remote machine to have it in place and tell your users not to use 'cls' in scripts for the same reasons.
Sorry, but I fail to see the whole point of this discussion. The command is cls on Windows and clear on Linux. Full stop. If you are not able to handle those two simple commands when you have to work on both systems, how do you handle more complex commands? Isn't it counterproductive to set it up that way (thinking that it tricks your brain to assume you are on a Windows machine when you actually are not, just because a few Windows commands work)?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.