agraja.wordpress.com

Posts Tagged ‘Linux’

Syntax Highlight For System Verilog Files

In Shell, SystemVerilog, Verilog on September 19, 2008 at 5:02 am

Enable syntax highlight for sytemm verilog, verilog preprocessor files with extensions v, sv, vpp, svh, svhpp

Create a file named “.vimrc” in your home directory [*nix]

Put the following lines in that file

“File Begins here

“Note: Comments in vim script begin with double quote

“Filename : .vimrc

“Author    :  A.G.Raja

“Website  : http://agraja.wordpress.com

“Show line numbers

set nu

“Source the syntax file

so $VIMRUNTIME/syntax/verilog.vim

“Add file extensions to be highlighted

au Syntax sv runtime! syntax/verilog.vim

au Syntax svh runtime! syntax/verilog.vim

au Syntax vpp runtime! syntax/verilog.vim

au Syntax svpp runtime! syntax/verilog.vim

au Syntax svhpp runtime! syntax/verilog.vim

“End of file

Linux Desk Calculator

In Linux on October 5, 2007 at 4:08 am

Terminal command to perform arithmetic operations

dc [OPTION] [file ...]

-e    –expression=EXPR    evaluate expression

-f    –file=FILE                    evaluate contents of file

Basic arithmetic uses the standard + – / * symbols but entered after the digits

To print result type p

To quit dc type q

desk_calculator.JPG

Monitor Terminals Using script Command

In Linux, Shell on October 4, 2007 at 6:34 am

Open a terminal and type as below

[raja@AGRAJA ~]$ mkfifo output
[raja@AGRAJA ~]$ script -f output

Open another terminal and type as below

[raja@AGRAJA ~]$ cat output

Now return to first terminal and execute any command.

Everything on the first terminal is updated on the second terminal also.

script.JPG


Multiple Windows in a Terminal

In Linux, Shell on October 4, 2007 at 5:59 am

Manage multiple terminals using screen utility

[raja@AGRAJA ~]$ screen -t name_of_screen
[raja@AGRAJA ~]$ screen -t name_of_screen2 screen_no

To navigate between screens:

1) CTRL+a

2.1) Type to list available screens; use arrow keys to select

[or]

2.2) Type w to list screens on the title bar for a moment.

i) CTRL+a

ii) type screen_no (it can be 0, 1, 2 … )

To scroll within a screen

1) CTRL+a

2) ESC

3) Page-Up/Page-Down

terminal_screen.JPG

Never type ls Again

In Linux, Shell on September 27, 2007 at 6:59 am

It is compelling to type “ls” every time after

1) changing directory

2) copy/remove files

3) program is run; output file is created

etc. etc. …
Here’s a script that runs on an infinite loop that

1) allows type any command as usual (no auto-complete is available)

2) automatically “ls” after every command

# save file as cdls
# chmod 755 cdls
# type "exit" to terminate
while [ 1 ]
do
    ls
    read shell_command
    $shell_command
done

cdls_usage.JPG

A more useful form of the script is given below

# save as cdls
# chmod 755 cdls
# cp cdls /bin
clear
tput cup 24 0
while [ 1 ] do
         tput setb 9
         tput setf 0
         echo --------------------------------------------------------------------------------
         ls -F --color=auto
         echo [`whoami` `pwd` `date`]$
         tput setb 0
         tput setf 7
         read cmd1
         $cmd1
         tput cup 24 0
done

Creating a linux man page

In Linux on April 28, 2006 at 10:35 am

Structure of a Man page

Title Header (.TH)
Section Header (.SH)
Name of command (.NM)
Paragraph (.TP)
Synopsis
Description
Options
Resources
Diagnostics
See also
Copyright
Bugs
Authors

mymanpage.1
—————————————————————

.TH MYMANPAGE 1
.SH NAME mymanpage \- A Demo
.SH SYNOPSIS .B mymanpage [\-option ...]
.SH DESCRIPTION .PP \fImymanpage\fP is a complete application that
 does nothing useful.
.PP It was written for demo
.SH OPTIONS .PP It doesn't have any, but let's pretend, to make
 this template complete:
.TP .BI \-option If there was an option ...
.SH RESOURCES .PP mymanpage uses almost no resources.
.SH DIAGNOSTICS The program should provide info about what it does
.SH SEE ALSO The only other program we know with this little
 functionality is the hello world application.
.SH COPYRIGHT
This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published
 by the Free Software Foundation; either version 2 of the License,
 or (at your option) any later version.
.SH BUGS There were a few bugs
.SH AUTHORS Raja

———————————————————–

After saving the file, type at the terminal:

[raja@AGRAJA~]#groff -Tascii -man mymanpage.1

Installing the man page:

[raja@AGRAJA~]#gzip mymanpage.1
[raja@AGRAJA~]#cp mymanpage.1.gz /usr/share/man/man1

Test the man page:

[raja@AGRAJA~]#man mymanpage