Useful Unix Commands

Change Permission on Folder/Files Recursively

GOOD

find /path/to/base/dir -type d -exec chmod 755 {} +
find /path/to/base/dir -type f -exec chmod 644 {} +

BETTER

find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644

BEST 🙂

chmod -R u+rwX,go+rX,go-w /path

SVN: Unversioned Files and Ignore List

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

svn status | grep "^\?" | awk "{print \$2}"

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

svn status | grep "^\?" | awk "{print \$2}" > unversioned.txt
svn propset svn:ignore -F unversioned.txt .
rm unversioned.txt
svn ci -m "ignore list"

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):

svn stat | grep "^[^?]"

*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:

svn stat --show-updates | grep "^[^?]"

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


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

svn --diff-cmd "diff" --extensions  "-y --suppress-common-lines" diff

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:

grep -rHn "text to search" /path/to/dir

To use a search pattern, use the following command:

grep -rHn -e "text pattern to search" /path/to/dir

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s