linux:start

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux:start [2026/04/26 22:15] – [Repair FAT32 filesystem errors] mhlinux:start [2026/07/02 21:26] (current) – [File operations] mh
Line 213: Line 213:
  
 ====== File & Data Operations ====== ====== File & Data Operations ======
 +
 +===== Shell toolbox =====
 +
 +==== File operations ====
 +
 +=== Mass renaming ===
 +
 +__**Changing an extension:**__
 +
 +<code bash>
 +for i in *.JPG; do mv "$i" "${i/.JPG/.jpg}"; done
 +</code>
 +
 +__**Changing a prefix:**__
 +
 +<code bash>
 +for i in "prefix"*.png; do
 +  mv -n -- "$i" "${i/#prefix/another prefix}"
 +done
 +</code>
 +
 +  * ''"prefix"*.png'' targets only files beginning with the selected prefix, so unrelated files in the folder are ignored.
 +  * ''${i/#prefix/another prefix}'' replaces only the prefix at the beginning of the filename. If the same text appears later in the filename, it is left untouched.
 +  * In Bash parameter expansion, the ''#'' before ''prefix'' means “match only at the start of the variable value”. Without ''#'', Bash would replace the first matching occurrence anywhere in the filename.
 +  * ''mv -n'' prevents overwriting an existing file if the renamed target already exists.
 +  * ''--'' tells ''mv'' that everything after it is a filename, not an option. This protects against unusual filenames starting with ''-''.
 +  * ''"$i"'' keeps the original filename safely quoted, so spaces and special characters in filenames are preserved.
 +
 +__**Alternative (rename tool):**__
 +
 +<code bash>
 +rename 's/\.JPG$/.jpg/' *.JPG
 +</code>
 +
 +  * Use the ''for ... done'' + ''mv -n --'' loop for safe, explicit prefix renaming.
 +  * Use ''rename'' for concise regex-based changes, especially extension changes such as ''.JPG'' to ''.jpg''.
 +  * On Linux Mint / Ubuntu, ''rename 's/\.JPG$/.jpg/' *.JPG'' usually works because the available ''rename'' is the Perl-style tool.
 +  * The ''rename'' command is not fully portable across all Linux distributions, because different systems may ship different versions with different syntax.
 +  * For safety, preview first with ''rename -n 's/\.JPG$/.jpg/' *.JPG''.
 +
 +----
 +
 +=== Empty a file ===
 +
 +<code bash>
 +: > /path/to/file
 +</code>
 +
 +----
 +
 +==== Text processing ====
 +
 +=== cut ===
 +
 +Extract part of a string:
 +
 +<code bash>
 +date | cut -c17-24
 +</code>
 +
 +----
 +
 +==== Archives ====
 +
 +=== tar ===
 +
 +<code bash>
 +# Extract
 +tar -xvf file.tar
 +tar -xvzf file.tar.gz
 +
 +# Create
 +tar -cvf file.tar /path/folder
 +tar -cvzf file.tar.gz /path/folder
 +</code>
 +
 +Flags:
 +
 +  * ''c'' create archive
 +  * ''x'' extract archive
 +  * ''v'' verbose (list files processed)
 +  * ''f'' specify archive file
 +  * ''z'' gzip compression
 +
 +----
 +
 +====== User Environment ======
 +
 ===== PATH ===== ===== PATH =====
 <WRAP round info> <WRAP round info>
Line 420: Line 508:
 It often reduces file size, especially with image-heavy PDFs, but this is not guaranteed. It often reduces file size, especially with image-heavy PDFs, but this is not guaranteed.
 </WRAP> </WRAP>
- 
- 
- 
- 
-===== Data recovery ===== 
- 
-Use **TestDisk** / **PhotoRec** as a first recovery tool. 
- 
-  * **TestDisk** attempts partition repair and file undelete when filesystem metadata is still usable. 
-  * **PhotoRec** performs file carving by signature. It can recover files from damaged filesystems, but filenames and folder structure are usually lost. 
- 
-Do not write recovered files to the source disk. 
- 
-==== PhotoRec: recovered MOV files ==== 
- 
-For some recovered ''.mov'' files, PhotoRec may split the video into separate ''ftyp'' and ''mdat'' parts. 
- 
-In PhotoRec ''FileOpts'', enable: 
- 
-<code> 
-[X] mov/mdat Recover mdat atom as a separate file 
-</code> 
- 
-Sort recovered files by name, then try concatenating matching parts: 
- 
-<code bash> 
-cat f123_ftyp.mov f456_mdat.mov > recovered_1.mov 
-cat f456_mdat.mov f123_ftyp.mov > recovered_2.mov 
-</code> 
- 
-One order may produce a usable file. 
- 
-Sometimes the header/container part may be ''.mp4'' while the media data part is ''.mov'': 
- 
-<code bash> 
-cat f54114560.mp4 f51781632_mdat.mov > recovered.mov 
-</code> 
- 
-Note: This is a recovery attempt, not a guaranteed repair method. For valuable data, stop using the disk immediately and clone/image it before experimenting. 
- 
  
 ===== Video playback (minimal UI) ===== ===== Video playback (minimal UI) =====
Line 511: Line 559:
 osdlevel=0 osdlevel=0
 </code> </code>
 +
 +
 +
 +====== Specialized & Recovery ======
 +
 +===== Data recovery =====
 +
 +Use **TestDisk** / **PhotoRec** as a first recovery tool.
 +
 +  * **TestDisk** attempts partition repair and file undelete when filesystem metadata is still usable.
 +  * **PhotoRec** performs file carving by signature. It can recover files from damaged filesystems, but filenames and folder structure are usually lost.
 +
 +Do not write recovered files to the source disk.
 +
 +==== PhotoRec: recovered MOV files ====
 +
 +For some recovered ''.mov'' files, PhotoRec may split the video into separate ''ftyp'' and ''mdat'' parts.
 +
 +In PhotoRec ''FileOpts'', enable:
 +
 +<code>
 +[X] mov/mdat Recover mdat atom as a separate file
 +</code>
 +
 +Sort recovered files by name, then try concatenating matching parts:
 +
 +<code bash>
 +cat f123_ftyp.mov f456_mdat.mov > recovered_1.mov
 +cat f456_mdat.mov f123_ftyp.mov > recovered_2.mov
 +</code>
 +
 +One order may produce a usable file.
 +
 +Sometimes the header/container part may be ''.mp4'' while the media data part is ''.mov'':
 +
 +<code bash>
 +cat f54114560.mp4 f51781632_mdat.mov > recovered.mov
 +</code>
 +
 +Note: This is a recovery attempt, not a guaranteed repair method. For valuable data, stop using the disk immediately and clone/image it before experimenting.
 +
 +
  
 ===== Using Apple USB SuperDrive ===== ===== Using Apple USB SuperDrive =====
Line 716: Line 806:
 </WRAP> </WRAP>
  
-===== Shell toolbox ===== 
  
-==== File operations ==== 
- 
-=== Mass renaming === 
- 
-Uppercase .JPG to lowercase .jpg 
- 
-<code bash> 
-for i in *.JPG; do mv "$i" "${i/.JPG/.jpg}"; done 
-</code> 
- 
-Alternative (rename tool): 
- 
-<code bash> 
-rename 's/\.JPG$/.jpg/' *.JPG 
-</code> 
- 
----- 
- 
-=== Empty a file === 
- 
-<code bash> 
-: > /path/to/file 
-</code> 
- 
----- 
- 
-==== Text processing ==== 
- 
-=== cut === 
- 
-Extract part of a string: 
- 
-<code bash> 
-date | cut -c17-24 
-</code> 
- 
----- 
- 
-==== Archives ==== 
- 
-=== tar === 
- 
-<code bash> 
-# Extract 
-tar -xvf file.tar 
-tar -xvzf file.tar.gz 
- 
-# Create 
-tar -cvf file.tar /path/folder 
-tar -cvzf file.tar.gz /path/folder 
-</code> 
- 
-Flags: 
- 
-  * ''c'' create archive 
-  * ''x'' extract archive 
-  * ''v'' verbose (list files processed) 
-  * ''f'' specify archive file 
-  * ''z'' gzip compression 
- 
----- 
  
  
  • linux/start.1777234505.txt.gz
  • Last modified: 2026/04/26 22:15
  • by mh