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

Sunday, April 10, 2011

Attaching files in mail (Unix - mailx)

The following command can be used to attach files in the mail while sending it using 'mailx' command in UNIX OS.


uuencode sourcefilename destfilename | mailx -m -s "My attachment"  mailid@server.com




uuencode command will convert the file into ASCII data. The 'sourcefilename' is the name of the file to be attached in th email. If the file name has to be different than the source file name then 'destfilename' can be specified as new file name.



Wednesday, October 7, 2009

Unix command to remove queues,semaphores and shared memory segments

The following command will remove all the message queues,semaphores and shared memory segments which got created.

ipcs | awk  ' {print "ipcrm -" $1 " " $2}' |sh


If the queues ,shared memory segments and  semaphores of particulare user needs to be removed then the following command will be used.

ipcs | grep username | awk ' {print "ipcrm -" $1 " " $2}' | sh

Wednesday, September 30, 2009

UNIX command to find distinct values in a column

A file which has some duplicate numbers present in a column and if we need distinct values ,the following unix command can be used

$ > sort filename | uniq

Example: number.txt contains the following values

1
2
3
2
1


then the command sort number.txt |uniq willl result in
1
2
3

For more info,please refer
http://www.unix.com/shell-programming-scripting/77138-awk-print-distinct-col-values.html

Thursday, August 13, 2009

VI editor (UNIX)

A good site for learning advanced options available in VI editor:

http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html

It's quite interesting and useful.

I learned about map option and opening two files in vi editor to edit.

Monday, August 10, 2009

Process status (ps command in unix)

Command to print the last column in ps -eaf command(UNIX):

> ps -aef -0 comm

This would serve as an alternate for awk command to print the column values.

If you want to print the user alone in the ps command then

> ps -aef -o user

If you want to print the pid alone in the ps command then

> ps -aef -o pid

If you want to print the ppid(Parent process id) alone in the ps command then
> ps -aef -o ppid

Thursday, August 6, 2009

Grep either of two strings in unix:

The following command can be used to find either string1 or string2 in UNIX

egrep '(string1 | string2)'

Check out the following link:
http://www.unix.com/shell-programming-scripting/25598-how-grep-two-more-words-line-same-time.html

Thursday, November 20, 2008

SCP – Secure copy

scp can be used to transfer files from a remoter server. I would consider this as an alternate to ftp command to transfer files.

scp uses ssh for data transfer.Like ftp it also uses authentication before accessing the remote server.

Example:

Source file details:

Server : 192.150.120.106
Path : /home/sqlscripts/
File name: truncate.sql
Username: sam

Destination file details:

Server : 192.192.100.150
Path : /home/sqlscipts/
Username : john

If the file truncate.sql needs to be transfer to destination server(192.192.100.150
) from source the following command would do. Go to destination directory and enter the command as follows

scp sam@192.150.120.106:/home/sqlscripts/truncate.sql .

After pressing enter you will be prompted to enter your password. Enter the password and press enter the file would be in destination folder.

Find more info on this page http://unixhelp.ed.ac.uk/CGI/man-cgi?scp+1
Powered By Blogger