Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Thursday, February 12, 2009

Check the version of applications running on Linux

OS version: uname -a cat /etc/redhat-release Apache version: httpd -v /usr/local/apache/bin/httpd -version Jrun version For JRun 3.0, look at logs /opt/jrun/bin/jrun -version Perl /usr/sbin/perl -version (-v works too) Sendmail /usr/lib/sendmail -d0.1 -bt cat /proc/version

Tuesday, January 15, 2008

Unix file compression utilities

Unix file compression utilities: Creating a tape archive: tar -cf archive.tar myDirectories/ Listing the contents of an archive: tar -tf archive.tar Extracting all files from an archive: tar -xf archive.tar To extract just partial pieces from the archive, supply a file or directory name after the archive name. You can list as many as desiered here, separated by spaces. tar -xf archive.tar filename Compress: gzip archive.tar Decompress: gunzip archive.tar.gz Merging commands The "z" flag works with gzip, to either create a tar/gzipped archive: tar -czvf archive.tgz files/ Decompress a tar/gzipped archive: tar -xzvf archive.tgz

Friday, January 11, 2008

vi Commands

Undo Command

u undo the last command.

Screen Commands

CTL/F Pages forward one screen.

CTL/B Pages back one screen.

>> Indent right

<< Indent left

Cursor Positioning Commands

0 Moves cursor to beginning of current line.

$ Moves cursor to end of current line.

nG Moves cursor to beginning of line n. Default is last line of file.

:n Moves cursor to beginning of line n.

/pattern Moves cursor forward to next occurrence of pattern.

?pattern Moves cursor backward to next occurrence of pattern.

n Repeats last / or ? pattern search.

N Repeats last / or ? pattern search in opposite direction

:.= Print line number of current line

Text Insertion Commands

a Appends text after cursor.

A Appends text at the end of the line.

i Inserts text before cursor.

I Inserts text at the beginning of the line.

Text Deletion Commands

x Deletes current character.

dd Deletes current line.

d) Deletes the rest of the current sentence.

D, d$ Deletes from cursor to end of line.

P Puts back text from the previous delete.

Changing Commands

~ Changes case of current character.

J Joins current line with next line.

Cut and Paste Commands

yy Puts the current line in a buffer. Does not delete the line from its current position.

p Places the line in the buffer after the current position of the cursor.

Appending Files into Current File

:R filename Inserts the file filename where the cursor was.

Exiting vi

ZZ Exits vi and saves changes.

:wq Writes changes to current file and quits edit session.

:q! Quits edit session (no changes made).

Visual mode commands

v Start/stop visual mode Allows you to select a block of text

> shift the block right one shiftwidth

< shift the block left one shiftwidth

y yank ( copy ) the block ( paste with a p )

d delete the block

c change the block


Thursday, October 4, 2007

Ctrl - S

If mistakenly typed Control S at vi terminal, and the terminal stops responding type control Q to resume CTL-S Stop transmission to your terminal. CTL-Q Restart transmission to your terminal.

Tuesday, December 26, 2006

Search for a string in a selection of files

How to search for a string in a selection of files (-exec grep ...). find . -exec grep "www.athabasca" '{}' \; -print This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output. If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files. find . -exec grep -q "www.athabasca" '{}' \; -print This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string "www.athabascau.ca". You can then process the files with a sed script to change those occurrances of "www.athabascau.ca" with "intra.athabascau.ca".

Monday, September 25, 2006

Shell Script to Bounce resin and Apache eligently

bash-2.05b$ more /etc/init.d/webfe #!/bin/sh # Startup script for syndicated services web front end # . /home/syndprod/.profile case "$1" in start) /opt/oracle/Apache/Apache/bin/apachectl start su syndprod -c "/internet/apps/resin/bin/httpd.sh start" ;; stop) /opt/oracle/Apache/Apache/bin/apachectl stop su syndprod -c "/internet/apps/resin/bin/httpd.sh stop" ;; restart) /opt/oracle/Apache/Apache/bin/apachectl restart su syndprod -c "/internet/apps/resin/bin/httpd.sh stop" su syndprod -c "/internet/apps/resin/bin/httpd.sh start" ;; condrestart) ;; *) echo $"Usage: -zsh {start|stop|restart}" exit 1 esac exit 0

Friday, August 18, 2006

Remove Carriage Return from Files

Using AWK To use awk to convert a Windows file to Unix, at the Unix prompt, enter: awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt To convert a Unix file to Windows using awk, at the command line, enter: awk 'sub("$", "\r")' unixfile.txt > winfile.txt On some systems, the version of awk may be old and not include the function sub. If so, try the same command, but with gawk or nawk replacing awk. Using TR You can use tr to remove all carriage returns and Ctrl-z ( ^Z ) characters from a Windows file by entering: tr -d '\15\32' < winfile.txt > unixfile.txt You cannot use tr to convert a document from Unix format to Windows. Using vi In vi, you can remove the carriage return ( ^M ) characters with the following command: :1,$s/^M//g Note: To input the ^M character, press Ctrl-v , then press Enter or return.