Showing posts with label operation. Show all posts
Showing posts with label operation. Show all posts

Monday, March 19, 2012

Examine multiple files in command less

To change to the next file after opening multiple files simultaneously in 'less' command, use this command

:n

And to change to the previous file, use

:p


The instruction should also be available from the man page.

Monday, March 5, 2012

Hostname on Mac OS X

If the dynamic hostname is provided by DHCP, and you prefer a fixed one, there are a few ways to do it.

From System Preferences/Network

  • Select the network adapter which interfaces the DHCP server.
  • Click on the "Advanced" button on the lower right.
  • In the TCP/IP tab, specify the "DHCP client ID" text field.
Or depending on the version of Mac OS:

-- Mac OS X 10.5 and older
On Mac, the hostname shown on the terminal prompt is configured by the file,
/etc/hostconfig. If it is specified as
HOSTNAME=-AUTOMATIC-,
the name shown in the prompt is provided by DHCP or BootP server.

Change that line to
HOSTNAME=(preferred-name)

-- Mac OS X 10.6 and newer
Use the command scutil (system configuration utility)
scutil --set HostName (preferred-name)

Remember to check the name set in
/Library/Preferences/SystemConfiguration/preferences.plist,
under System/System/ComputerName

Tuesday, December 6, 2011

Global search in vi and list results

We use the simple command to search a pattern (or a fragment of text),

:/{pattern}

Sometimes, there would be a few dozens of matches that you want to list and browse quickly.  Use this command,

:g/{pattern}

It lists the search results in one buffer.  If you want to search the pattern case insensitive, add \c in the command, like

:g/\c{pattern}

Tuesday, November 1, 2011

Monitor disk IO activities on a Linux host

1. Use df first to find all the devices
2. Use iostat

iostat -dx <device> <time-interval>

For example,
iostat -dx /dev/sdb 5

to display disk IO activities every 5 seconds.

Thursday, October 27, 2011

Find CPU information on a Linux

A good tip for finding out CPU and 32/64 bit kernel information on a Linux host, at http://www.cyberciti.biz/faq/linux-how-to-find-if-processor-is-64-bit-or-not/

In short, use

uname -a 

and

cat /proc/cpuinfo

Thursday, August 18, 2011

Use wildcard in the command find

To use a wildcard * in the find command needs a little more care.

Without quote or backslash \, such as
find . foo*bar -print
the shell will expand * before passing it into find command.  This results is a different, and most likely a narrower, search.

To avoid that, use
find . 'foo*bar' -print
or
find . foo\*bar -print

Tuesday, August 16, 2011

Add one more yum repository

Read yum.conf first.  Usually the path is /etc/yum.conf.
Understand where the cache and repository configuration file directory

The following examples use default locations

## add epel to the repo list
## see what is there before change
ls /var/cache/yum/*/*
cd yum.repos.d/
## copy contents from another configured host
sudo vi epel.repo
sudo yum clean all
## make sure it is empty
ls /var/cache/yum/*/*
sudo yum makecache
## see if the new repo epel is added
ls /var/cache/yum/*/*
## add GPG key for the new repo, also do copy-paste
sudo vi /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

If you are not sure about the name of RPM-GPG key, run rpm to install the package.  Towards the end, rpm will complain about missing the GPG key and prompt the file name for you.

Find out it is a 32 or 64-bit Linux

Use the command
uname -m
If it shows x86_64, it is a 64-bit host.
If it shows i386 (or sometimes i686), it is a 32-bit machine

Plus, run the command
file /bin/ls
For 64-bit kernel, it should show
/bin/ls: ELF 64-bit LSB executable ....

Find installed packages on Linux hosts

To find installed packages on a Redhat/CentOS Linux, use
rpm -qa | less

Once the package name is found, use this command to find more details
rpm -qil {package-name}

To find installed packages on a Debian (also Ubuntu) Linux, use
dpkg --list

Once the package name is found, use this command to find more details
dpkg -p {package-name}

Tuesday, August 9, 2011

Find and delete into directories recursively

How to find a set of files or directories that are named the same?  For example, to delete all the '.svn' directories in the current working directory.

One easy way is
rm -rvf `find . -type d -name .svn`

The option [-v] prints out the files/directories found.  and rm -rf is the typical force deletion of a directory.

Another way to do it is
find . -name ".svn" -exec rm -rf {} \;

But this command prints out warning messages that sometimes confuse users.
find: ./.svn: No such file or directory
find: ./images/.svn: No such file or directory

The warning message means it found a .svn directory in the current directory and deleted as instructed ( -exec rm -rf ).  When the command find wanted to descend into .svn directory, it could not.

The trailing {} \; is required.  Pay attention to its format: there is a space between } and \.

Wednesday, August 3, 2011

Find socket/port status on Linux

When debugging or monitoring a client-server application or any connected application, it is necessary to find out what is going on at socket level.

To start, use
netstat -an

To start with TCP connections, use
netstat -ant

Although the option -p should show process information (PID), it usually gives a "-" for that field. Remember to use ifconfig to find interfaces and IP addresses.