Useful Unix Commands

Change Permission on Folder/Files Recursively

GOOD

[code lang=text]
find /path/to/base/dir -type d -exec chmod 755 {} +
find /path/to/base/dir -type f -exec chmod 644 {} +
[/code]

BETTER

[code lang=text]
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
[/code]

BEST 🙂

[code lang=text]
chmod -R u+rwX,go+rX,go-w /path
[/code]


SVN: Unversioned Files and Ignore List

Use this command to get the list of files not under SVN:

[code lang=text]
svn status | grep "^\?" | awk "{print \$2}"
[/code]

If one were to find the unversioned files to ignore them from versioning, this would be handy:

[code lang=text]
svn status | grep "^\?" | awk "{print \$2}" > unversioned.txt
svn propset svn:ignore -F unversioned.txt .
rm unversioned.txt
svn ci -m "ignore list"
[/code]


SVN: Show Pending Check-ins

Use this command to get the list of pending check-ins (similar to the pending check-ins in Tortoise SVN):

[code lang=text]
svn stat | grep "^[^?]"
[/code]

*Would be really handy and nifty if you define an alias for the above command.


SVN: (Tortoise SVN like) Show Modifications

Use this command to show what are the effective changes – those have changed on the server and also the ones that have changed locally in your code base:

[code lang=text]
svn stat –show-updates | grep "^[^?]"
[/code]

*Would be really handy and nifty if you define an alias for the above command.


SVN: Compare Files – Show differences side-by-side

[code lang=text]
svn –diff-cmd "diff" –extensions "-y –suppress-common-lines" diff
[/code]


Everyday grep

To look up files recursively in the given directory for the given text, and display the file name with line number that has the matching text:

[code lang=text]
grep -rHn "text to search" /path/to/dir
[/code]

To use a search pattern, use the following command:

[code lang=text]
grep -rHn -e "text pattern to search" /path/to/dir
[/code]

r – search recursively, H – display the file name with the matching text, n – display the line number in the file with the matching text