This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux:linux_tips [2021/01/01 21:25] 127.0.0.1 external edit |
linux:linux_tips [2023/11/15 18:07] (current) manu |
||
---|---|---|---|
Line 22: | Line 22: | ||
install the basic desktop on CentOS: | install the basic desktop on CentOS: | ||
yum groupinstall basic-desktop | yum groupinstall basic-desktop | ||
+ | | ||
+ | ===== Screen ===== | ||
+ | |||
+ | Screen is deprecated into Redhat, now replaced by **TMUX** | ||
+ | |||
+ | https://www.redhat.com/sysadmin/introduction-tmux-linux | ||
+ | |||
+ | TMUX is a terminal using a background session, so you can run long process without being disconnected from TIMEOUT (TMOUT) | ||
+ | <cli prompt='$'> | ||
+ | $ tmux | ||
+ | </cli> | ||
+ | |||
+ | {{linux:tmux01.png?500}} | ||
+ | |||
+ | **For HELP** | ||
+ | You can now run your first Tmux command. For example, to get a list of all commands, you would type: | ||
+ | Ctrl+b ? | ||
+ | |||
+ | To start using tmux, type tmux on your terminal. This command launches a tmux server, creates a default session (number 0) with a single window, and attaches to it. | ||
+ | |||
+ | You can detach from your tmux session by pressing **Ctrl+B** then **D**. Tmux operates using a series of keybindings (keyboard shortcuts) triggered by pressing the "prefix" combination. By default, the prefix is Ctrl+B. After that, press D to detach from the current session. | ||
+ | |||
+ | List you background sessions | ||
+ | <cli prompt='$'> | ||
+ | $ tmux ls | ||
+ | 0: 1 windows (created Sat Aug 27 20:54:58 2022) | ||
+ | </cli> | ||
+ | |||
+ | Connect to session number 0 (or maybe attach-session ?) | ||
+ | <cli prompt='$'> | ||
+ | $ tmux attach -t 0 | ||
+ | </cli> | ||
+ | As you can see, the command continued to run and print messages on the screen. You can type Ctrl+C to cancel it. | ||
+ | |||
+ | Satart a session with specific name | ||
+ | tmux new -s Session1 | ||
+ | |||
+ | TMUX options | ||
+ | * Ctrl+B D — Detach from the current session. | ||
+ | * Ctrl+B % — Split the window into two panes horizontally. | ||
+ | * Ctrl+B " — Split the window into two panes vertically. | ||
+ | * Ctrl+B Arrow Key (Left, Right, Up, Down) — Move between panes. | ||
+ | * Ctrl+B X — Close pane. | ||
+ | * Ctrl+B C — Create a new window. | ||
+ | * Ctrl+B N or P — Move to the next or previous window. | ||
+ | * Ctrl+B 0 (1,2...) — Move to a specific window by number. | ||
+ | * Ctrl+B : — Enter the command line to type commands. Tab completion is available. | ||
+ | * Ctrl+B ? — View all keybindings. Press Q to exit. | ||
+ | * Ctrl+B W — Open a panel to navigate across windows in multiple sessions. | ||
+ | |||
+ | then toggle the mouse on (or off) with the command set -g mouse. | ||
+ | |||
+ | Using colors: | ||
+ | Change the status bar background color: set -g status-bg cyan | ||
+ | Change inactive window color: set -g window-status-style bg=yellow | ||
+ | Change active window color: set -g window-status-current-style bg=red,fg=white | ||
+ | |||
+ | === Configure tmux === | ||
+ | |||
+ | You can change the tmux configuration permanently by modifying the tmux configuration file. By default, this file is located at $HOME/.tmux.conf. | ||
+ | |||
+ | For example, the default prefix key combination is Ctrl+B, but sometimes this combination is a little awkward to press, and it requires both hands. You can change it to something different by editing the configuration file. I like to set the prefix key to Ctrl+A. To do this, create a new configuration file and add these lines to it: | ||
+ | <cli prompt='$'> | ||
+ | $ cat $HOME/.tmux.conf | ||
+ | # Set the prefix to Ctrl+a | ||
+ | set -g prefix C-a | ||
+ | # Remove the old prefix | ||
+ | unbind C-b | ||
+ | # Send Ctrl+a to applications by pressing it twice | ||
+ | bind C-a send-prefix | ||
+ | </cli> | ||
+ | |||
+ | Another example | ||
+ | <code> | ||
+ | # 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 | ||
+ | </code> | ||
+ | |||
+ | === Screen === | ||
+ | |||
+ | //Only for historic info// | ||
+ | |||
+ | Screen (command) is a background terminal, you can start applications in background, quit your windows and recall your session. | ||
+ | |||
+ | Start a sceen session using a specific name | ||
+ | <cli prompt='#'> | ||
+ | # screen -S session_name | ||
+ | </cli> | ||
+ | |||
+ | Help | ||
+ | Ctrl+a ? | ||
+ | | ||
+ | Below are some most common commands for managing Linux Screen Windows: | ||
+ | |||
+ | * Ctrl+a c Create a new window (with shell). | ||
+ | * Ctrl+a " List all windows. | ||
+ | * Ctrl+a 0 Switch to window 0 (by number). | ||
+ | * Ctrl+a A Rename the current window. | ||
+ | * Ctrl+a S Split current region horizontally into two regions. | ||
+ | * Ctrl+a | Split current region vertically into two regions. | ||
+ | * Ctrl+a tab Switch the input focus to the next region. | ||
+ | * Ctrl+a Ctrl+a Toggle between the current and previous windows | ||
+ | * Ctrl+a Q Close all regions but the current one. | ||
+ | * Ctrl+a X Close the current region. | ||
+ | |||
+ | You can detach from the screen session at any time by typing: | ||
+ | Ctrl+a d | ||
+ | |||
+ | Reattach to a Linux Screen: | ||
+ | screen -r | ||
+ | |||
+ | To find the session ID list the current running screen sessions with: | ||
+ | <cli prompt='#'> | ||
+ | # screen -ls | ||
+ | |||
+ | There are screens on: | ||
+ | 10835.pts-0.linuxize-desktop (Detached) | ||
+ | 10366.pts-0.linuxize-desktop (Detached) | ||
+ | 2 Sockets in /run/screens/S-linuxize. | ||
+ | </cli> | ||
+ | |||
+ | If you want to restore screen 10835.pts-0, then type the following command: | ||
+ | screen -r 10835 | ||
+ | |||
+ | ===== limit a process ===== | ||
+ | |||
+ | You can easily limit CPU usage with cpulimit command like: | ||
+ | <cli prompt='#'> | ||
+ | # cpulimit -l 10 -- /usr/bin/clamscan -r / --exclude-dir=/sys/ --quiet --infected > /var/log/clamscan/clamscan.$(date +%Y%m%d).log | ||
+ | </cli> |