Wednesday, December 17, 2014

Using netcat


Send a string (e.g. to a Graphite server)

echo "metrics.test.random $RANDOM $(date +%s)" | nc 10.60.35.50 2003

Test status of a TCP daemon

nc -vz someserver port

-v: verbose
-z: scan for listening daemons but send no data

Disable IPv6 on CentOS


echo 'install ipv6 /bin/true' > /etc/modprobe.d/ipv6.conf
init 6

This process disables the IPv6 kernel module entirely. It can be considered good form, but by no means necessity, to do the following:

chkconfig ip6tables off

Also in /etc/sysconfig/network-scripts/ifcfg-*:

IPV6INIT=no
IPV6_AUTOCONF=no

To verify, the following should produce empty output:

lsmod | grep v6

Wednesday, December 03, 2014

Tuesday, December 02, 2014

VirtualBox video resolution: guest only allows small video resolutions


Symptom: Guest OS (Kubuntu) only allows 640x480 video resolution

Solution: Increase video memory allocation on virtual machine - on VirtualBox: Settings > Display > Video > Video Memory (set to >64MB)

Wednesday, November 26, 2014

VMWare Player scare: Boot time error: The file specified is not a virtual disk

Documented here, the issue occurs due to mismatched settings between the virtual hard drive descriptor and data files. This was caused by a VMDK file deleted by VirtualBox (presumed) and mirculously retrieved using TOKIWA data recovery. The restored file was uncorrupted, but unrecognized by VMWare Player. The solution was to unregister the VM and register it anew. Blessed be the goddess.

Ugly hack - Elasticsearch plugin (Knapsack) install on Windows



  • Under Cygwin, with a mix of POSIX and Windows paths
  • Firewalled ES node -- downloaded to RDP client and pulled binary via tsclient
  • ES server is embedded in a proprietary stack


$ 'C:\Program Files\ObscureDistro\java/bin/java' -Xmx64m -Xms16m -Delasticsearch '-Des.path.home=/cygdrive/c/Program Files/ObscureDistro/server/bin' -cp  'C:\Program Files\ObscureDistro\server\lib.obscure\*' org.elasticsearch.plugins.PluginManager -install knapsack -url 'file:///\\tsclient\C\Users\someone\Downloads\elasticsearch-knapsack-1.3.2.0-plugin.zip'

-> Installing knapsack...
Trying file://///tsclient/C/Users/someone/Downloads/elasticsearch-knapsack-1.3.2.0-plugin.zip...
Downloading .....DONE
Installed knapsack into C:\cygdrive\c\Program Files\ObscureDistro\server\bin\plugins\knapsack



  • ES node must be restarted

Tuesday, November 25, 2014

Using strace


Trace system calls from a process and all its children and threads:

sudo strace -f -p 3914 2>&1 | grep -vE 'clock_gettime|SIGSTOP|gettime|epoll|futex|restart' | head -10000 | less

-f: track forked
-p: parent PID
grep: remove fast, unimportant calls

Tuesday, November 11, 2014

Elasticsearch - useful cats


http://myhost:9200/_cat/thread_pool?v

Shows:

host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected 

Friday, November 07, 2014

Elasticsearch multilevel aggregation

/*
SELECT count(*)
FROM docs
GROUP BY storm_data_spout.task_id
UNION
SELECT count(*)
FROM docs
GROUP BY storm_data_bolt.task_id
*/

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "bolt": {
      "terms": {
        "field": "storm_data_spout.task_id"
      }
    },
    "spout": {
      "terms": {
        "field": "storm_data_bolt.task_id"
      }
    }
  }
}

// ======================

/*
SELECT count(*)
FROM docs
GROUP BY storm_data_spout.task_id, storm_data_bolt.task_id
-- embedded agg not supported for multilevel using terms agg. Using script workaround per http://bit.ly/1uI76eO
*/

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "spout-bolt": {
      "terms": {
        "script": "doc['storm_data_spout.task_id'].getValues() + '|' + doc['storm_data_bolt.task_id'].getValues()"
      }
    }
  }
}

