Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
comp:commands [2022/09/24 14:32] Bernard Condraucomp:commands [2026/07/19 17:24] (current) – [Copy all files except some in all sub directories] Bernard Condrau
Line 13: Line 13:
  
 ===== Copy files between servers ===== ===== Copy files between servers =====
-  Copy between servers in the same network as user<code>$ rsync -avz -e 'ssh -p 22' <dir> <user>@<ip-address>:/path/to/dir/</code> +  Copy between servers with user privileges<code>$ rsync -avz -e 'ssh -p 22' dir user@x.x.x.x:/path/to/dir/</code> 
 +  - Copy between servers with root privileges<file>$ rsync -avz -e 'ssh -p 22 -i /home/user/.ssh/id_ecdsa' --rsync-path="sudo rsync" dir user@x.x.x.x:/path/to/dir/</file> 
 +    * also enable the user on the target machine to run rsync with root privileges, to do so create file ''/etc/sudoers.d/rsync'' (line 1) with content (line 2)<code>$ sudo visudo /etc/sudoers.d/rsync 
 +user ALL = NOPASSWD:/usr/bin/rsync</code> 
 +  Copy from cloud<code>$ rsync -avz -e 'ssh -p 22 -i /path/to/identity/file' --info=progress2 user@x.x.x.x:/path/to/dir/ /local/dir/</code>
 ===== File Management ===== ===== File Management =====
 +
 +==== Read very large text file ====
 +  tail -n 100 ./file-name.txt
 +  head -n 100 ./file-name.txt
  
 ==== Copy all files except some in all sub directories ==== ==== Copy all files except some in all sub directories ====
Line 28: Line 35:
  
 ==== Find all files containing specific text ==== ==== Find all files containing specific text ====
-  grep -rnw '/path/to/somewhere/' -e 'pattern'+  * Since you have GNU find/xargs, this is a safe way for xargs to read filenames:<code>find . -type f -print0 | xargs -0 grep "some string"</code> 
 +  * If you only want the filenames that have a matching line without showing the matching line:<code>find . -type f -print0 | xargs -0 grep -l "some string"</code> 
 ==== Find all files which were modified within the last month from the current directory ==== ==== Find all files which were modified within the last month from the current directory ====
   find . -newermt $(date +%Y-%m-%d -d '1 month ago') -type f -print   find . -newermt $(date +%Y-%m-%d -d '1 month ago') -type f -print
Line 47: Line 56:
 ==== Determine size of a folder path ==== ==== Determine size of a folder path ====
   du -hs   du -hs
 +
 +==== Find size of all sub-directories (only 1 level) ====
 +  find -maxdepth 1 -type d -path ./proc -prune -o -exec du -hs "{}" \;
  
 ==== Change permissions for all files in a directory tree ==== ==== Change permissions for all files in a directory tree ====