UNIX Commands

These are some interesting UNIX Commands are used during the middleware administration.

1. To set the “tree” alias to list all the directory in the UNIX terminal as tree structure.

tree=’ls -R | grep :$ | sed -e ‘\”s/:$//’\” -e ‘\”s/[^-][^\/]*\//–/g’\” -e ‘\”s/^/ /’\” -e ‘\”s/-/|/’\’

Output of the above command is like this:

/home/mqm$tree
|-mqsc_scripts
|—logs
|-omegamon
|—Deploy
|—InstallITM
|—–plugin
|——-plugins
|—REPORTS

2. “find” command.
One of the useful command to find the files and directories in the UNIX file system is “find” command. The find command takes the following argument to identify the files or directory in UNIX file system.

find . -type f -print -exec grep -i “type your string here to find” {} \;

To find out the result and we can use the output to filter the result strings.

find . -name *.txt | xargs du -h|grep -i M

The below command gives the same output, but we can not use the output to other grep commands.. (may be I don’t know how to use that)

find . -name “test*” -exec du -sh {} \;

 

Click to access lifetime-support-middleware-069163.pdf

3. Software (Package) installation and query details:

$which gcc
/usr/bin/gcc

$whereis gcc

$ locate httpd

redhat$rpm -q python

redhat$ rpm -qf /etc/httpd

freebsd@pkg which /usr/local/sbin/httpd

/usr/local/sbin/httpd was installed by package apache-24-2.x.x

ubuntu@dpkg -query -S /etc/apache2
apache2: /etc/apache2

4. Installing new software/package in UNIX/Linux:

ubuntu$sudo apt-get install
redhat$sudo yum install
freebsd$sudo pkg install -y

 

5. Simple HTTP Server using python.

python m SimpleHTTPServer 8000

6. sar command will help to get the CPU and Memory utilization for any unix servers. Usage the following command to get the current and past history report.

sar -A               (To get the current report)

sar -A -f /var/log/sa/sa23  ( To get the past reports e.g. 23rd of the month)

Use the ksar tool to analyses this report.

https://sourceforge.net/projects/ksar/

 

 


7. The following commands are useful to enter into UNIX server in scrips using password or key file.

sshpass -p ‘yourpassword’ ssh -o StrictHostKeyChecking=no ibmadmin@servername.ibmadmin.com ‘ls -ltr’

ssh -i yourkeyfile.key ibmadmin@servername.ibmadmin.com ‘ls -ltr’


 

8. The following command will help to tar only directory or tar only folders in unix servers.

find . -type d -print0 | tar cf dirstructure.tar --null --files-from - --no-recursion

 


python -m SimpleHTTPServer 8000

Responses

  1. Command to delete logs that are older than 365 days

    find . -name “*.log” -mtime +365 -exec rm {} \;


Leave a comment