Thursday, November 06, 2014

rsync


Synchronize directory trees incrementally (only newer files get pushed)

rsync -vazh ~/git/myproj --exclude 'node_modules/' --exclude '.git/' --exclude '.idea/' myser@dev01:~/git

-a: archive (preserve timestamps/permissions)
-v: verbose
-h: human-readable output
-z: compress
-u: only new(er) files
--exclude: self-explanatory. Be sure to list a separate instances for every excluded path

It is important to include the trailing slash in the source path. That instructs rsync to copy the content of that directory into the destination path. Omitting the trailing slash will create the referenced directory in the destination (e.g ~/git/myproject/src/src/)

Friday, October 31, 2014

Disable iptables in a whole cluster



for node in mynode{03,04,05,06,07,08,09,10,11,12}; do ssh root@$node '/etc/init.d/iptables stop; chkconfig iptables off'; done

Monday, October 27, 2014

Scala console


Start with 'sbt console'

scala> import sys.process._
import sys.process._

scala> "ls -al" !
total 64
drwxr-xr-x  10 Al  staff   340 May 18 18:00 .
drwxr-xr-x   3 Al  staff   102 Apr  4 17:58 ..
-rw-r--r--   1 Al  staff   118 May 17 08:34 Foo.sh
-rw-r--r--   1 Al  staff  2727 May 17 08:34 Foo.sh.jar
res0: Int = 0

Monday, October 20, 2014

Interactive debugging in Scala Play


Start with:

sbt console. At prompt, enter:

scala>

import java.io.File
import play.api._
import play.api.Play
val application = new DefaultApplication(new File("."), this.getClass.getClassLoader, None, Mode.Dev)
Play.start(application)
import play.api.Play.current
Play context becomes available on the console:
scala> conf.Global.esClient.search("mazda")
EmbeddedESServer.search: Setting future
res6: String = {"took":218,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":246,"max_score":null,"hits":[{"_shard":0,"_node":"qffjZhZWTqObiZaTqQB7WA","_index":"twitter","_type":"tweet","_id":"523156744353370112","_score":null,"_source":{"filter_level":"medium","retweeted":false,"in_reply_to_screen_name":null,"possibly_sensitive":false,"truncated":false,"lang":"en","in_reply_to_status_id_str":null,"id":523156744353370112,"in_reply_to_user_id_str":null,"timestamp_ms":"1413565262298","in_reply_to_status_id":null,"created_at":"Fri Oct 17 17:01:02 +0000 2014","favorite_count":0,"place":null,"coordinates":null,"text":"New Mazda MX-5 - exclusive studio pictures http://t.co/mqUhp8Wf2w","contributors":null,"geo":null,"entities":{"trends":[],"symbols":[],"urls":[{
 
Also may use:
 
new play.core.StaticApplication(new java.io.File("."))
 
 
 

Thursday, October 16, 2014

Passwordless SSH


# on client:
user=root
[[ ! -f ~/.ssh/id_rsa.pub ]] && ssh-keygen
for n in $CLUSTER_NODES; do ssh-copy-id -i ~/.ssh/id_rsa.pub $root@$n; done

The code above is roughly equivalent to the code below, which is included only to explain roughly what ssh-copy-id does under the covers. The first approach is strongly recommended.  

CLUSTER_NODES="39.96.64.13 39.96.64.15 39.96.64.17"

for node in $CLUSTER_NODES
do
     cat ~/.ssh/id_rsa.pub |
          ssh $user@${node} 'cat >> ~/.ssh/authorized_keys;
               chmod go-w ~/;
               chmod 700 ~/.ssh;
               chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa;
               chmod 644 ~/.ssh/id_rsa.pub' # ~/.ssh/known_hosts
done

# on server:
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub ~/.ssh/known_hosts

Tuesday, October 14, 2014

Set up SSH tunnel


Tunnel firewalled Elasticsearch port (9200) through SSH

Tunnel service out with access to server host:

ssh -N -f remoteuser@remotehost -L 19200:localhost:9200

Options:

  • -N: Do not execute command (optional, mostly for security)
  • -f: Go into background (otherwise remote prompt comes into terminal)
  • -L: Local port mapping (local port 19200 will tunnel into remote 9200)

SOCKS proxy

ssh -D 8080 -f -C -q -N myuser@remote_ssh_server
-D 8080: Dynamic SOCKS server
-f : Fork into background
-C : Turn on compression
-q : Quiet mode
-N : No commands (required by -f)

Wednesday, October 08, 2014

Test host name resolution (python)


python -c 'import socket; print socket.getfqdn(), socket.gethostbyname(socket.
getfqdn())'
 

