User Tools

Site Tools


ubuntu:file:copy_files_to_different_directory

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
ubuntu:file:copy_files_to_different_directory [2022/05/10 20:12] peterubuntu:file:copy_files_to_different_directory [2022/06/13 10:16] (current) – removed peter
Line 1: Line 1:
-====== Ubuntu - File - Copy files to different directory ====== 
- 
-<code bash> 
-#!/bin/bash                                                                                                                                                                                                  
- 
-for filename in *; do 
-  if [[ -f "$filename" ]]; then 
-    base=${filename%.*} 
-    ext=${filename#$base.} 
-    mkdir -p "${ext}" 
-    mv "$filename" "${ext}" 
-  fi 
-done 
-</code> 
- 
----- 
- 
-===== Copy all files by extension to single directory ===== 
- 
-<code bash> 
-find . -name \*.txt -exec cp {} someDirectory \; 
-</code> 
- 
-or 
- 
-<code bash> 
-find . -name "file*" -exec mv {} /tmp \; 
-</code> 
- 
-<WRAP info> 
-**NOTE:**  The open brackets **{}** are a placeholder for the argument which is to be used from the output of find. 
-</WRAP> 
- 
-<WRAP info> 
-**NOTE:**  Why not just use **mv file* /tmp**. 
- 
-  * Problem with Moving Large Number of Files 
-    * Linux systems have a predefined limit on the maximum number of arguments that can be used with a single command. 
-    * This limit varies from system to system based on the stack size. 
-    * Thus, if a very high number of files are being specified with the wildcard; e.g. over a hundred thousand files, it throws an error: **Argument list too long**. 
- 
-</WRAP> 
- 
----- 
  
ubuntu/file/copy_files_to_different_directory.1652213547.txt.gz · Last modified: 2022/05/10 20:12 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki