Bash


One liners

To find a sting in a directory of gzipped files - log files etc -

needle is the search term.

 gunzip -c  *.gz|grep -H needle

When you are running out of disk space - find the big files - first find huge directories:

du --human-readable | sort --human-numeric-sort -r | head

Then the file(s)

find /var/ -type f -iname "*" -printf '%s %p\n'| sort -nr | head -10

Rename files and directories - spaces to underscore

$ find -name "* *" -type d | rename 's/ /_/g'    # do the directories first
$ find -name "* *" -type f | rename 's/ /_/g'

Copy directory tree with only one file type

rsync -avm --include='*.mp3' -f 'hide,! */' from_dir/ /to_dir

The entire directory structure from from_dir/  is copied to /to_dir, but only the .mp3 files are copied.
-a ensures all permissions and times on files are unchanged.
-m will omit empty directories.
-v is for verbose output.
--include is a simplified filter rule. In this case hide keeps files from the transfer - the comma separates the prefix from a modifier

-f is a filter rule

-n prints out a dry run - it will tell you what it would do but not actually copy anything.

If you don't want the top directory use the trailing slash.




Top Page wiki Index

Disclaimer

This information may have errors; It is not permissible to be read by anyone who has ever met a lawyer.
Use is confined to Engineers with more than 370 course hours of electronic engineering for theoretical studies.
ph +1(785) 841-3089

Email inform@xtronics.com

(C) Copyright 1994-2017, Transtronics, Inc. All rights reserved
Transtronics® is a registered trademark of Transtronics, Inc.
All trademarks are the property of their respective owners.