VirtualBox, CentOS eth0: transmit timed out; status 0073, resetting.



Error seemed due to unused virtual adapters having 'Cable Connected' checked:

1. Clear 'Cable Connected' in all unused adapters
2. Set 'Attached to:' to 'Not attached' in all unused adapters
3. service network restart

Hello Neo4j


service neo4j-service stop
service neo4j-service start


// all Page nodes named Automobile
match (n:Page{name:'Automobile'}) return count(*);
// = 24 // should be 1

match (n:Page) return n.id, n.name, count(*) limit 10;
n.idn.namecount(*)
nullEuropean_Car_of_the_Year1
nullHamm_AG1
nullFord_Motors1



Set up static IP address


vi /etc/sysconfig/network/ifcfg-eth0 (SLES)
vi /etc/sysconfig/network-scripts/ifcfg-eth0 (CentOS)
 
vi /etc/sysconfig/networking/devices/ifcfg-eth0 (CentOS?), set values to:

BOOTPROTO=static
IPADDR=10.1.1.100
NETMASK=255.255.255.0
BROADCAST=10.1.0.255
NETWORK=10.1.0.0

Also, set up DNS server:
vi /etc/resolv.conf
search home
nameserver 10.1.1.1

May need to :

route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.1.1.1

and

1. rm -f /etc/udev/rules.d/70-persistent-net.rules
2. Edit ifcfg-eth0 and remove the UUID and MACADDR (HWADDR):
vi /etc/sysconfig/networking/devices/ifcfg-eth0
3. Reboot (init 6)

Centos error on VirtualBox (Device eth0 does not seem to be present, delaying initialization)



1. rm -f /etc/udev/rules.d/70-persistent-net.rules
2. Edit ifcfg-eth0 and remove the UUID and MACADDR (HWADDR):
vim /etc/sysconfig/networking/devices/ifcfg-eth0
3. Reboot (init 6)

Tuesday, October 07, 2014

Install Elasticsearch on CentOS


Install RPM

sudo rpm -i https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.4.noarch.rpm

ES is installed under /usr/share/elasticsearch
Config at /etc/elasticsearch/elasticsearch.yml

Start automatically
sudo /sbin/chkconfig --add elasticsearch

Start now
sudo service elasticsearch start


Disable IPv6 on CentOS




Method #1 (recommended)

Permanent: Edit /etc/sysctl.conf to:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Runtime only:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

Method #2 (discouraged: it may interfere with SELinux and other components)

Add the following to /etc/sysconfig/network-scripts/ for the device
IPV6INIT=no

SCRIPT (caution!):

echo -e "net.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1" | while read f; do if [ $(grep -c "$f" /etc/sysctl.conf) -eq 0 ]; then echo -e "\n$f" >> /etc/sysctl.conf; fi; done

Mount block device

How to mount a new block device (CentOS)

# Check current status: shows no partition info and disk ID=0x0

sudo fdisk -l

Disk /dev/xvdc: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

# Create a partition. Answer prompts as indicated
sudo fdisk /dev/xvdc
n # new partition
p # primary
1 # partition no.
<enter> # accept start cyclinder default
<enter> # accept end cyclinder default (take whole device!)
w # write partition

# Verify. fdisk should show new partition info
sudo fdisk -l

Disk /dev/xvdc: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb7719266

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1       26108   209712478+  83  Linux


# Format new device
sudo mkfs -t ext3 /dev/xvdc1

# Mount it
[ ! -d /data ] && sudo mkdir /data
sudo mount /dev/xvdc1 /data

# Make permanent
sudo nano /etc/fstab
# edit to add:
/dev/xvdc1            /data                    ext3    defaults,noatime,barrier=0      1 1

Thursday, October 02, 2014

Generate Elasticsearch test documents

for i in $(seq 1 100); do echo curl -XPUT \''http://roadrunner2:9200/test-001/doc/'${i}''\' -d \''{"sentence":"'$(head -c 56 < /dev/urandom | base64)'"}'\'; done | bash

Thursday, September 18, 2014

Install iPerf on CentOS

yum -y install yum-plugin-priorities
sed -i -e "s/\]$/\]\npriority=1/g" /etc/yum.repos.d/CentOS-Base.repo
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo
yum --enablerepo=epel -y install iperf3   # install from EPEL

Saturday, September 06, 2014

Sensei

Storm:

Clojure:

Distrosys:

Clojure and Storm

$ lein repl
(require '[clj-http.client :as client])
(client/get "http://asterdc:8080/api/v1/getfile?name=stream.10.log")
(def stream (client/get "http://node1:8080/api/v1/getfile?name=stream.10.log"))
(require '[clojure.data.json :as json])


user=> (type stream)
clojure.lang.PersistentArrayMap
user=> (keys stream)
(:orig-content-encoding :trace-redirects :request-time :status :headers :body)
user=> (count (:body stream)) ;; count characters in body
20279
user=> (get (.split (:body stream) "\n") 0) ;; get first body from array
"{\"id\":\"tag:search.twitter.com,2005:178204609083473921\",\"body\":\"RT @mikeanikevans: I am such a queer\",\"verb\":\"share\",\"link\":\"http://twitter.com/gthang42069/statuses/178204609083473921\",\"generator\":...{\"klout_score\":27}}\r"
user=> (get (json/read-str (get (.split (:body stream) "\n") 9)) "body")
"@MEMOZ809 No se :("
user=> (keys (json/read-str (get (.split (:body stream) "\n") 9)))
("inReplyTo" "body" "postedTime" "twitter_entities" "gnip" "provider" "generator" "actor" "objectType" "link" "id" "verb" "object")

# run topology from command line (no Storm runtime)
$ lein run -m fiat.topology/run!


lein clear
lein compile
lein jar

To run on a local cluster:

```bash
lein run -m fiat.topology/run!
# OR
lein run -m fiat.topology/run! debug false workers 10
```

To run on a distributed cluster:

```bash
lein uberjar
# copy jar to nimbus, and then on nimbus:
bin/storm jar path/to/uberjar.jar fiat.TopologySubmitter workers 30 debug false
```

Install local Storm jars on master node
```
/usr/lib/maven/bin/mvn deploy:deploy-file  -Dfile=/usr/lib/storm/lib/storm-core-0.9.1.2.1.2.0-402.jar -DartifactId=storm -DgroupId=local -Dversion=0.9.1.2.1.2.0-402 -Dpackaging=jar -Durl=file:repo
```


lein clean; lein deps; lein compile; lein uberjar

Clojure and HBase

(println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))) ;; get class path in REPL
# in REPL
(require '[clojure-hbase.core :as hbase])
(import [org.apache.hadoop.hbase HBaseConfiguration HConstants KeyValue])
(import [org.apache.hadoop.hbase.client HTablePool Get Put Delete Scan Result RowLock HTableInterface])

(hbase/set-config (hbase/make-config {
     :zookeeper.znode.parent "/hbase-unsecure" 
     :hbase.zookeeper.property.clientPort "2181"
     :hbase.cluster.distributed "true"
     :hbase.zookeeper.quorum "hdp005-3,hdp005-21,hdp005-23"
}
))
(hbase/table "tweets-test")

---
create 'tweets_test', 'cf'
put "tweets_test", "newkey1", 'cf', 'somevalue'
hbase(main):007:0> scan "tweets_test"
ROW                             COLUMN+CELL
newkey1                        column=cf:, timestamp=1405693122884, value=somevalue

Clojure cider, lein

lein repl :start :port 10010

(use 'clojure.repl 'clojure.pprint)

(setq nrepl-popup-stacktraces-in-repl nil)
(setq nrepl-auto-select-error-buffer nil)

Zoom
You can use `C-x C-+’ and ‘C-x C--’ (‘text-scale-adjust’) to increase or decrease the buffer text size (`C-+’ or ‘C--’ to repeat).

