Sunday, 1 February 2015
Linux Script - Useful Ones
[Tested in cygwin]
1. Find Strings in the Dir.
find [Dir Path] -type f -name "*.[FileTypePostFix]" | xargs grep "[search string]" -bn --color=auto
e.g.
find . -type f -name "*.substvar" | xargs grep "P1O1" -bn --color=auto
2. Copy the Dir Structure under specific Dir (auto creates all the non-exist dirs)
Instruction:
XCOPY <<SourceFolder>> <<Destination>> /O /X /E /H /K /T
/E - Copies folders and subfolders, including empty ones.
/H - Copies hidden and system files also.
/K - Copies attributes. Typically, Xcopy resets read-only attributes.
/O - Copies file ownership and ACL information.
/X - Copies file audit settings (implies /O).
/T : Copies the subdirectory structure (that is, the tree) only, not files
(To copy empty directories, you must include the /e command-line option.)
Ex:
xcopy C:\temp D:\temp /O /X /E /H /K /T
It copies all the dir structure under C:\temp to D:\temp
3. Remove dup-record in the file
sort -u input.txt > output.txt
4. Find specific file
find . -type f -name '*.xml'
5. Find file numbers in dir and sub dir
find . -type f |wc -l
6. list all dirs:
find . -type d
7. Remove Files Postfix
find -type f -name '*.temp' -print0 | while read -d $'\0' f; do mv "$f" "${f%.temp}"; done
Labels:
Linux
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment