Linux

System

Shell

Show current shell.

CLI
1
echo $SHELL

Show available shells.

CLI
1
cat /etc/shells

Change shell for current user.

CLI
1
chsh

Data


Synchronizing


Lsyncd

axkibe/lsyncd
lsyncd实时同步搭建指南——取代rsync+inotify

CLI
1
brew install lsyncd

Rsync

Rsync (Remote Sync): 10 Practical Examples of Rsync Command in Linux
rsync 用法教程
How To Use Rsync to Sync Local and Remote Directories
Linux下文件实时自动同步备份

Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. With the help of rsync command you can copy and synchronize your data remotely and locally across directories, across disks and networks, perform data backups and mirroring between two Linux machines.

Some advantages and features of Rsync command

  • It efficiently copies and sync files to or from a remote system.
  • Supports copying links, devices, owners, groups and permissions.
  • It’s faster than scp (Secure Copy) because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.
  • Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends.

Basic syntax of rsync command

CLI
1
rsync [options] [source] [destination]

Some common options used with rsync commands

  • v: verbose
  • r: copies data recursively (but don’t preserve timestamps and permission while transferring data
  • a: archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
  • z: compress file data
  • h: human-readable, output numbers in a human-readable format

Examples

This following command will sync a single file on a local machine from one location to another location. Here in this example, a file name backup.tar needs to be copied or synced to /tmp/backups/ folder.

CLI
1
2
3
4
5
6
7
8
9
rsync -zvh backup.tar /tmp/backups/

# created directory /tmp/backups

# backup.tar

# sent 14.71M bytes received 31 bytes 3.27M bytes/sec

# total size is 16.18M speedup is 1.10