Tag: unix

Tmux vs Screen

Tmux vs Screen

The unix command screen and tmux have similar goal, but tmux is more complex than screen.

Quick Tips

In order to start using tmux without worrying about forgetting keys, remember follows one after another.

  • Help using key Ctrl+b ?
  • Detach using key Ctrl+b d
  • Resume using command tmux a
  • Create window using command Ctrl+b c
  • Navigate windows using key Ctrl+b w, then arrow keys
  • Rename window using key Ctrl+b ,
  • Status bar has window name and <id>
  • Switch window using key Ctrl+b <id>

Commands

screen tmux
Startup screen tmux
Starting Named Session screen -S session_name tmux new -s session_name
List running session screen -ls tmux ls
Reattach screen -r
Reattach by id screen -r <id> tmux attach-session -t <id>

Keys

screen tmux
Help Ctrl+a ? Ctrl+b ?
Create a new shell (without window) Ctrl+a c
Switch to next shell Ctrl+a space
Switch to previous shell Ctrl+a backspace
Create a new window (with shell) Ctrl+b c
List all shells Ctrl+a "
Choose window from a list Ctrl+b w
Switch to N'th shell Ctrl+a <n>
Switch to N'th window Ctrl+b <n>
Rename the current window Ctrl+a A Ctrl+b ,
Split current region horizontally into two regions Ctrl+a S Ctrl+b %
Split current region vertically into two regions Ctrl+a | Ctrl+b "
Switch the input focus to the next region Ctrl+a tab Ctrl+b o
Toggle between the current and previous windows Ctrl+a Ctrl+a Ctrl+b ;
Close all regions but the current one Ctrl+a Q
Close the current region Ctrl+a X Ctrl+b x
Detach from session Ctrl+a d Ctrl+b d
Sent Ctrl+a to region Ctrl+a a

Customize

screen

Customization can be done in /etc/screenrc and ~/.screenrc. Sample of contents is shown below.

# Turn off the welcome message
startup_message off

# Disable visual bell
vbell off

# Set scrollback buffer to 10000
defscrollback 10000

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

tmux

Customization can be done in ~/.tmux.conf. Sample of contents is shown below.

# Improve colors
set -g default-terminal 'screen-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Customize the status line
set -g status-fg  green
set -g status-bg  black

References

How To Use Linux Screen
Getting started with Tmux
How to split the terminal into more than one "view"?

Remove empty directories recursively

Remove empty directories recursively

Use find command

Use following command can remove empty directories which may have empty directories in them. The -depth will sort the output according to the depth of directories.

find . -type d -depth -exec rmdir {} \;

Note: Just ignore error due to directory not empty

Use rmdir command

First, need to know how deep of your directory, then can run following command

rmdir */*/*/*
rmdir */*/*
rmdir */*
rmdir *

Note: This can cause too many arguments error or command line too long error for large directory.