rsync command

rsync is very useful program to backup the files.
-a is archive mode, it will reverse the created date of the files.
-v is the verbose, it can give you more information when rsync is running.
-z means to compress file data during the transfer.
-h means to output numbers in a human-readable format.
--delete is to delete the files in destination but not in the sources ( just like to create the identical copy).

rsync -avzh --delete --ignore-errors xxx@server:/test/ ./external_drive/




ssh/scp without login password

Suppose you want to login from your laptop to a server by ssh, each time you probably will be asked to input the password. Here are instructions to skip this step, but make sure your laptop will be safe, and no other people will use it.

Step 1:
in your laptop
ssh-keygen -t rsa -b 2048 , and hit enter key to accept the default setting.

Step 2:
in your laptop
ssh-copy-id username@XXXserver

That is all you need to do, next time you won't need to input the password.




cut command

cut command is useful for extracting data. Suppose we have

		field1 field2 field3 fiedl4
		----------------------------------------- 
		aaaaaa bbbbbb cccccc dddddd
		aaaaaa bbbbbb cccccc dddddd
		aaaaaa bbbbbb cccccc dddddd
	    

The above data structure uses space as delimiter, which separate the field 1, field 2, and field 3.
Let's say we will to show the field 1 and filed 3.

cut -d ' ' -s -f 1,3 source.txt

-d ' ' is to use ' ' as delimiter.
-s is to limited for the following fields
-f 1,3 apply to field 1 and field 3

The results will be:
		aaaaaa cccccc
		aaaaaa cccccc
		aaaaaa cccccc
	    




find command

find command has many applications:
suppose we want to find the files we edited within 5 days ago.
find . -mtime -5 -iname "*.txt"

. means the current folder
-mtime means the modified time
-iname means the file name and ignore the case

-   -   -   -   -   -   -   -   -   -   -   -  -   -   -   -   -   -   -   -   -   -   -  -  -

suppose we want to find the files with the sizes larger than 5 MB.
find . -size +5M
find / -type f -size +10M -exec ls -lh {} \; 2>/dev/null
Here, you can list the file as well.

. means the current folder
-size means the file size
+5M means larger than 5MB