Photo by David Travis on Unsplash

Check the newline code of the opened file

:set fileformat?
:se ff?

Visualization of line feed code

Display line feed code

:se list

Hide newline code

:se nolist

Specify line feed code to open

LF

:edit ++fileformat=unix

CRLF

:e ++ff=dos

CR

:e ++ff=mac

Specify line feed code

:se ff=dos
:se ff=mac
:se ff=unix

Remove line feed code

:%s/\r//g

Reopen the file with the specified character code

Reopen the file in UTF-8

#Option 1
:e ++enc=utf-8
#Option 2
:edit ++enc=utf-8

Save file with specified character code

Save the file in UTF-8

#Option 1
:set fileencoding=utf-8
#Option 2
:se fenc=utf-8

Check current encoding

Vim encoding

:se enc?

File encoding

:se fenc?

--

--

Compare files under the specified directory and display only file names

diff -qr /home/vagrant/example1 /home/vagrant/example2

Compare ignoring newline spaces and newline codes

cd /home/vagrant/
diff -Bw --strip-trailing-cr example1.txt example2.txt

Display only the differences side by side

cd /home/vagrant/
diff -y example1.txt example2.txt | grep "|\|<"

Side-by-side comparison (vimdiff)

⚠️ Vim must be installed

#Option 1
cd /home/vagrant/
vimdiff example1.txt example2.txt
#Option 2
cd /home/vagrant/
vim -d example1.txt example2.txt

Diff Options

Compare by directory

diff -r /home/vagrant/example1 /home/vagrant/example2

Show file name only

diff -q /home/vagrant/example1 /home/vagrant/example2

Ignore newlines

diff -B example1.txt example2.txt

Ignore whitespace

diff -w example1.txt example2.txt

Ignore newline code

diff — strip-trailing-cr example1.txt example2.txt

Ignore case

diff -i example1.txt example2.txt

Side by side comparison

diff -y example1.txt example2.txt

--

--

Copy from remote server to local server

rsync -ahvn username@hostname:/var/www/html/website* /var/www/html/website --max-size=10M

Explanation:

  • -a → By specifying , the file will be copied under the same conditions as the copy source file as much as possible.
  • -h → Improve the visibility of the file size.
  • -v → Output details.
  • -n → Check the target file.
  • --max-size → You can specify the upper limit of the file size to be transferred with .

Viewing file transfer status

rsync -ahv --progress username@hostname:/var/www/html/website* /var/www/html/website

If you specify --progress, the transfer status is displayed for each file.

Specify ssh port in rsync

#Option 1
rsync -e "ssh -p 2233"
#Option 2
rsync --rsh="ssh -p 2233"

Rsync options

--

--

Maciej

Maciej

623 Followers

DevOps Consultant. I’m strongly focused on automation, security, and reliability.