Very important: add cider plugin in project.clj
(defproject lucy "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
                 [org.clojure/clojure "1.6.0"]
                 [clucy "0.4.0"]
                 ]
  :plugins [[cider/cider-nrepl "0.6.0"]]
  )

In CIDER

C-c M-n: Set REPL namespace from buffer
C-x C-e: Eval preceding line
C-c C-k: compile buffer
C-x C-c: eval region
C-c C-c: abort eval
M-: Read a single Emacs Lisp expression in the minibuffer, evaluate it, and print the value in the echo area (eval-expression).
C-x h selects the entire buffer.
C-M-\ reindents the selected region.
C-M-@ select s-expression
M-. Jump to the definition of a symbol. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
M-@ (mark-word) puts the mark at the end of the next word
Use M-< to move to the beginning of the buffer, and M-> to move to the end
C-v to scroll down, and M-v to scroll up

M-d Kill up to the end of a word (kill-word).
M-\ Delete spaces and tabs around point (delete-horizontal-space)
M-<SPC> Delete spaces and tabs around point, leaving one space (just-one-space)
M-^ Join two lines by deleting the intervening newline, along with any indentation following it (delete-indentation)
C-t Transpose two characters (transpose-chars).
M-t Transpose two words (transpose-words).
C-M-t Transpose two balanced expressions (transpose-sexps).
C-x C-t Transpose two lines (transpose-lines).
M-x auto-revert-tail-mode (tail a file)

You can hide the *nrepl-connection* and *nrepl-server* buffers from appearing in some buffer switching commands like switch-to-buffer(C-x b) like this:
(setq nrepl-hide-special-buffers t)


M-% string <RET> newstring <RET>
Replace some occurrences of string with newstring.
C-M-% regexp <RET> newstring <RET>
Replace some matches for regexp with newstring.

