Skip to content

Instantly share code, notes, and snippets.

@jimboobrien
Last active March 14, 2016 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimboobrien/4bac9df1f45267a77bdd to your computer and use it in GitHub Desktop.
Save jimboobrien/4bac9df1f45267a77bdd to your computer and use it in GitHub Desktop.
/*~~~~~~~~~~~~~
RESTART SERVICES
~~~~~~~~~~~~~~~*/
restart apache:
service named restart
OR
/scripts/restartsrv_apache
service iptables restart
/*~~~~~~~~~~~~~
FIND / SEARCH
~~~~~~~~~~~~~~~*/
find . -name myFile.txt
grep -r "192.168.1.5" /etc/
/*~~~~~~~~~~~~~
FIND WHAT VERSION OF LINUX YOU ARE RUNNING
~~~~~~~~~~~~~~~*/
uname a
cat /etc/*-release
/*~~~~~~~~~~~~~
CPU / RAM / RESOURCE MANAGEMENT
~~~~~~~~~~~~~~~*/
(Prints just the 1 minute load average)
echo ''; sar -q -f /var/log/sa/sa01 | grep -E '[1-9]+[0-9]*[0-9]*\...' | awk -v one=' 1 Minute Load Average' '{print $1, $2, $5, one}'; echo ''
Change the grep -E number to get a specific load average
(Prints just the 5 minute load average)
echo ''; sar -q -f /var/log/sa/sa01 | grep -E '[1-9]+[0-9]*[0-9]*\...' | awk -v five=' 5 Minute Load Avg' '{print $1, $2, $6, five}'; echo ''
(Prints just the 15 minute load average)
echo ''; sar -q -f /var/log/sa/sa01 | grep -E '[1-9]+[0-9]*[0-9]*\...' | awk -v fifteen=' 15 Minute Load Avg' '{print $1, $2, $7, fifteen}'; echo ''
/*~~~~~~~~~~~~~
COPY / MOVE
~~~~~~~~~~~~~~~*/
copy folder and say yes to overwrite:
yes | cp -rf /home/direcotry/to/folder /home/folder/to/copy/to
/*~~~~~~~~~~~~~~~~~~~~~~
Changing Permissions
~~~~~~~~~~~~~~~~~~~~~~~*/
Folder permissions are change in exactly the same way. For example:
chmod 755 images
will change the permissions to 755 of a folder called images that's in the current working directory. This, however, will only change the permissions of the folder itself. If you want to change the permissions recursively, meaning to change the permissions of the folder and everything in it, you can use the -R option. For example:
chmod -R 755 images
will change the permissions to 755 of the folder images and all the subfolders and files inside it. You can also change the permissions of several folders with one command by listing them (e.g. chmod 755 files images scripts).
The chmod command can also be very useful in combination with other commands. For example, if you want to change the permissions of all files but you don't want the permissions of the folders to be changed, you can execute the following command:
find . -type f -exec chmod 644 {} \;
It will change the permissions of all files in the current working directory and those in all its subdirectories to 644.
In a similar way you can change the permissions of all folders without modifying the permissions of files. The following command:
find . -type d -exec chmod 755 {} \;
will change the permissions of all directories in the current working directory (and the subdirectories of those directories) to 755.
chown -R owner:group directory
How to check if a particular domain is owned by any particular user:
/scripts/whoowns mydomain.com owner
OR
grep mydomain.com /etc/userdomains
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MOUNTING DISKS / DISK UTILITY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Check disks for filesystem type:
sudo fdisk -l
Mount the drive:
mount -t ext3 /dev/sdb1 /home/jim/folder
find out how much storage the current folder consumes
du -sh
show human readable storage of current folder
du -h --max-depth=1 .
/* ~~~~~~~~~~~~~~~
Special command - that will show you a bar graph (horizontal) in
command line showing the directories that consume most
of the space in a percentage
~~~~~~~~~~~~~~~~~*/
t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');du / –exclude /proc –exclude /sys –max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++) {printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}'
OUTPUT LOOKS LIKE THIS:
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| / 74.9925% total
|||||||||||||||||||||||||||||||||||| /home 42.0249% total
||||||||||||||||||||| /usr 23.4493% total
||||||||||||| /usr/local 15.2291% total
||||||||||| /usr/local/cpanel 12.4911% total
|||||||| /home/southerntatler 9.18143% total
|||||||| /home/southerntatler/public_html 9.11341% total
|||||||| /home/southerntatler/public_html/wp-content 8.70109% total
||||||| /home/theloft 7.90133% total
||||||| /home/vqdev 7.8221% total
||||||| /home/vqdev/public_html 7.80835% total
|||||| /home/southerntatler/public_html/wp-content/infinitewp 6.7047% total
|||||| /home/southerntatler/public_html/wp-content/infinitewp/backups 6.70468% total
|||||| /home/theloft/public_html 6.11472% total
|||||| /home/theloft/public_html/wp-content 5.947% total
||||| /home/roswellghost 4.80236% total
||||| /home/roswellghost/public_html 4.71811% total
|||| /var 4.47821% total
/*~~~~~~ end ~~~~~~ */
/*~~~~~~~~~~~~~~~~~~~~~~
MySQL COMMANDS
~~~~~~~~~~~~~~~~~~~~~~~*/
Sign in:
remove table:
DROP DATABASE dbname;
create:
CREATE DATABASE dbname;
import:
mysql -p -u username database_name < file.sql
export:
mysqldump -p -u wpuser wp-db-1 > database-bkp.sql
/*~~~~~~~~~~~~~~~~~~~~~~
ZIP/UNZIP COMMANDS
~~~~~~~~~~~~~~~~~~~~~~~*/
zip -r filename.zip foldername/
tar -xfvz filename.tar.gz
Not sure what this one does:
tar cjf <filename>.tar.bz2 <file1><file2>..
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LIST ALL USERS / CREATE NEW USER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
list all users:
cat -d: -f1 /etc/passwd
add user:
adduser newuser
change users:
su - newuser
add user to sudoers file (as root):
visudo
add this line:
newuser ALL=(ALL:ALL) ALL
/* ~~~~~~~~~~~~~~~
Special command for creating a new user and assigning them
to a new usergroup and with that ownership
~~~~~~~~~~~~~~~~~*/
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Tomcat Java Servlet and JSP engine' \
--group \
--disabled-password \
--home /home/tomcat \
tomcat
OUTPUT LOOKS LIKE THIS:
Adding system user 'tomcat' (UID 108) ...
Adding new group 'tomcat' (GID 113) ...
Adding new user 'tomcat' (UID 108) with group 'tomcat' ...
Creating home directory '/home/tomcat' ...
/*~~~~~~ end ~~~~~~ */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZONE FILES / CPANEL / WHM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
How to check if the zone file for the domain exists:
ls -ld /var/named/mydomain.com.db
remove zone File:
/scripts/killdns mydomain.com
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WORDPRESS FIX ALL FOLDER AND FILE PERMISSIONS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
RUN THIS IN THE ROOT OF YOUR WORDPRESS INSTALL IN SSH!!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
find . -type f -name "wp-config-sample.php" -o -name "readme.html" -o -name "README.txt" -o -wholename "wp-admin/install.php" -exec rm -f {} \; && find . -type d -exec chmod 0755 {} \; && find . -type f -exec chmod 0644 {} \; && find . -name "wp-config.php" -exec chmod 600 {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment