IT Community - Software Programming, Web Development and Technical Support

Linux Tips & Tricks

This is a discussion on Linux Tips & Tricks within the Operating Systems forums, part of the Computer Hardware/Software and Networking category; I want to issue a "clearscreen" in or after a logout command so that the next login is ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Computer Hardware/Software and Networking > Operating Systems

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-22-2007, 07:27 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Thumbs up Linux Tips & Tricks

I want to issue a "clearscreen" in or after a logout command so that the next login is on a blank screen. How can I accomplish this?

Solution

I used to use an alias:

alias bye = "clear && exit"

Another viable solution, if you use the bash shell, I believe you can add the word "clear" on one line of your ~/bash_logout, and the screen will be cleared for you.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-22-2007, 07:30 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Thumbs up Re: Linux Tips & Tricks

If I'm idle for about 10 minutes, my screen turns black, how do I turn that off or start a screen saver?

Solution

To disable blanking for the text consoles: setterm -blank 0

To disable X server screen blanking: xset s off

To get a (great!) screensaver for X, install the xscreensaver package and
add the following to your ~/.xsession (for XDM) or equivalent for startx
(.xinitrc? not sure what Debian uses):

xset s off
xscreensaver &

These lines should precede the one that execs your window manager.
My .xsession is:

===========================
#!/bin/sh

xset s off
xscreensaver &
exec fvwm2

===========================
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-22-2007, 10:41 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Keep Logs Longer with Less Space.

Normally logs rotate monthly, over writing all the old data. Here's a sample "/etc/logrotate.conf" that will keep 12 months of backup compressing the logfiles

$ cat /etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
#chirico changes to monthly
monthly

# keep 4 weeks worth of backlogs
# keep 12 months of backup
rotate 12

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}

# system-specific logs may be also be configured here.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-22-2007, 10:43 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

SSH - How to Generate the Key Pair.

On the local server

$ ssh-keygen -t dsa -b 2048

This will create the two files:

.ssh/id_dsa (Private key)
.ssh/id_dsa.pub (Public key you can share)

Next insert ".ssh/id_dsa.pub" on the remote server in the file ".ssh/authorized_keys" and ".ssh/authorized_keys2" and change the permission of each file to (chmod 600). Plus, make sure the directory ".ssh" exists on the remote computer with 700 rights.Ok, assuming 192.168.1.155 is the remote server and "donkey" is the account on that remote server.

$ ssh donkey@192.168.1.155 "mkdir -p .ssh"
$ ssh donkey@192.168.1.155 "chmod 700 .ssh"
$ scp ./.ssh/id_dsa.pub donkey@192.168.1.155:.ssh/newkey.pub

Now connect to that remote server "192.168.1.155" and add .ssh/newkey.pub to both "authorized_keys" and "authorized_keys2". When done, the permission on (This is on the remote server)

$chmod 600 .ssh/authorized_key*

Next, go back to the local server and issue the following:

$ ssh-agent $SHELL
$ ssh-add

The "ssh-add" will allow you to enter the passphrase and it will save it for the current login session. You don't have to enter a password when running "ssh-keygen" above. But,remember anyone with root access can "su - <username>" and then connect to your computers. It's harder, however, not impossible, for root to do this if you have a password.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-22-2007, 10:45 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Convert Epoch Seconds to the Current Time. Note, some programs like Nagios list epoch seconds. Here's a way to do the conversion.


$ date -d "1970-01-01 1184521826 sec GMT"
Sun Jul 15 13:50:26 EDT 2007
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-22-2007, 10:46 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

emacs - commands in your ~/.emacs file to disable splash screen startup message.

;;disable splash screen and startup message
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-22-2007, 10:47 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

biosdecode - Querying the Bios from the command prompt.

This command can be executed as followed from root:

$ biosdecode

SYSID present.
Revision: 0
Structure Table Address: 0x000F0411
Number Of Structures: 1
SMBIOS 2.3 present.
Structure Table Length: 2570 bytes
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-22-2007, 10:49 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

cat - header, stdin, and footer. (Working with /dev/fd/0 or -)

If you have data from a command that you want preceded by the contents of a header file and followed by data in a footer file, then, the following command may help.

$ w|cat header /dev/fd/0 footer

Above the output of the "w" command follows the contents of the header file. Note "/dev/fd/0" refers to stdin. Yes, you could use "-" in its place in this situation. However, if "-" is used as the first argument, it will be interpreted as
as a command line option, whereas "/dev/fd/0" would not.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-24-2007, 01:34 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Bash Brace Expansion

$ echo f{ee,ie,oe,um}
fee fie foe fum

This works with almost any command

$ mkdir -p /work/junk/{one,two,three,four}
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-24-2007, 01:35 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

FTP auto-login. "ftp" to a site and have the password stored.

For instance, here's a sample ".net" file in a user's home
directory for uploading to sourceforge. Note, sourceforge will
take any password, so m@temp.com is used here for login "anonymous".

$ cat ~/.netrc
machine upload.sourceforge.net login anonymous password m@temp.com
default login anonymous password user@site

It might be a good idea to change the rights on this file

$ chmod 0400 ~/.netrc


#!/bin/bash
#
# Sample ftp automated script to download
# file to ${dwnld}
#
dwnld="/work/faq/unix-faq"
cd ${dwnld}
ftp << FTPSTRING
prompt off
open rtfm.mit.edu
cd /pub/usenet-by-group/news.answers/unix-faq/faq
mget contents
mget diff
mget part*
bye
FTPSTRING

Sourceforge uses an anonymous login with an email address as
a password. Below is the automated script I use for uploading
binary files.

#!/bin/bash
# ftp sourceforge auto upload ftpup.sh
# Usage: ./ftpup.sh <filename>
#
# machine upload.sourceforge.net user anonymous m@aol.com
ftp -n -u << FTPSTRING
open upload.sourceforge.net
user anonymous m@aol.com
binary
cd incoming
put ${1}
bye
FTPSTRING

(Also see TIP 114 for ncftpget, which is a very powerful restarting
ftp program)
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 08-24-2007, 01:37 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Less is More -- piping to less to scroll backword and forward

For large "ls" listings try the followin, then, use the arrow key
to move up and down the list.

$ ls /some_large_dir/ | less

or

$ cat some_large_file | less

or

$ less some_large_file
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 08-24-2007, 01:39 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Moving around Directories.
Change to the home directory:
$ cd ~
or
$ cd

To go back to the last directory
$ cd -

Instead of "cd" to a directory try "pushd" and look
at the heading...you can see a list of directories.

$ pushd /etc
$ pushd /usr/local

Then, to get back "popd" or "popd 1"

To list all the directories pushed on the stack
use the "dirs -v" command.

$ dirs -v
0 /usr/local
1 /etc
2 /work/souptonuts/documentation/theBook

Now, if you "pushd +1" you will be moved to "/etc", since
is number "1" on the stack, and this directory will become
"0".

$ pwd
/usr/local
$ pushd +1
$ pwd
/etc

$ dirs -v
0 /etc
1 /work/souptonuts/documentation/theBook
2 /usr/local



TIP 39:

Need an Underscore after a Variable?

Enclose the variable in "{}".

$echo ${UID}_

Compare to

$echo $UID_

Also try the following:


