How to get started with tmux

Quite simply, tmux allows you to run multiple terminal command lines at the same time side by side much like putting multiple windows next to each other so you see both simultaneously. It stands for "terminal multiplexer", a fancy term for something so logical. Here are the basics to get you started with tmux quickly.

First of all, just run tmux. You will very likely have it in your system no matter which Linux or UNIX distribution you're using. Otherwise you can get it from the tmux website.

tmux

And you're in. Not much has changed, but you should see the green bar at the bottom, which is the tmux status bar showing you which window you're in, date and time, and the hostname of your system. The goodness is in the keyboard commands that you can now use to split the current window into multiple panes, or to create new windows with their own panes. You can then switch between panes and windows with ease.

The way keyboard commands work is by first pressing a shortcut CTRL-B, and then entering a character corresponding to a command. For example, to split the current window or pane into two vertical panes press CTRL-B %. Just press CTRL-B together, then enter the % normally, and it will split.

Here are a few of the basic commands that will have you up and going with tmux with ease:

  • CTRL-B % – split into two vertical panes (as mentioned)
  • CTRL-B " – split into two horizontal panes
  • CTRL-B z – make the current pane full screen (press again to exit full screen)
  • CTRL-B arrow-key – switch between panes with arrow keys. For example
  • CTRL-B up-arrow – will switch to the pane above the currently active one.
  • CTRL-B c – create a new window. You will notice it indicated in the green status bar under a number.
  • CTRL-B number – switch to a window. To switch to a window 0, for example, press CTRL-B 0.

With these shortcuts you can create as many panes and windows as you need, and switch between them.

One more thing though. These sets of windows and panes are known as tmux sessions, and you can actually have multiple of them, and they are saved on the system so that they can be attached to different terminals you can in from.

You can detach from the current session with CTRL-B d, and you'll end up back on the normal bare command line. Then you can run this to list all of the sessions with its numbers:

tmux -l

You'll see something like:

0: 2 windows (created Tue Sep 2 18:30:02 2014) [237×55]
1: 1 windows (created Tue Sep 2 19:04:03 2014) [237×55]

Then you can attach to session 0, for example, with this command:

tmux attach -t 0

And if you no longer want a particular session you can kill it:

tmux kill-session -t 0

You can see the full breakdown of sessions, their windows, and their panes by issuing this command:

tmux info

Other useful commands with more information:

tmux list-keys
tmux list-commands
man tmux

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Where, how and why are you using Unix?

Greetings everyone, today's post is going to be a bit different from the usual technical tips and tricks I share. This time around, I need a bit of help myself – and I hope many of you will be able to answer my questions. Bear with me: it's a lengthy post, but any help is GREATLY APPRECIATED!

Why am I asking these questions?

As you remember, a month ago I have offered invited all of the Unix Tutorial readers to learn Unix together. Everyone benefits from this – you get a chance to ask the questions which you always wanted answered, and I get to refresh my mind or even conduct a research on new topics just so that I can share the answers and solutions in the easiest to follow form.

I'm currently working on a members area for Unix Tutorial, which will eventually have a number of self-paced courses to help you improve your knowledge of Unix and get to the next level of productivity when solving technical problems.

Update: if you're interested in becoming a member, subscribe to the Unix Tutorial waiting list!

[Read more…]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

What to do if numeric id is shown instead of Unix username

As you know, every file in your Unix OS belongs to some user and some group. It is very easy to confirm the ownership of any file because user id and group id which own the file are always linked to the file. However, sometimes you can't tell which user owns the file, and today I'm going to explain why. It's a rather lengthy post and a complicated matter, so please leave questions or comments to help me polish this article off.

Files and directories ownership in Unix

If you look at any file using ls command, you will see an output like the one shown below – it reveals file access permissions, user and group id of the owner, the modification timestamp and the file name itself:

ubuntu$ ls -l /tmp/myfile
-rw-r--r-- 1 greys admin 0 Jan  6 03:51 /tmp/myfile

[Read more…]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Confirm the Day of the Week Based on a Timestamp

I recently created a Unix Questions and Answers page, if you have a Unix question – feel free to ask it there using the submit form and I'll do my best to help you out.

Today's Unix question is this:

How can we write a shell script in unix to find the day of the week when date is given?

The solution for this is even simpler: there's no need for Unix scripting, all you need is to have GNU date command at your disposal. I've already shown you all the basic date/time calculations using this great tool, and that's just another way of using it.

How to find a Day of the week based on timestamp

All you need is to know the base date. Let's say I'm interested in October 16th, 2009. Here's how easy it is to confirm that day will be Friday:

ubuntu$ date -d "Oct 16 2009" "+%a"
Fri

That's it – enjoy!

See also:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

How To Parse Text Files Line by Line in Unix scripts

I'm finally back from my holidays and thrilled to be sharing next of my Unix tips with you!

Today I'd like to talk about parsing text files in Unix shell scripts. This is one of the really popular areas of scripting, and there's a few quite typical limitations which everyone comes across.

Reading text files in Unix shell

If we agree that by "reading a text file" we assume a procedure of going through all the lines found in a clear text file with a view to somehow process the data, then cat command would be the simplest demonstration of such procedure:

redhat$ cat /etc/redhat-release
Red Hat Enterprise Linux Client release 5 (Tikanga)

[Read more…]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS