LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-07-2012, 11:04 PM   #1
Master_CAPS
Member
 
Registered: Mar 2012
Location: I live at ::1 usually...
Distribution: Yes.
Posts: 55

Rep: Reputation: Disabled
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

(make it accessible) terminal commands:
sudo chmod a=r /bin/cls
sudo chmod a+x /bin/cls

thats it! now whenever by whoever types cls they will be able to clear the screen. Enjoy windows users!
 
Old 03-08-2012, 12:55 AM   #2
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
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"
 
Old 03-08-2012, 02:25 PM   #3
Master_CAPS
Member
 
Registered: Mar 2012
Location: I live at ::1 usually...
Distribution: Yes.
Posts: 55

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rng View Post
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.
 
Old 03-08-2012, 02:31 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
Old 03-08-2012, 04:24 PM   #5
etech3
Senior Member
 
Registered: Jul 2009
Location: Virginia
Distribution: Debian Stable Testing Sid Slackware CentOS
Posts: 1,055
Blog Entries: 2

Rep: Reputation: 45
Thumbs up Plus one for bashrc

one of the first things I always tweak.

Code:
cd ~
Code:
nano -w .bashrc
add
Code:
alias cls=clear
at the end of your file and will work without the quotes in squeeze.

control x + y to save

to put in into use without logging out do

Code:
. .bashrc
that's one dot space dot bashrc

just my and that's all I got to say about that
 
1 members found this post helpful.
Old 03-19-2012, 09:46 AM   #6
Master_CAPS
Member
 
Registered: Mar 2012
Location: I live at ::1 usually...
Distribution: Yes.
Posts: 55

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by etech3 View Post
one of the first things I always tweak.

Code:
cd ~
Code:
nano -w .bashrc
add
Code:
alias cls=clear
at the end of your file and will work without the quotes in squeeze.

control x + y to save

to put in into use without logging out do

Code:
. .bashrc
that's one dot space dot bashrc

just my and that's all I got to say about that
lol wut?
 
Old 03-19-2012, 10:14 AM   #7
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
Another way to overcome this problem: type 'clear' 20 times on your keyboard. After that you will be typing 'clear' even in windows!
 
Old 03-19-2012, 01:06 PM   #8
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
why are you making it bit more complex when there is already an easy solution?
 
Old 03-19-2012, 01:13 PM   #9
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by rng View Post
Another way to overcome this problem: type 'clear' 20 times on your keyboard. After that you will be typing 'clear' even in windows!
I think this is the best answer.
I lose track of how many times I've typed 'ls' and 'rm' in Windows.
 
Old 03-19-2012, 01:52 PM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,608

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by Satyaveer Arya View Post
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.
 
Old 03-19-2012, 01:57 PM   #11
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by TB0ne View Post
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.
 
Old 03-19-2012, 01:59 PM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
1 members found this post helpful.
Old 03-19-2012, 02:25 PM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,608

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by 273 View Post
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.
 
Old 03-19-2012, 02:51 PM   #14
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
Old 03-19-2012, 03:11 PM   #15
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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)?
 
  


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
typing Faster Typing Tutor Maurice Arthur Ubuntu 3 12-14-2011 01:52 PM
tutorial for CLS charlie_lab Calculate 5 08-16-2010 05:15 AM
CLS to CLD? ManfredB Calculate 1 09-22-2009 02:55 PM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM

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

All times are GMT -5. The time now is 02:59 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