User Tools

Site Tools


files

This is an old revision of the document!


Files

File Types

$ ls -l # shows type in the first character of the file permissions column

where type is:
  * - : regular file
  * d : directory
  * c : character device file
  * b : block device file
  * s : local socket file
  * p : named pipe
  * l : symbolic link
$ ls -F # appends symbols to filenames

where symbol is:
  * @ : symbolic link (or that the file has extended attributes)
  * * : executable
  * = : socket 
  * | : named pipe
  * > : door
  * / : directory

Soft link

$ ln -s filename linkname
$ ln -s /media/john/Seagate\ Expansion\ Drive/ /seagate
$ unlink /seagate

filename wildcards

$ rm *.?????[!3]?[!1].*.sql # delete all files not in march and not day 1
$ rm *.?????[!3][!0]?.*.sql # delete all files not in march and not day 11, 21, or 31

tree

$ tree # draw tree structure of folders

find

$ find . -name *.plugin
$ find . -name *.plugin 2>/dev/null
$ find /media/seagate/media/ -name Thumbs.db -exec rm {} \; # delete files across folders
$ find . -name "*.js" -exec java -jar compiler.jar --js {} --js_output_file new{} \;
$ find . -name "*.jpg" -exec convert {} -resize 1920x1080 ../assets_youtube/{} \; 

find unique list of file types

$ find ../ -type f | awk -F. '!a[$NF]++{print $NF}'

find and execute command on files across files

$ find /media/seagate/media/ -name Thumbs.db -exec rm {} \; # delete files across folders
$ find ../ -type f \( -name "*.jpg" -o name "*.JPG" \) -exec rm {} \;
$ find ../ -type f -name "*.JPG" -exec rename s/JPG/jpg/ {} \;

find a file anywhere on the disk and ignore the “Permission denied” messages

$ find / -name Wire.h 2>&1 | grep -v "Permission denied"

grep

$ grep -r "progressive" . 

rename

$ rename s/JPG/jpg/ *

copy files

$ mv SRC DEST
$ cp SRC DEST
$ scp SRC DEST
$ rsync SRC DEST

synchronize two external hard disks, dry run, real thing, ending slash required

rsync --dry-run --itemize-changes -avh /media/john/My\ Passport/pub/ /media/john/Seagate\ Expansion\ Drive/pub/
rsync -avh /media/john/My\ Passport/pub/ /media/john/Seagate\ Expansion\ Drive/pub/
  1. -dry-run
  2. -itemize-changes
  3. -delete, delete extraneous files from destination (dest will mirror src)
  4. a –archive, equivalent to -rlptgoD
    1. r –recursive
    2. l –links, copy symlinks as symlinks
    3. p –perms, preserve permissions
    4. t –times, preserve modification times
    5. g –group, preserve group
    6. o –owner, preserve owner
    7. D preserve device files, preserve special files
  5. v –verbose
  6. h –human-readable number formats

sync songs from hard disk to phone, skipping the cover art

rsync --delete -avh -e "ssh -p 2222" --exclude '*.jpg' /media/passport/pub/songs/ '192.168.1.100:/storage/emulated/0/media/songs/'
files.1704543059.txt.gz · Last modified: 2024/01/06 07:10 by jhagstrand

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki