Saturday, January 18, 2014

Useful recipes

  • Change encoding of files
    The following example uses iconv to change the encoding of all the .php files in a folder tree from ISO-88592 to UTF8.

    find . -name "*.php" -exec sh -c "( \
    iconv -f ISO88591 -t UTF8 {} -o {}.iconv ; \
    mv {}.iconv {} ; echo {}; \
    )" \;

    Remember to backup your data just in case. This will recursively find the appropriately named files and re-encode them (the temporary file is necessary, as iconv otherwise destroys the input). You might also want to convert other files (.html).
    See also this link

  • Match and delete files recursively
    The following example deletes files ending in tilde (~), which usually are temporary or backup files

    find . -type f -name '*~' -exec rm -f '{}' \;

  • List all files in $PATH

    for i in `echo $PATH | tr ':' '\n'`; do echo $i; ls $i; done

No comments:

Post a Comment