Tag Archives: linux

Rsync

rsync is a powerful Linux command that allows users to efficiently synchronize files and directories between two locations. It is commonly used for backups, mirroring data, and moving files between servers.

One of the key features of rsync is its ability to only copy files that have been modified, which makes it much more efficient than simply copying all files every time. It also has the ability to compress data and skip files that are already up-to-date, which further improves performance.

Here are three common use cases for the rsync command:

  1. Backing up data: rsync can be used to create backups of important files and directories. For example, the following command will create a backup of the /home directory in the /backup directory:
rsync -avz /home /backup
  1. Mirroring data: rsync can be used to create a mirror of a directory on another server. This is useful for creating a redundant copy of data for high availability. For example, the following command will create a mirror of the /var/www directory on a remote server:
rsync -avz --delete /var/www [email protected]:/var/www
  1. Transferring files: rsync can be used to transfer files between two servers. This is useful for moving large amounts of data quickly and efficiently. For example, the following command will transfer all files in the /data directory to a remote server:
rsync -avz /data [email protected]:/data

I hope this brief overview of the rsync command and its use cases has been helpful. As always, be sure to carefully read the documentation and test the command on a non-critical system before using it in a production environment

TMUX cheat sheet

Tmux is a terminal that I often use. Great benefits are if ssh disconnects the terminal remains and if I run some command, it continues to run. Other benefit is same screen for two or more ssh connections.

These are more common basic command to use in tmux

Start a new session with a specific name

tmux new -s session-5

By default , after entering the command “tmux”, sessions are named with a number

List sessions tmux ls

[email protected]:~$ tmux ls
0: 2 windows (created Sun Oct 11 13:10:12 2020) (attached)
session-5: 1 windows (created Tue Oct 13 11:26:48 2020)
[email protected]:~$

There are two sessions in this computer, named 0 and session-5.

Connect to specific session

tmux attach -t session-5

I”ll use C^ to specify CONTROL and M^ to specify ALT button. The control character for tmux is C^b. After this combination is pressed user enters control mode and perform actions like copy and paste, split windows etc.

Split session vertically

C^b %

Split session horizontally

C^b "

The result of splitting first vertically then horizontally looks like the following:

Navigate between open windows

C^b arrows

Open new window

C^b c

Detach – exit from tmux, but leave the session running

C^b d

To copy in tmux, first click C^b [. With arrows go to desired text click C^SPACE. Select desired text with arrows. Click M^w. Text copied.

To paste go to desired location to paste , click C^b ]

Tar cheat sheet

I don’t use tar very often. However every time I do, I don’t remember the switches and options. So I am making this post in order to remember the basics of the tar command.

Store files in a new archive (option -c), in file name arch.tar (option -f indicates file name), while show all output (-v).

tar -c -v -f arch.tar .

This will be the same as :

tar -cvf arch.tar .

From now on will use a short way of giving commands to the tar.

To archive files with compression add switch for compression. For gzip add -z:

tar -cvzf arch.tar .

List files (-t) within the archive (-f) arch.tar, while showing verbose output (-v) :

tar -tvf arch.tar

Extract files (-x) from archive (-f) arch.tar, while showing verbose output (-v):

tar -xvf arch.tar

Extract to specific directory use -C switch.

tar -xvf arch.tar -C arch