<SPC>
to replace the occurrence with newstring.
<DEL>
to skip to the next occurrence without replacing this one.
, (Comma)
to replace this occurrence and display the result. You are then asked for another input character to say what to do next. Since the replacement has already been made, <DEL> and <SPC> are equivalent in this situation; both move to the next occurrence.You can type C-r at this point (see below) to alter the replaced text. You can also type C-x u to undo the replacement; this exits the query-replace, so if you want to do further replacement you must use C-x <ESC> <ESC> <RET> to restart (see Repetition).
<RET>
to exit without doing any more replacements.
. (Period)
to replace this occurrence and then exit without searching for more occurrences.
!
to replace all remaining occurrences without asking again.
Y (Upper-case)
to replace all remaining occurrences in all remaining buffers in multi-buffer replacements (like the Dired `Q' command which performs query replace on selected files). It answers this question and all subsequent questions in the series with "yes", without further user interaction.
N (Upper-case)
to skip to the next buffer in multi-buffer replacements without replacing remaining occurrences in the current buffer. It answers this question "no", gives up on the questions for the current buffer, and continues to the next buffer in the sequence.
^
to go back to the position of the previous occurrence (or what used to be an occurrence), in case you changed it by mistake or want to reexamine it.




Print object members

(doseq [m (.getMethods (type index))] (println m))

(use 'clojure.reflect 'clojure.pprint)
(pprint (reflect "hello"))
{:bases
 #{java.io.Serializable java.lang.Comparable java.lang.Object
   java.lang.CharSequence},
 :flags #{:public :final},
 :members
 #{{:name valueOf,
    :return-type java.lang.String,
    :declaring-class java.lang.String,...

List classpath
(defn classpath []
(seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))

Expand macros
(macroexpand '(time (print "timing")))
;; or better yet
(clojure.pprint/pprint (macroexpand '(time 1)))

List members in namespace
(require '[clojure-hbase.core :as hbase])
(dir clojure-hbase.core)

Show function source
user=> (source hbase/table)
(defn table
  "Gets an HTable from the open HTablePool by name."
  [table-name]
  (io!
   (.getTable (htable-pool) (to-bytes table-name))))

Find elements by regex match in collection
(filter #(re-find #"zoo" (key %)) (seq (hbase/make-config nil)))

clojure.core/all-ns
  Returns a sequence of all namespaces.

List files
(take 10 (file-seq (clojure.java.io/file ".")))



Clojure and Zookeeper

Add [zookeeper-clj "0.9.1"] to dependencies

lein repl
(require '[zookeeper :as zk])
(.getChildren client "/" false) ;; watcher=false
#<ArrayList [hbase-unsecure, storm, zookeeper]>

(def ZK_HOSTS "127.0.0.1:2181,node1,node2,node3)
(def ZK_ROOT "/twitter-demo")(def client (zk/connect ZOOKEEPER_HOSTS :watcher (fn [event] (println event))))
(zk/create client ZK_ROOT :persistent? false)
(def version (:version (zk/exists client ZK_ROOT)))
(zk/create client ZK_ROOT :data (.getBytes "123143kdjkds") :persistent? false)


Friday, August 29, 2014

Emacs

open
emacs& RET     or click a graphical icon
emacs -nw RET     start in terminal, not in a windowing system
cancel
C-g     a command
M-g g    Go to line #

Text size
Shrink/Grow: C - - / C - + 

Copy & Paste

C-<space>
    Start selection
C-w
    Cut
M-w
    Copy
C-y
    Paste

12.1.2 Killing by Lines

C-k
Kill rest of line or one or more lines (kill-line).
C-S-backspace
Kill an entire line at once (kill-whole-line)

M-: evaluate function in minibuffer
(vi yy): C-a (beginning) C-spc (highlight) C-e (end) C-y (yank)

M-<Move to the top of the buffer (beginning-of-buffer). With numeric argument n, move to n/10 of the way from the top.
M->Move to the end of the buffer (end-of-buffer). 

15.10.4 Query Replace


M-% string <RET> newstring <RET>
Replace some occurrences of string with newstring
C-M-% regexp <RET> newstring <RET>
Replace some matches for regexp with newstring.

26.3.2 Indenting Several Lines

C-M-q
Reindent all the lines within one parenthetical grouping. 
C-u <TAB>
Shift an entire parenthetical grouping rigidly sideways so that its first line is properly indented. 
M-x indent-code-rigidly
Shift all the lines in the region rigidly sideways, but do not alter lines that start inside comments and strings.
C-u 4 M-x indent-rigidly to indent the region by four spaces, C-u -4 M-x indent-rigidly to remove four spaces

Also, in Python mode, with a marked region, use C-c > and C-c <

Displaying in Another Window

C-x 4 is a prefix key for commands that select another window (splitting the window if there is only one) and select a buffer in that window. Different C-x 4commands have different ways of finding the buffer to select.

C-x 4 b bufname RET
Select buffer bufname in another window. This runs switch-to-buffer-other-window.
C-x 4 f filename RET
Visit file filename and select its buffer in another window. This runs find-file-other-window. See section Visiting Files.
C-x 4 d directory RET
Select a Dired buffer for directory directory in another window. This runs dired-other-window. See section Dired, the Directory Editor.
C-x 4 m
Start composing a mail message in another window. This runs mail-other-window, and its same-window version is C-x m (see section Sending Mail).
C-x 4 .
Find a tag in the current tag table in another window. This runs find-tag-other-window, the multiple-window variant of M-. (see section Tag Tables).

Deleting and Rearranging Windows


C-x 0
Get rid of the selected window (kill-window). That is a zero.
C-x 1
Get rid of all windows except the selected one (delete-other-windows).
C-x ^
Make the selected window taller, at the expense of the other(s) (enlarge-window).
C-x }
Widen the selected window (enlarge-window-horizontally).