Useful Linux Shell Commands

From Metro Studios Knowledgebase

Jump to: navigation, search

Contents

[edit] Apache 2

Enable a virtual host:

sudo a2ensite virtual-host.com

Disable a virtual host:

sudo a2dissite virtual-host.com

Enable a module:

sudo a2enmod module

Disable a module:

sudo a2dismod module

[edit] Upgrading / Patching

[edit] Distribution Releases

Do release update (requires update-manager-core):

sudo do-release-upgrade

[edit] Aptitude

Update Aptitude's sources and patch the server's software to most recent version:

sudo apt-get update
sudo apt-get upgrade

[edit] MySQL

MySQL Backup/Restore

[edit] Searching

Search for text within files and dump results to "grep_results.txt" in the current user's home directory:

sudo grep "text-to-search" /directory/to/search/ -R > ~/grep_results.txt

Search for a file by name in the current working directory and it's sub-directories:

find . -name *FILENAME*

Find and replace text within a file:

sed -i 's/string_to_search/string_to_replace/g' file

[edit] User Management

Add a user to a group:

sudo usermod -a -G group user

Check user's last login time:

sudo last kkhaldi

[edit] ACL

Get the ACL of a file or directory:

getfacl /path/to/file/or/dir

Set the ACL of a file or a directory based off of ACL entries within a file. (the -R argument is for recursion, the -M is for the permissions file)

setfacl -MR ~/perms.acl directory

[edit] Compression

Decompress a gzipped tar ball:

tar -xvzf tarball.tar.gz

Decompress a bzipped tar ball:

tar -xvjf tarball.tar.bz2

[edit] File Comparison

Check the MD5sum of a file:

md5sum file

Check the differences between files:

diff file1 file2

[edit] Image Manipulation

Resize JPEG images to a maximum of 600x600 at 85 quality. This will overwrite the original files, so make backups first!

mogrify -verbose -resize 600x600\> -quality 85 *.jpg

[edit] Permissions

Set permissions only on directories within the current directory and all sub-directories:

find . -type d -exec chmod 755 {} \;

Set permissions only on files within the current directory and all sub-directories:

find . -type f -exec chmod 644 {} \;
Personal tools
Namespaces
Variants
Actions
Wiki Navigation
Knowledgebase
Toolbox