Differences

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

Link to this comparison view

Next revision
Previous revision
en:tools:linux:file-handling [2023/09/30 14:15] – created crunchyslimeen:tools:linux:file-handling [2023/10/25 12:01] (current) admin
Line 89: Line 89:
  
 echo "done" echo "done"
 +</code>
 +
 +==== copy while preserving arborescence ====
 +[[https://ostechnix.com/copy-specific-file-types-while-keeping-directory-structure-in-linux/|source]]
 +
 +<code bash>find. -name '*.mp3' -exec cp --parents \{\}~/target\;</code>
 +
 +   * ''find'' – command to find files and folders in Unix-like systems.
 +   * The dot (''.'') - represents that we copied the contents from current directory.
 +   * ''-name ‘*.mp3''' – search for files with the extension .mp3
 +   * ''-exec cp'' – execute the ‘cp’ command to copy files from source to destination directory.
 +   * ''--parents'' - create the intermediate parent directories if needed to preserve the parent directory structure.
 +   * ''\{\}'' – is automatically replaced with the file name of the files found by the ‘find’ command. And the braces are escaped to protect them from expansion by the shell in some "find" command versions. You can also use ''{}'' without escape characters.
 +   * ''~/target'' – target directory to save the matching files.
 +   * ''\;'' – indicates it that the commands to be executed are now complete, and to carry out the command again on the next match.
 +
 +==== recursively copy all files without preserving the file tree ====
 +
 +<code bash>find. -name '*.PNG' -exec cp\{\}allpics/\;</code>
 +
 +Here we are at the root of the file tree to explore and the destination folder is ''allpics''.
 +
 +==== list the differences between two directories ====
 +count the differences
 +<code bash>diff -y <(cd /path/to/files/1/ && ls -R) <(cd /path/to/files/2/ && ls -R) | wc -l</code>
 +
 +list the differences in diff.log
 +<code bash>diff -y <(cd /path/to/files/1/ && ls -R) <(cd /path/to/files/2/ && ls -R) > diff.log</code>
 +
 +adding ''grep -E \/'' or ''-d'' on the ''ls'' allows you to list directories
 +
 +==== list the duplicates ====
 +[[https://buildvirtual.net/how-to-find-duplicate-files-on-linux/|source]]
 +
 +**detect duplicates**
 +
 +<code bash>fdupes -Sr .</code>
 +
 +==== Disk usage ====
 +Usefull commands : 
 +<code bash>
 +#liste the 30 largest files in filetree
 +du -Sh | sort -rh | head -30</code>
 +<code bash>
 +#ncurse disk usage
 +ncdu
 +#on remote system
 +ssh -C user@system ncdu -o- / | ./ncdu -f-
 </code> </code>
  • en/tools/linux/file-handling.1696076158.txt.gz
  • Last modified: 2023/09/30 14:15
  • by crunchyslime