$ m="my stuff here"
$ echo -e ${m// /'\n'}
my
stuff
here
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 08-24-2007, 02:55 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Editing a Bash Command

Try typing a long command say, then, type "fc" for an easy way to edit the command.

$ find /etc -iname '*.cnf' -exec grep -H 'log' {} \;
$ fc

"fc" will bring the last command typed into an editor, "emacs" if
that's the default editor. Type "fc -l" to list last few commands.

To seach for a command, try typing "CTL-r" at the shell prompt for searching. "CTL-t" to transpose, say "sl" was typed by you want "ls".

Hints when using "fc: in emacs:

ESC-b move one word backward
ESC-f move one word forward
ESC-DEL kill one word backward
CTL-k kill point to end
CTL-y un-yank killed region at point
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 08-24-2007, 02:57 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Getting a List of User Accounts on the System

$ cut -d: -f1 /etc/passwd | sort

Note (Thanks to Philip Vanmontfort) you can also do the following:

$ getent passwd|cut -d: -f1|sort
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 08-24-2007, 02:58 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Bash Brace Expansion

$ echo f{ee,ie,oe,um}
fee fie foe fum

This works with almost any command

$ mkdir -p /work/junk/{one,two,three,four}
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 08-24-2007, 02:59 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Need to Find the Factors of a Number?

$ factor 2345678992
2345678992: 2 2 2 2 6581 22277

It's a quick way to find out if a number is prime

$ factor 7867
7867: 7867
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 08-24-2007, 11:08 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Keeping Files in Sync Between Servers.

The remote computer is "192.168.1.171" and has the account "donkey". You want to "keep in sync" the files under "/home/cu2000/Logs" on the remote computer with files on "/home/chirico/dev/MEDIA_Server" on the local computer.

$ rsync -Lae ssh donkey@192.168.1.171:/home/cu2000/Logs /home/chirico/dev/MEDIA_Server

"rsync" is a convient command for keeping files in sync, and as shown here will work through ssh. The -L option tells rsync to treat symbolic links like ordinary files.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 08-24-2007, 11:09 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Looking up the Spelling of a Word.

$ look <partial spelling>

so the following will list all words that start with stuff

$ look stuff
stuff
stuffage
stuffata
stuffed
stuffender
stuffer
stuffers
stuffgownsman
stuffier
stuffiest
stuffily
stuffiness
stuffinesses
stuffiness's
stuffing
stuffings
stuffing's
stuffless
stuffs
stuffy

It helps to have a large "linuxwords" dictionary. You can download
a much bigger dictionary from the following:

SourceForge.net: Downloading ...

Note: vim users can setup the .vimrc file with the following. Now when you type
CTL-X CTL-T in insert mode, you'll get a thesaurus lookup.

set dictionary+=/usr/share/dict/words
set thesaurus+=/usr/share/dict/words

Or, you can call aspell with the F6 command after putting the folling entry in your .vimrc file

:nmap <F6> :w<CR>:!aspell -e -c %<CR>:e<CR>

Now, hit F6 when you're in vim, and you'll get a spell checker.


There is also an X Windows dictionary that runs with the following command.

$ gnome-dictionary
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 08-24-2007, 11:12 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Find out if a Command is Aliased.

$ type -all <command>

Example:

$ type -all ls
ls is aliased to `ls --color=tty'
ls is /bin/ls
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 08-24-2007, 11:14 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Linux Tips & Tricks

Create a Terminal Calculator

Put the following in your .bashrc file

function calc
{
echo "${1}"|bc -l;
}

Or, run it at the shell prompt. Now "calc" from the shell will work as follows:

$ calc 3+45
48

All functions with a "(" or ")" must be enclosed in quotes. For instance, to get the sin of .4

$ calc "s(.4)"
.38941834230865049166
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# .Net Tips & Tricks oxygen C# Programming 85 01-08-2009 01:25 AM
SAP Tips & Tricks leoraja8 Operating Systems 0 03-29-2008 01:11 AM
Digital Photo Management In Linux Tips and Tricks Sabari Server Management 5 12-01-2007 03:15 AM
.NET tricks & Tips Karpagarajan VB.NET Programming 1 04-23-2007 09:17 AM
SEO Tips & Tricks spid4r Search Engine Optimization 0 03-09-2007 12:03 AM


All times are GMT -7. The time now is 01:43 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.