<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://serverkb.co.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rootadminacc</id>
	<title>Server Knowledge Base - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://serverkb.co.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rootadminacc"/>
	<link rel="alternate" type="text/html" href="http://serverkb.co.uk/wiki/Special:Contributions/Rootadminacc"/>
	<updated>2026-04-09T11:35:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.4</generator>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=134041</id>
		<title>Minecraft</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=134041"/>
		<updated>2025-05-02T21:42:00Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Server host/IP: play.bywatercraft.co.uk / 51.89.214.136&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Currently the Bywater Craft Minecraft server is running Paper 1.21.4.&lt;br /&gt;
&lt;br /&gt;
Load Minecraft:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/usr/bin/java -Djline.terminal=jline.UnsupportedTerminal -client -Xmx7132M -jar spigot.jar nogui -d yyyy-MM-dd HH:mm:ss -nojline&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n minecraft&lt;br /&gt;
cd /home/user&lt;br /&gt;
./MCMA2_Linux_x86_64 | tee yourminecraft.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to connect from elsewhere to view the above output/console load the screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh user@localhost -pXXXX&lt;br /&gt;
tmux ls&lt;br /&gt;
tmux attach 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To kill the process on boot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps -ef | grep tmux | grep -v grep | awk &#039;{print $2}&#039; | xargs kill -9&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using CTRL + D will quit screen and close any processes running within it.&amp;lt;br&amp;gt;&lt;br /&gt;
To exit safely do CTRL + B, let go, then press D on it&#039;s own. &lt;br /&gt;
&lt;br /&gt;
When downloading a backup from McMyAdmin, it comes in the mcb format. Change it to .zip and you can then unzip it into a folder and restore to the server.&lt;br /&gt;
&lt;br /&gt;
== Allowing PvP ==&lt;br /&gt;
&lt;br /&gt;
Personally, for WorldGuard&#039;s pvp flag to work we had to ensure:&lt;br /&gt;
&lt;br /&gt;
* Essentials plugin had pvp = true&lt;br /&gt;
* McMyAdmin control panel had Configuration &amp;gt; Game Settings &amp;gt; Allow Player vs Player combat&lt;br /&gt;
* server.properties file had pvp = true&lt;br /&gt;
* WorldGuard had __global__ set to pvp deny&lt;br /&gt;
* WorldGuard then could have specific regions set to pvp allow&lt;br /&gt;
&lt;br /&gt;
== Backpack ==&lt;br /&gt;
&lt;br /&gt;
Reduce/downgrade Backpack space:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /Minecraft/plugins/Backpack/backpacks/world&lt;br /&gt;
ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the value next to &amp;quot;contents-amount:&amp;quot; in the user&#039;s .yml file.&lt;br /&gt;
&lt;br /&gt;
== Bungeecord ==&lt;br /&gt;
&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord/&amp;lt;br&amp;gt;&lt;br /&gt;
https://www.spigotmc.org/wiki/bungeecord-configuration-guide/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord-installation/#installing-bungeecord-on-linux&lt;br /&gt;
&lt;br /&gt;
To end Bungeecord script, type end and hit enter.&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=0ViRZPLuBiA How to use and install BungeeCord]&lt;br /&gt;
&lt;br /&gt;
== Buycraft ==&lt;br /&gt;
&lt;br /&gt;
=== Edit Store welcome page ===&lt;br /&gt;
&lt;br /&gt;
Webstore &amp;gt; General settings &amp;gt; Homepage description&lt;br /&gt;
&lt;br /&gt;
== Chat ==&lt;br /&gt;
&lt;br /&gt;
/tell PlayerName will whisper a message to a player. This option will not show in a console.&lt;br /&gt;
&lt;br /&gt;
/msg PayerName will show it as YourPlayerName -&amp;gt; Me to the other Player but be private&lt;br /&gt;
&lt;br /&gt;
=== Prefix and Suffix ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Never&#039;&#039;&#039; use McMyAdmin&#039;s Prefix and Suffix boxes, as you likely will not be able to remove them after you have set them without removing the group and re-adding it.&lt;br /&gt;
&lt;br /&gt;
== Check server&#039;s TPS ==&lt;br /&gt;
&lt;br /&gt;
Ticks Per Second&lt;br /&gt;
&lt;br /&gt;
If you use Bukkit/Essentials, do /lag&lt;br /&gt;
&lt;br /&gt;
== ColorMe ==&lt;br /&gt;
&lt;br /&gt;
If you add or remove a player to players.yml manually, keep a copy of the text you entered or of the file from which the text was removed. Sometimes when you do /color reload it will import an old version of the file from before the change you made. To resolve this:&lt;br /&gt;
&lt;br /&gt;
* make a copy of the text you added or the entire file not including the text you remove&lt;br /&gt;
* run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; players.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
* in config.yml set updateConfig: to true from the default of false&lt;br /&gt;
* /color reload&lt;br /&gt;
* now add or remove the text you did before, run the above command and it should work&lt;br /&gt;
&lt;br /&gt;
Also, it may be worth keeping updateConfig: as true always&lt;br /&gt;
&lt;br /&gt;
=== Colour and type ===&lt;br /&gt;
&lt;br /&gt;
To use both colour and formatting/type such as bold, itallic, strikethrough and underline at the same time, use the colour first then the formatting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;amplified: &#039;&amp;amp;6&amp;amp;oModerator&amp;amp;f&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
/prefix me &amp;amp;6&amp;amp;oModerator&lt;br /&gt;
&lt;br /&gt;
== Command Block ==&lt;br /&gt;
&lt;br /&gt;
Quick FAQ/Guide: http://hypixel.net/wiki/command-block/&lt;br /&gt;
&lt;br /&gt;
== Connection reset ==&lt;br /&gt;
&lt;br /&gt;
[Metrics]&lt;br /&gt;
&lt;br /&gt;
Set opt-out to true in plugins/PluginMetrics/config.yml&lt;br /&gt;
&lt;br /&gt;
This by default is false.&lt;br /&gt;
&lt;br /&gt;
In minecraft.log &amp;quot;[INFO] Connection reset&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;touch reset.sh ; chmod +x reset.sh ; vim reset.sh&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565 &amp;gt;&amp;gt; reset.log&lt;br /&gt;
echo -e &amp;quot;\n-------------------------------------------------------------------------------------------&amp;quot;&lt;br /&gt;
date +%R&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do the following in two separate SSH windows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f minecraft/install/directory/logs/minecraft.log&lt;br /&gt;
watch -n 1 ./reset.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then match up the times, and block the IP address from the server list website that is causing the message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A INPUT -s 50.116.54.77 -j DROP&lt;br /&gt;
iptables-save&lt;br /&gt;
iptables -L&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Lava ===&lt;br /&gt;
&amp;lt;!-- WorldProtect had to be disabled for this.--&amp;gt;&lt;br /&gt;
Allowing lava seems to be easiest by creating a group that can do it and then doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Allow lava buckets&lt;br /&gt;
[lavabucket]&lt;br /&gt;
allow&lt;br /&gt;
ignore-groups=Everyone&lt;br /&gt;
on-use=notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below method seems to fail&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ignore-perms=worldguard.lavabucket.exempt&lt;br /&gt;
ignore-groups=admins,mods,Lava&lt;br /&gt;
on-use=deny,tell,notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Current errors ==&lt;br /&gt;
&lt;br /&gt;
[WARNING] Can&#039;t keep up! Did the system time change, or is the server overloaded?&lt;br /&gt;
&lt;br /&gt;
May be due to TPS, /lag&lt;br /&gt;
&lt;br /&gt;
=== Current issues ===&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== DynMap ==&lt;br /&gt;
&lt;br /&gt;
To remove a map from rendering on the Dynamic Map web page, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&lt;br /&gt;
/map mapdelete _worldname_:_mapname_&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or remove the folder from /home/user/Minecraft/plugins/dynmap/web/tiles/worldname&lt;br /&gt;
&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Configuring-Maps-and-Worlds-using-dmap Configuring Maps and Worlds using dmap]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Component-Configuration Component Configuration]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://dev.bukkit.org/server-mods/dynmap/pages/faq/ FAQ]&lt;br /&gt;
&lt;br /&gt;
Render all:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap fullrender&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please be warned if you run a full render with the template set as the [https://github.com/webbukkit/dynmap/wiki/HD-Map-Configuration highest one for HD], hi_boost_xhi, then on a server with 8GB of RAM it will cause ~45-65% RAM usage.&lt;br /&gt;
&lt;br /&gt;
Pause render: &lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Disable world render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dmap worldset WorldName enabled:false&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hide a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap hide PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap show PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/webbukkit/dynmap/wiki/Web-UI-Parameters&lt;br /&gt;
&lt;br /&gt;
http://bywatercraft.co.uk:8123/?worldname=world&amp;amp;mapname=surface&lt;br /&gt;
&lt;br /&gt;
The Dynmap WorldGuard plugin that shows the WorldGuard region areas on the Dynamic Map shows a green border when there is no owner as it is not claimed.&lt;br /&gt;
&lt;br /&gt;
This will stop a render in progress and purge the tiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap purgeworld Le_Monde&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enjin ==&lt;br /&gt;
&lt;br /&gt;
* domain.co.uk//admin/games/minecraft-plugin/gid/6207-0&lt;br /&gt;
* Click [http://dev.bukkit.org/server-mods/vault Vault]&lt;br /&gt;
* If using Unix download the Vault.jar by doing wget http://dev.bukkit.org/media/files/655/849/Vault.jar&lt;br /&gt;
* Download the Enjin plugin&lt;br /&gt;
* Upload it via FTP to your server and it&#039;s Minecraft plugins directory&lt;br /&gt;
* Click Add Server&lt;br /&gt;
* Note down the enjinkey&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
If your site expires you will need to set the Custom Domain Name again.&lt;br /&gt;
&lt;br /&gt;
Go to http://site5659999cd2a04.enjin.com/dashboard/website/dns?site_id=722890&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Essentials | Essentials]] ==&lt;br /&gt;
&lt;br /&gt;
== Fixed errors ==&lt;br /&gt;
&lt;br /&gt;
=== Failed to start the minecraft server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Loading libraries, please wait...&lt;br /&gt;
Failed to start the minecraft server&lt;br /&gt;
java.lang.NullPointerException&lt;br /&gt;
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move your usercache.json file to another folder and try start/restart the server again&lt;br /&gt;
&lt;br /&gt;
=== FirstJoinPlus ===&lt;br /&gt;
&lt;br /&gt;
Could not pass event FirstJoinEvent to FirstJoinPlus v1.8.2&lt;br /&gt;
&lt;br /&gt;
Set your first join point again using /firstjoinplus setspawn&lt;br /&gt;
&lt;br /&gt;
Setting debug to true will treat every join as if it was a first join, so don&#039;t keep it on permanently!&lt;br /&gt;
&lt;br /&gt;
=== Modifyworld pass event ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] Could not pass event InventoryClickEvent to Modifyworld v1.19.4 org.bukkit.event.EventException&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fix: Disable the Modifyworld plugin and allow people to edit the world via the essentials.build permission.&lt;br /&gt;
&lt;br /&gt;
Notes: http://www.minecraftforum.net/topic/1763125-severe-could-not-pass-event-inventoryclickevent-to-modifyworld-v1194&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/PEXPlugins/PermissionsEx/wiki/Modifyworld#wiki-mw-configuration&lt;br /&gt;
&lt;br /&gt;
=== NoSplosion will cause Endermen to NOT spawn ===&lt;br /&gt;
&lt;br /&gt;
Disables all explosions vanilla or mods (Tekkit etc...) and fire from destroying blocks as well as Endermen from spawning. All explosions and fire still damage players but do not damage the environment.&lt;br /&gt;
&lt;br /&gt;
=== Your configuration might be outdated! ===&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then reload the server configuration or NCP plugin itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/reload&lt;br /&gt;
/ncp reload&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check if the config is different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;diff config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Give items ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftinfo.com/IDList.htm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/give [playername] [data-value] [amount]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftwiki.net/wiki/Data_values&lt;br /&gt;
&lt;br /&gt;
== Install Feed The Beast on a Unix server ==&lt;br /&gt;
&lt;br /&gt;
Add a user and make a directory specifically for the mod, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;add user ftb&lt;br /&gt;
mkdir server&lt;br /&gt;
cd /home/ftb/server&lt;br /&gt;
su ftb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&lt;br /&gt;
su user&lt;br /&gt;
cd ~/server&lt;br /&gt;
wget http://www.creeperrepo.net/direct/FTB2/6ce418a51b200ece8cb3c509ba9e094a/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv modpacks^Ultimate^1_0_1^Ultimate_Server.zip Ultimate_Server.zip&lt;br /&gt;
unzip Ultimate_Server.zip&lt;br /&gt;
vim ServerStart.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the values as you see fit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x ServerStart.sh&lt;br /&gt;
./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will error out if you&#039;re already running a Minecraft server on the default port 25565. If it does, do CTRL + C. To change this, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim server.properties&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the server-port to something that is not 25565. Then make sure the user:group ownership is correct on the server folder and all files and directories below it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CTRL + B then d to quit the tmux session.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
If you get something like below, you likely need to disable some mods (for me it was mods/railcraft.jar and mods/MineFactoryReloaded.jar):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] [ForgeModLoader] Detected leaking worlds in memory. There are 4 worlds that appear to be persisting.&lt;br /&gt;
A mod is likely caching the world incorrectly&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 7debb392 (world) has leaked.&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 3e6abeb4 (world) has leaked.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;mkdir McMyAdmin&lt;br /&gt;
cd McMyAdmin&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/MCMA2_glibc25.zip&lt;br /&gt;
unzip MCMA2_glibc25.zip&lt;br /&gt;
rm MCMA2_glibc25.zip&lt;br /&gt;
./MCMA2_Linux_x86_64 -configonly -setpass NEWADMINPASSWORD&lt;br /&gt;
vim McMyAdmin.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the Port and Server.Address to something other than 8080 and the Java.Memory value to as much RAM as you want/can use. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.creeperrepo.net/direct/FTB2/3be5e192a47685f491605e902dae3460/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv *press tab* FTB-Beta-A.jar ~/ftb/McMyAdmin/Minecraft&lt;br /&gt;
./MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
java -Xms1G -Xmx1G -jar ftbserver.jar nogui --&amp;gt;&lt;br /&gt;
== Install Votifier ==&lt;br /&gt;
&lt;br /&gt;
Install the plugin as normal by placing the .jar file in your plugins folder: http://dev.bukkit.org/server-mods/votifier&lt;br /&gt;
&lt;br /&gt;
Then reload the server and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat plugins/Votifier/rsa/public.key&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the code into the area of the server listing website you are using.&lt;br /&gt;
&lt;br /&gt;
=== [http://dev.bukkit.org/server-mods/votifier/forum/vote-listeners/48844-simple-vote-listener-perform-commands-and-timed-commands/#posts SimpleVoteListener] ===&lt;br /&gt;
&lt;br /&gt;
SimpleVoteListener can perform commands and broadcast messages&lt;br /&gt;
&lt;br /&gt;
== Load MCMyAdmin and Minecraft on server start ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh -p port user@localhost&lt;br /&gt;
crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press insert and add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;@reboot screen -dmS minecraft /home/mc/MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:wq&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then if you wish do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exit&lt;br /&gt;
touch /etc/init.d/minecraftd ; chown user:user /etc/init.d/minecraftd&lt;br /&gt;
vim /etc/init.d/minecraftd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Other options are to use:&lt;br /&gt;
#screen -S minecraft /home/mc/MCMA2_Linux_x86_64&lt;br /&gt;
#screen -dmS minecraft sh -c &#039;/home/mc/MCMA2_Linux_x86_64 ; exec bash&#039;&lt;br /&gt;
&lt;br /&gt;
## don&#039;t remove windows from the window list as soon as window process exits.&lt;br /&gt;
zombie kr #  k: destory window, r: resurrect window --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lock chests ==&lt;br /&gt;
&lt;br /&gt;
Use LWC or Lockette. &lt;br /&gt;
&lt;br /&gt;
To reload LWC, do /lwc admin reload&lt;br /&gt;
&lt;br /&gt;
To snoop in a chest with Lockette and to do this without a broadcast message, edit this file:&lt;br /&gt;
&lt;br /&gt;
/home/user/Minecraft/plugins/Lockette/config.yml&lt;br /&gt;
&lt;br /&gt;
And edit the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allow-admin-snoop: true&lt;br /&gt;
broadcast-snoop-target: &#039;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill all MCMA processes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results of the above command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;for a in `!!`&lt;br /&gt;
for a in `ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}`&lt;br /&gt;
&amp;gt; do&lt;br /&gt;
&amp;gt; kill -9 $a&lt;br /&gt;
&amp;gt; done&lt;br /&gt;
ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/McMyAdmin | McMyAdmin]] ==&lt;br /&gt;
&lt;br /&gt;
== Migrate from one *nix server to another ==&lt;br /&gt;
&lt;br /&gt;
scp / rsync the data in the Minecraft directory across. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install unzip&lt;br /&gt;
apt-get install openjdk-7-jre openjdk-7-jdk&lt;br /&gt;
cd /usr/local&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/etc.zip&lt;br /&gt;
unzip etc.zip&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to serverIPaddress:8080 in your browser. To login, check the details in McMyAdmin.conf. To change the password you &#039;&#039;&#039;need to stop McMyAdmin&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
/quit in console&lt;br /&gt;
&lt;br /&gt;
The file stores the password as MD5, to convert your password use this: http://www.md5hashgenerator.com/index.php&lt;br /&gt;
&lt;br /&gt;
== [http://media-mcw.cursecdn.com/thumb/4/4a/Mob_spawning_ranges.png/800px-Mob_spawning_ranges.png Mob Spawning Ranges] ==&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiverse | Multiverse]] ==&lt;br /&gt;
&lt;br /&gt;
This page has been moved to the above link as our server does not used Multiverse any more, it used Multiworld.&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiworld | Multiworld]] ==&lt;br /&gt;
&lt;br /&gt;
== NCore ==&lt;br /&gt;
&lt;br /&gt;
Plugin list: http://www.ribesg.fr/&lt;br /&gt;
&lt;br /&gt;
=== NEnchantingEgg ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NEnchantingEgg Documentation]&lt;br /&gt;
&lt;br /&gt;
=== nTheEndAgain ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NTheEndAgain Documentation]&lt;br /&gt;
&lt;br /&gt;
Shortcut instead of /ntheendagain -&amp;gt; /nend&lt;br /&gt;
&lt;br /&gt;
=== Check amount of dragons ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain nb world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Regen the world ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain regen world_the_end&lt;br /&gt;
/ntheendagain respawn world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Respawn the dragon ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain respawnEnderDragon world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Redstone ==&lt;br /&gt;
&lt;br /&gt;
=== [http://i.imgur.com/uM7O1l.png Powering a column of pistons] ===&lt;br /&gt;
&lt;br /&gt;
== Reload command ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftforum.net/topic/1506590-warning-cant-keep-up-did-the-system-time-change-or-is-the-server-overloaded&lt;br /&gt;
&lt;br /&gt;
v&lt;br /&gt;
&lt;br /&gt;
http://forums.bukkit.org/threads/petition-to-remove-the-reload-command.43212&lt;br /&gt;
&lt;br /&gt;
== Remote Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Colour code errors in console/log such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[12:21:32 INFO]: CONSOLE: Forcing save..←[m&lt;br /&gt;
[12:21:32 INFO]: CONSOLE: Save complete.←[m&lt;br /&gt;
←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1&lt;br /&gt;
G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K[12:21&lt;br /&gt;
:32 INFO]: ←[0;35;1m[Server←[0;35;1m] Save is complete.←[m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is due to the MinecraftRKitPlugin.jar file in your plugins folder. This is as of Release 10, Alpha 15.3 of the toolkit wrapper and happens on both Windows ([http://forums.bukkit.org/threads/console-format-issue.205024/ example]) and Unix (my own) ([https://forums.bukkit.org/threads/weird-multicraft-bukkit-error.127851/ example 2]).&lt;br /&gt;
&lt;br /&gt;
== Restart required ==&lt;br /&gt;
&lt;br /&gt;
If you use PermissionsBukkit with McMyAdmin, if you make a change you normally need to restart the Minecraft server to get it to see the changes. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;huge&#039;&#039;&#039; advantage of setting the Permissions Export to PermissionsEx is when a permission is added to McMyAdmin it automatically reloads the configuration, this is shown in the console by:&lt;br /&gt;
&lt;br /&gt;
[INFO] Permissions file successfully reloaded&amp;lt;br&amp;gt;&lt;br /&gt;
[INFO] Permissions reloaded&lt;br /&gt;
&lt;br /&gt;
If you op or de-op a player from ops.txt and the Administrators group in McMyAdmin.&lt;br /&gt;
&lt;br /&gt;
To set negative permissions in PermissionsEx, use - -permission before the other permissions.&lt;br /&gt;
&lt;br /&gt;
== Restore backup from McMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir BACKUPOFWORLDShhmm&lt;br /&gt;
cp -v world world_nether world_the_end BACKUPOFWORLDShhmm/ -R&lt;br /&gt;
mkdir movedawayworlds&lt;br /&gt;
mv world world_nether world_the_end movedawayworlds&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restore the backup via the McMyAdmin control panel.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To check when a player was last online, their IP address, what world they are in, do:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
/seen playername&lt;br /&gt;
&lt;br /&gt;
Useful:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -xr mcmonitor&lt;br /&gt;
CTRL A + D&lt;br /&gt;
screen -xr mysqlmcmon&lt;br /&gt;
&lt;br /&gt;
cd /home/mc/Minecraft&lt;br /&gt;
cat server.log | grep &amp;quot;YYYY-MM-DD&amp;quot; | grep User | grep -v indestructible&lt;br /&gt;
cat server.log | grep User | grep -v &#039;indestructible\|fell from a high place&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hawkeye ===&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/bukkit-plugins/hawkeye/pages/other-information/usage/ Usage]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Log everything:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Install Hawkeye by doing this manually or through a server control panel. In Unix, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/home/user/Minecraft/plugins/HawkEye# cat config.yml&lt;br /&gt;
&lt;br /&gt;
log:&lt;br /&gt;
  lava-bucket: true&lt;br /&gt;
  pvp-death: true&lt;br /&gt;
  other-death: true&lt;br /&gt;
  chat: true&lt;br /&gt;
  join: true&lt;br /&gt;
  open-container: true&lt;br /&gt;
  container-transaction: true&lt;br /&gt;
  teleport: true&lt;br /&gt;
  sign-place: true&lt;br /&gt;
  sign-break: true&lt;br /&gt;
  flint-steel: true&lt;br /&gt;
  block-place: true&lt;br /&gt;
  block-break: true&lt;br /&gt;
  enderman-pickup: true&lt;br /&gt;
  spawnmob-egg: true&lt;br /&gt;
  crop-trample: true&lt;br /&gt;
general:&lt;br /&gt;
  max-lines: 0&lt;br /&gt;
  log-item-drops-on-death: true&lt;br /&gt;
  cleanse-period: 20m&lt;br /&gt;
  cleanse-age: 0&lt;br /&gt;
  delete-data-on-rollback: true&lt;br /&gt;
  log-ip-addresses: true&lt;br /&gt;
  debug: false&lt;br /&gt;
  debug-level: low&lt;br /&gt;
  max-radius: 0&lt;br /&gt;
  give-user-tool: true&lt;br /&gt;
  tool-block: &#039;17&#039;&lt;br /&gt;
  default-here-radius: 5&lt;br /&gt;
  default-tool-command: &#039;&#039;&lt;br /&gt;
  check-for-updates: true&lt;br /&gt;
  log-delay: 2&lt;br /&gt;
mysql:&lt;br /&gt;
  hawkeye-table: hawkeye&lt;br /&gt;
  port: 3306&lt;br /&gt;
  player-table: hawk_players&lt;br /&gt;
  username: root&lt;br /&gt;
  world-table: hawk_worlds&lt;br /&gt;
  hostname: localhost&lt;br /&gt;
  max-connections: 10&lt;br /&gt;
  password: &#039;InsertMySQLPasswordHere&#039;&lt;br /&gt;
  database: hawkminecraft #you can rename this if you wish&lt;br /&gt;
ignore-worlds:&lt;br /&gt;
- thisworldisignored&lt;br /&gt;
- soisthisone&lt;br /&gt;
command-filter:&lt;br /&gt;
- /login&lt;br /&gt;
- /restartsrv&lt;br /&gt;
- /register&lt;br /&gt;
- /spawn&lt;br /&gt;
block-filter:&lt;br /&gt;
- NONE&lt;br /&gt;
containertransaction-filter:&lt;br /&gt;
  chest: true&lt;br /&gt;
  doublechest: true&lt;br /&gt;
  furnace: true&lt;br /&gt;
  dispenser: true&lt;br /&gt;
version: 1.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database hawkeye;&lt;br /&gt;
show databases;&lt;br /&gt;
use hawkeye&lt;br /&gt;
show tables;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be empty. If so (more than likely), log into your minecraft server and do /reload. Then go back into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use hawkeye&lt;br /&gt;
show tables;&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| Tables_in_hawkeye       |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| hawk_players            |&lt;br /&gt;
| hawk_worlds             |&lt;br /&gt;
| hawkeye                 |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
select * from hawk_worlds;&lt;br /&gt;
select * from hawkeye;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you can now do /hawk in game. To check a block, do /hawk tool , then left click a block and it will show you the block information.&lt;br /&gt;
&lt;br /&gt;
==== Get table structure and players ====&lt;br /&gt;
&lt;br /&gt;
desc hawkeye;&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
&lt;br /&gt;
==== Look at logs ====&lt;br /&gt;
&lt;br /&gt;
Via a web interface: http://dev.bukkit.org/bukkit-plugins/hawkeye-reload/pages/web-interface-setup/&lt;br /&gt;
&lt;br /&gt;
If you do a search and get this error message you need to re-download the interface:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Error! Unknown column &#039;date&#039; in &#039;where clause&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Via SQL: &lt;br /&gt;
&lt;br /&gt;
select * from hawkeye ORDER BY data_id DESC LIMIT 100000;&lt;br /&gt;
&lt;br /&gt;
== See region information ==&lt;br /&gt;
&lt;br /&gt;
/region info area&lt;br /&gt;
&lt;br /&gt;
It should output something like:&lt;br /&gt;
&lt;br /&gt;
Region: area, type: shape, Priority: X&amp;lt;br&amp;gt;&lt;br /&gt;
Flags: use: ALLOW, mob-spawning: DENY (OR ALLOW)&amp;lt;br&amp;gt;&lt;br /&gt;
Bound: (x) (z)&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftwiki.net/wiki/Server.properties server.properties] file ==&lt;br /&gt;
&lt;br /&gt;
== Set flyspeed ==&lt;br /&gt;
&lt;br /&gt;
Default is 1&lt;br /&gt;
&lt;br /&gt;
For yourself:&lt;br /&gt;
&lt;br /&gt;
/flyspeeed 2&lt;br /&gt;
&lt;br /&gt;
For others:&lt;br /&gt;
&lt;br /&gt;
/flyspeed 2 playername&lt;br /&gt;
&lt;br /&gt;
== Setting spawn ==&lt;br /&gt;
&lt;br /&gt;
On Bywater Craft where we have multiple spawn plugins, to set spawn you need to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/mw setspawn&lt;br /&gt;
/setspawn&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set warps ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/setwarp NewWarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp WarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have per-warp-permission set to true in the config.yml then you can limit what warps players can use. This also controls what players would see with /warp, hence why both essentials.warp and essentials.warp.list are used.&lt;br /&gt;
&lt;br /&gt;
== Set world for SkyGridMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim SkyGrid.jar/config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;world: WorldName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching 09/09/14 - 28/11/14 (old) ==&lt;br /&gt;
&lt;br /&gt;
This was changed as of November 28th 2014: http://www.spigotmc.org/threads/bukkit-craftbukkit-spigot-1-8.36598/&lt;br /&gt;
&lt;br /&gt;
Please now use http://www.spigotmc.org/threads/buildtools-updates-information.42865/ for Minecraft 1.8+&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd ~/spigotwork&lt;br /&gt;
java -jar ~/spigotwork/SpigotPatcher-1.0.jar ~/spigotwork/spigot1649.jar ~/spigotwork/spigot-YYYYMMDDa.bps ~/spigotwork/spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&lt;br /&gt;
rm ../Minecraft/spigot.jar&lt;br /&gt;
mv spigot.jar ../Minecraft/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside the spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;java -jar SpigotPatcher-1.0.jar spigot1649.jar spigot-YYYYMMDD.bps spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching - new ==&lt;br /&gt;
&lt;br /&gt;
Inside your spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir 1.XX-XBuildTools&lt;br /&gt;
rm BuildTools.jar&lt;br /&gt;
wget &amp;quot;https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar&amp;quot; -O BuildTools.jar&lt;br /&gt;
java -jar BuildTools.jar&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If needed run this first outside of McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exec java -jar spigot.jar --forceUpgrade nogui | tee test.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftforum.net/videos/view-51785-how-to-synchronize-nether-portals Synchronise Nether Portals] ==&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/server-mods/ascii-bukkit-menu/ ASCII SSH Bukkit Menu] (via screen)&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/Ahtenus/minecraft-init Init script]&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
[[Linux#tmux | Using it]]&lt;br /&gt;
&lt;br /&gt;
http://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen/13954#13954&lt;br /&gt;
&lt;br /&gt;
== Update CraftBukkit ==&lt;br /&gt;
&lt;br /&gt;
Stop the server, then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit.jar versioncraftbukkit.jar&lt;br /&gt;
wget http://dl.bukkit.org/latest-rb/craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or download the development/beta build and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit-dev.jar craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the server&lt;br /&gt;
&lt;br /&gt;
Log out and back into MCMyAdmin.&lt;br /&gt;
&lt;br /&gt;
== World Edit ==&lt;br /&gt;
&lt;br /&gt;
Place .schematic files in /home/user/Minecraft/plugins/WorldEdit/schematics&lt;br /&gt;
&lt;br /&gt;
Import them by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//schematic load filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you can do //paste in Minecraft to paste it into the world where you are.&lt;br /&gt;
&lt;br /&gt;
=== Fill an area ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select position 1 and 2. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//set block&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unbind a tool/block ===&lt;br /&gt;
&lt;br /&gt;
If for example you accidentally do //fill block (e.g. sand), and each time you right click with a tool/block or your hand, clear it by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== World Guard ==&lt;br /&gt;
&lt;br /&gt;
http://wiki.sk89q.com/wiki/WorldEdit/Selection&lt;br /&gt;
&lt;br /&gt;
https://bukkit.org/threads/worldguard-not-expanding-regions.20974/&lt;br /&gt;
&lt;br /&gt;
To protect an area, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then click the first position then the second position with the wooden axe.&lt;br /&gt;
&lt;br /&gt;
If you only do one layer, you can do //expand to go up or down, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//expand UpValue DownValue up&lt;br /&gt;
//expand 10 0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would expand up 10 blocks from the single layer but do 0 down.&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define newnameforarea owner&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Owner can be left blank.&lt;br /&gt;
&lt;br /&gt;
To get information on the area you just created, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region info newnameforarea&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Allow fire spread/tick ===&lt;br /&gt;
&lt;br /&gt;
In config.yml:&lt;br /&gt;
&lt;br /&gt;
Set high-frequency-flags to true&amp;lt;br&amp;gt;&lt;br /&gt;
Set disable-all-fire-spread to false&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag __global__ fire-spread allow&lt;br /&gt;
/rg flag __global__ lava-fire allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this still doesn&#039;t work, if you have Essentials then set these in config.yml:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fire-spread: true&lt;br /&gt;
lava-fire-spread: true&lt;br /&gt;
flint-fire: true&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit world regions from outside (and inside) that world ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w ExactWorldName RegionName FlagName allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to use the blocked-cmds flag and want to block multiple commands separate them by commas:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w world MyHome blocked-cmds /tp,/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Entry flag for groups ===&lt;br /&gt;
&lt;br /&gt;
Due to inheritance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag chestroomdoor entry deny&lt;br /&gt;
/rg flag chestroomdoor entry -g nonmembers&lt;br /&gt;
/rg addmember chestroomdoor g:citizen&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets round inheritance by denying all except members from a certain group up the inheritance tree.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you have:&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;vip&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:vip&lt;br /&gt;
/region flag doorway entry -g nonmembers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is not in the vip group for the doorway.&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;guest&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:guest&lt;br /&gt;
/region flag doorway entry -g members&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is in the members field, guest in this case, group for the doorway. Everyone else would be allowed.&lt;br /&gt;
&lt;br /&gt;
Then you&#039;d add the permission node &amp;quot;group.guest&amp;quot; to the guest group in your permissions plugin&#039;s config.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Guest&amp;quot; isn&#039;t a group - http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags#Group&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg removemember chestroomdoor playername&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Group inheritance ====&lt;br /&gt;
&lt;br /&gt;
Important note about the below example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag regionname entry deny&lt;br /&gt;
/rg addmember regionname g:groupname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands should deny entry to groups not added as members or owners.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keep in mind that if you use any inheritance system in your permissions (for example: builder inherits default permissions), any groups that inherit the same permissions as the allowed group will also be allowed entrance to the region.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Your best bet is to eliminate the inheritances and give each group their own group.groupname permission. This allows worldguard to see separate groups.&lt;br /&gt;
&lt;br /&gt;
The same goes with the exit flag.&lt;br /&gt;
&lt;br /&gt;
=== Flint &amp;amp; Steel doesn&#039;t work ===&lt;br /&gt;
&lt;br /&gt;
If it returns the message:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You&#039;re not allowed to use that here&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Do this in-game:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region flag -w world __global__ lighter allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: http://forums.bukkit.org/threads/i-need-help-with-allowing-flint-steel.152990/&lt;br /&gt;
&lt;br /&gt;
=== Rename region ===&lt;br /&gt;
&lt;br /&gt;
You cannot do this without editing the database manually. If the area is not too big, just remove it and re-add it.&lt;br /&gt;
&lt;br /&gt;
If you do edit the entry in the id column of the region table of the worldguard (by default) database, just do /worldguard reload in-game after you have changed it.&lt;br /&gt;
&lt;br /&gt;
=== Set flags ===&lt;br /&gt;
&lt;br /&gt;
To set flags, see this page: http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags&lt;br /&gt;
&lt;br /&gt;
To stop building and PvP but to allow use, you would do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag areaname build deny&lt;br /&gt;
/rg flag areaname pvp deny&lt;br /&gt;
/rg flag areaname use allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [http://dev.bukkit.org/bukkit-plugins/worldguard-block-restricter WorldGuard Block Restricter] ====&lt;br /&gt;
&lt;br /&gt;
This requires [http://dev.bukkit.org/bukkit-plugins/worldguard-custom-flags WorldGuard Custom Flags] installing too.&lt;br /&gt;
&lt;br /&gt;
To only allow a specific type of block you need to:&lt;br /&gt;
&lt;br /&gt;
* set build allow in WorldGuard: /rg flag areaname build allow&lt;br /&gt;
* then deny all blocks via WorldGuard Block Restricter using /rg flag areaname deny-blocks any&lt;br /&gt;
* then allow the blocks you want via WorldGuard Block Restricter using /rg flag areaname allow-blocks dirt&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134040</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134040"/>
		<updated>2025-01-10T17:39:14Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then start a new SSH session.&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;set background=dark&lt;br /&gt;
syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
Use shellcheck package to check syntax for bash scripts.&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
Keeper Commander and Python Virtual Environment&lt;br /&gt;
&lt;br /&gt;
=== Create Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python3 -m venv ~/py_envs&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Activate and enter Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source ~/py_envs/bin/activate&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enter Keeper Shell: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;(py_envs) root@host:~# &lt;br /&gt;
(py_envs) root@host:~# keeper shell&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log out of and exit Keeper Shell: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;logout&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deactivate and exit Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deactivate&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete a Python Virtual Environment ===&lt;br /&gt;
&lt;br /&gt;
https://python.land/virtual-environments/virtualenv#Deleting_a_Python_venv&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134039</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134039"/>
		<updated>2025-01-09T15:29:12Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then start a new SSH session.&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;set background=dark&lt;br /&gt;
syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
Keeper Commander and Python Virtual Environment&lt;br /&gt;
&lt;br /&gt;
=== Create Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;python3 -m venv ~/py_envs&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Activate and enter Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source ~/py_envs/bin/activate&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enter Keeper Shell: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;(py_envs) root@host:~# &lt;br /&gt;
(py_envs) root@host:~# keeper shell&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log out of and exit Keeper Shell: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;logout&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deactivate and exit Python Virtual Environment: === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deactivate&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete a Python Virtual Environment ===&lt;br /&gt;
&lt;br /&gt;
https://python.land/virtual-environments/virtualenv#Deleting_a_Python_venv&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134038</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134038"/>
		<updated>2025-01-08T16:18:03Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then start a new SSH session.&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;set background=dark&lt;br /&gt;
syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=SSH&amp;diff=134037</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=SSH&amp;diff=134037"/>
		<updated>2025-01-08T16:17:48Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [http://serverkb.co.uk/wiki/General_Linux#File_Permissions Changing File Permissions] ==&lt;br /&gt;
&lt;br /&gt;
== Coloured terminal ==&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then start a new SSH session.&lt;br /&gt;
&lt;br /&gt;
== Logging into SSH ==&lt;br /&gt;
&lt;br /&gt;
=== On a Linux PC/Mac === &lt;br /&gt;
&lt;br /&gt;
Open Terminal for Mac in Applications/Utilities or on Linux it is in Applications/Accessories and use the following command:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ssh -p22 root@IPaddress&#039;&#039;&#039; . Accept the RSA prompt by either typing or clicking Yes. Enter the root/Virtuozzo password that was provided on the account by default in your service providers welcome email.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please be aware if the SSH port has been changed from the default of 22, you need to change the number in the -p option above.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please also replace IPaddress with the one of your server. These are in the format of X.X.X.X/0.0.0.0 e.g. 215.178.46.39&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== On a Windows PC ===&lt;br /&gt;
&lt;br /&gt;
Please go to one of these links to download PuTTY: [http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.62-installer.exe Link 1], [http://tartarus.org/~simon/putty-snapshots/x86/putty-installer.exe Link 2]. Once installed and ran, please put your server IP address in the &amp;quot;Host (or IP Address)&amp;quot; field and the Port as 22. &lt;br /&gt;
&lt;br /&gt;
Press open and you will be prompted for a username, so use root as the username. Enter the root/Virtuozzo password that was provided on the account by default in your service providers welcome email. You will not be able to see a password being typed, but you can still backspace/delete.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use a program called [http://www.mremote.org/wiki/GetFile.aspx?File=Downloads/mRemote_1.50_Setup_EN.exe mRemote].&lt;br /&gt;
&lt;br /&gt;
== The next step after logging in ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Once in the SSH command line interface, please type cd /&#039;&#039;&#039; &#039;&#039;(that&#039;s cd forward-slash, separated by a space) or cd ..&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This puts you inside the top level directory of your server aka &amp;quot;root&amp;quot;. When logging in you will see root@ServerIPAddress:~. or root@hostname:~. The tilde symbol indicates you are in a directory called root, aka /./root with . being actual root.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Creating an account ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;useradd -g users -d /home/path/ -s /bin/bash &amp;lt;username&amp;gt;&lt;br /&gt;
chown &amp;lt;username&amp;gt;:users /home/path/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this does not work on Debian, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;useradd -g root -s /bin/bash username -m&lt;br /&gt;
usermod -a -G root username&lt;br /&gt;
passwd username&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html Good OpenSSH practices] ==&lt;br /&gt;
&lt;br /&gt;
== hosts.deny ==&lt;br /&gt;
&lt;br /&gt;
This file, if enabled, will deny people&#039;s IP addresses if they fail to log in/authenticate with your server by placing it in a file called hosts.deny. If you are getting denied access from your IP address (it cuts off the connection), connect from another IP address and remove your IP address from the file.&lt;br /&gt;
&lt;br /&gt;
[http://forums.devshed.com/bsd-help-31/blocking-a-range-of-ip-s-in-hosts-deny-322368.html Blocking a range of IPs]&lt;br /&gt;
&lt;br /&gt;
== Public and Private keys ==&lt;br /&gt;
&lt;br /&gt;
The public and private key are similar to a puzzle. They are created together to use during the login/authentication process. The public key resides on the server (the remote location) The private key resides locally on your computer/server. When you attempt to login to a server, the public and private key are compared. If they &amp;quot;match&amp;quot;, then you will be allowed to login to the server location.&lt;br /&gt;
&lt;br /&gt;
Note: SSH keys can be used to authenticate to SSH services like SFTP or SSH terminal if these features are enabled for your account.&lt;br /&gt;
&lt;br /&gt;
== Run a command remotely ==&lt;br /&gt;
&lt;br /&gt;
ssh -n user@hostname &#039;command&#039;&lt;br /&gt;
&lt;br /&gt;
== Setting root password ==&lt;br /&gt;
&lt;br /&gt;
To set your SSH, Virtuozzo and Plesk root user password type &#039;&#039;&#039;passwd&#039;&#039;&#039; or &#039;&#039;&#039;passwd root&#039;&#039;&#039; and then enter the password. Again, you will not be able to see this password being typed and will need to enter it multiple times.&lt;br /&gt;
&lt;br /&gt;
== Set up a secure chroot jail ==&lt;br /&gt;
&lt;br /&gt;
http://www.achawkins.com/tech/how-to-set-up-a-secure-chrooted-jail-with-rssh/&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/12181/how-do-i-create-a-user-with-read-only-access-over-ssh-to-a-limited-subtree-of-fo Create a user with read only access over SSH to a limited subtree of folders]&lt;br /&gt;
&lt;br /&gt;
== Shell Commands ==&lt;br /&gt;
&lt;br /&gt;
Note: anything with &amp;lt;&amp;gt; around it is where you need to enter your own value and the &amp;lt;&amp;gt; should not be used. Right clicking inside PuTTY will paste any text content in your clipboard to the command line. Alternatively use SHIFT + INSERT to paste.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Command&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;What it does&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Additional Information&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|cd&lt;br /&gt;
|Used to change directory. cd / takes you back to the root directory. cd on it&#039;s own goes to your home dir.&lt;br /&gt;
| cd .. takes you back on directory (use ../.. or more for 2+ directories) , cd - takes you back to last working dir&lt;br /&gt;
|-&lt;br /&gt;
|cp&lt;br /&gt;
|Used to copy files but leave the original in place&lt;br /&gt;
|-&lt;br /&gt;
|diff&lt;br /&gt;
|This command shows the difference between two files (or directory trees)&lt;br /&gt;
|Examples: diff index.php index.backup.php , diff -qr &amp;lt;dir1&amp;gt; &amp;lt;dir2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|/etc/init.d/&amp;lt;service&amp;gt;&lt;br /&gt;
|Use this with stop, start, restart, startall or stopall after the service name &amp;gt;&lt;br /&gt;
|Examples: /etc/init.d/apache2 restart , /etc/init.d/qmail start , /etc/init.d/psa startall , /etc/init.d/ssh (or sshd) restart&lt;br /&gt;
|-&lt;br /&gt;
|last&lt;br /&gt;
|Displays logged in users, when and where people last connected from.&lt;br /&gt;
|whoami and id show the user you are logged in as. w shows logged in users only.&lt;br /&gt;
|-&lt;br /&gt;
|ls -lah&lt;br /&gt;
|This lists the current files in the directory you are in and shows the permissions, ownerships, dates, file size, hidden files&lt;br /&gt;
|Use man ls to find out alternate options. -l uses a long listing format. -a is all. -h makes it human readable&lt;br /&gt;
|-&lt;br /&gt;
|mkdir &amp;lt;directoryname&amp;gt;&lt;br /&gt;
|This creates a directory&lt;br /&gt;
|[[Linux#File_Permissions|File Permissions]]&lt;br /&gt;
|-&lt;br /&gt;
|mv&lt;br /&gt;
|Used to permanently move a file from one file directory to another or rename a file&lt;br /&gt;
|-&lt;br /&gt;
|pwd&lt;br /&gt;
|This shows the directory you are currently in.&lt;br /&gt;
|Stands for Present Working Directory&lt;br /&gt;
|-&lt;br /&gt;
|rm&lt;br /&gt;
|Used to delete a file or empty folder&lt;br /&gt;
|Note: You cannot remove a folder with files/folder in it with -R&lt;br /&gt;
|-&lt;br /&gt;
|rm -rf &amp;lt;foldername&amp;gt;/*; rmdir &amp;lt;foldername&amp;gt;&lt;br /&gt;
|This recursively and forcibly removes a folder and anything below it&lt;br /&gt;
|To Be Filled In&lt;br /&gt;
|-&lt;br /&gt;
|touch &amp;lt;filename&amp;gt;&lt;br /&gt;
|This creates a file &amp;gt;&lt;br /&gt;
|If you want to enter the file straight after, use touch filename | vim filename&lt;br /&gt;
|-&lt;br /&gt;
|usermod&lt;br /&gt;
|This allows you to add users to groups, change their username. Do man usermod for more info.&lt;br /&gt;
|Example: usermod -a -G group username . This can be used to allow one website to access another&#039;s Virtual Host content.&lt;br /&gt;
|-&lt;br /&gt;
|vim &amp;lt;filename&amp;gt;&lt;br /&gt;
|Enters a file, press insert to edit, escape to stop editing &amp;gt;&lt;br /&gt;
|Type :q to quit without saving, :wq to quit and save, ! after to force&lt;br /&gt;
|-&lt;br /&gt;
|wc -l&lt;br /&gt;
|Wordcount. You can use this to see the amount of entries in a command.&lt;br /&gt;
|Do ls | wc -l to see amount of files in a directory, netstat -ant | wc -l to check amount of network connections&lt;br /&gt;
|-&lt;br /&gt;
|wget&lt;br /&gt;
|This grabs a file from somewhere. The example in the next column gets a PHP page.&lt;br /&gt;
|Example: wget linuxcommand.org/lts0070.php&lt;br /&gt;
|-&lt;br /&gt;
|which&lt;br /&gt;
|This shows the full path of (shell) commands.&lt;br /&gt;
|Useful for after installing software.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* If you want to wget a link that starts with https, do wget http://www.domain.co.uk/page.php --no-check-certificate&lt;br /&gt;
&lt;br /&gt;
* If you get &amp;quot;Argument list too long&amp;quot; when deleting do mv cur cur.old ; mkdir cur . You can then delete cur.old at your leisure. Alternatively if you can remove it without worrying about loss of data, cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
* If you go into the /etc/init.d/ you will see the services that are available to enable/disable.&lt;br /&gt;
&lt;br /&gt;
Using the command locate &amp;lt;file_or_folder&amp;gt; you can find where the files and directories are located. If this command shows &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;, please type updatedb and wait for it to finish and then try to locate the file again. If it fails, please see [[Linux#updatedb_.28locate_command.29|updatedb]]. &lt;br /&gt;
&lt;br /&gt;
* To reboot the server simply type reboot on it&#039;s own.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;To monitor running services/processes, CPU usage, RAM usage and other information run the command top&#039;&#039;&#039;. An alternate is called htop which you can run by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install htop&lt;br /&gt;
#or&lt;br /&gt;
yum update&lt;br /&gt;
yum install htop&lt;br /&gt;
htop (press F10 to exit)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use sed(1) to edit a file in place. E.g. to replace every &#039;e&#039; with an &#039;o&#039;, in a file named &#039;foo&#039;, you can do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sed -i.bak s/e/o/g foo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you&#039;ll get a backup of the original in a file named &#039;foo.bak&#039;, but if you want no backup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sed -i &#039;&#039; s/e/o/g foo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://en.wikipedia.org/wiki/Chattr Chattr] ===&lt;br /&gt;
&lt;br /&gt;
To check if it is protected lsattr file&amp;lt;br&amp;gt;&lt;br /&gt;
To protect a file, use chattr +i&amp;lt;br&amp;gt;&lt;br /&gt;
To remove this protection do chattr -i&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;Operation not permitted&amp;quot; you may need to do this on a folder to remove the protection on a file.&lt;br /&gt;
&lt;br /&gt;
=== Empty a file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kick user out of SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kill the process ID that has the same &amp;quot;sshd: root@tty&amp;quot;, e.g. sshd: root@pts/2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;kill processID&lt;br /&gt;
#e.g. kill 12716&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, kill use SIGTERM 15 so does a nice exit, so this will write their commands to the .bash_history file.&lt;br /&gt;
&lt;br /&gt;
=== View file ===&lt;br /&gt;
&lt;br /&gt;
Using [http://en.wikipedia.org/wiki/Less_(Unix) less] can be very useful. Use capital G and this will go to the bottom of the file. You can use spacebar to page down or B to page up.&lt;br /&gt;
&lt;br /&gt;
== Speed up SSH login ==&lt;br /&gt;
&lt;br /&gt;
vim /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
GSSAPIAuthentication=no&amp;lt;br&amp;gt;&lt;br /&gt;
UseDNS=no&lt;br /&gt;
&lt;br /&gt;
== sshd rootkit on Unix systems ==&lt;br /&gt;
&lt;br /&gt;
Feb 22, 2013 - http://kb.parallels.com/en/115589&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This issue is not related to Parallels products but all sshd-enabled systems are potentially vulnerable. Security checks are strongly advised.&lt;br /&gt;
&lt;br /&gt;
== SSH/OpenSSH Keys ==&lt;br /&gt;
&lt;br /&gt;
== SSH Port ==&lt;br /&gt;
&lt;br /&gt;
By default this is 22. This can be defined in /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
If you are getting one of the following errors when trying to start the SSH service using &#039;&#039;/etc/init.d/ssh start&#039;&#039; or go into it using &#039;&#039;ssh root@IPaddress&#039;&#039; :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;start: Job failed to start&lt;br /&gt;
ssh: connect to host port 22: Connection refused&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove the line that starts with &amp;quot;oom never&amp;quot; in /etc/init/ssh.conf&lt;br /&gt;
&lt;br /&gt;
== Wuff -- Wuff!! ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
alias screen=&#039;TERM=screen screen&#039;&lt;br /&gt;
&lt;br /&gt;
source ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This problem is caused the screen developers stubbornly sticking to the view that backspace should be non-destructive. Thus when your terminal, say xterm, sends a destructive backspace, screen treats it it like a delete. Here is the entry in their FAQ:&lt;br /&gt;
&lt;br /&gt;
Q: The cursor left key deletes the characters instead of just moving the cursor. A redisplay (^Al) brings everything back.&amp;lt;br&amp;gt;&lt;br /&gt;
A: Your terminal emulator (probably xterm) treats the backspace as “destructive”. You can probably change this somewhere in the setup. We can’t think of a reason why anybody would want a destructive backspace, but if you really must have it, add the line&lt;br /&gt;
&lt;br /&gt;
termcapinfo xterm ‘bc@:bs@’&lt;br /&gt;
&lt;br /&gt;
to your ~/.screenrc (replace xterm with the terminal type of your emulator, if different).&lt;br /&gt;
&lt;br /&gt;
Add that line to /etc/screenrc and you can fix it system wide.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=SSH&amp;diff=134036</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=SSH&amp;diff=134036"/>
		<updated>2025-01-08T16:17:31Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== [http://serverkb.co.uk/wiki/General_Linux#File_Permissions Changing File Permissions] ==&lt;br /&gt;
&lt;br /&gt;
== Coloured terminal ==&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Logging into SSH ==&lt;br /&gt;
&lt;br /&gt;
=== On a Linux PC/Mac === &lt;br /&gt;
&lt;br /&gt;
Open Terminal for Mac in Applications/Utilities or on Linux it is in Applications/Accessories and use the following command:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ssh -p22 root@IPaddress&#039;&#039;&#039; . Accept the RSA prompt by either typing or clicking Yes. Enter the root/Virtuozzo password that was provided on the account by default in your service providers welcome email.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please be aware if the SSH port has been changed from the default of 22, you need to change the number in the -p option above.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please also replace IPaddress with the one of your server. These are in the format of X.X.X.X/0.0.0.0 e.g. 215.178.46.39&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== On a Windows PC ===&lt;br /&gt;
&lt;br /&gt;
Please go to one of these links to download PuTTY: [http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.62-installer.exe Link 1], [http://tartarus.org/~simon/putty-snapshots/x86/putty-installer.exe Link 2]. Once installed and ran, please put your server IP address in the &amp;quot;Host (or IP Address)&amp;quot; field and the Port as 22. &lt;br /&gt;
&lt;br /&gt;
Press open and you will be prompted for a username, so use root as the username. Enter the root/Virtuozzo password that was provided on the account by default in your service providers welcome email. You will not be able to see a password being typed, but you can still backspace/delete.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use a program called [http://www.mremote.org/wiki/GetFile.aspx?File=Downloads/mRemote_1.50_Setup_EN.exe mRemote].&lt;br /&gt;
&lt;br /&gt;
== The next step after logging in ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Once in the SSH command line interface, please type cd /&#039;&#039;&#039; &#039;&#039;(that&#039;s cd forward-slash, separated by a space) or cd ..&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;This puts you inside the top level directory of your server aka &amp;quot;root&amp;quot;. When logging in you will see root@ServerIPAddress:~. or root@hostname:~. The tilde symbol indicates you are in a directory called root, aka /./root with . being actual root.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Creating an account ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;useradd -g users -d /home/path/ -s /bin/bash &amp;lt;username&amp;gt;&lt;br /&gt;
chown &amp;lt;username&amp;gt;:users /home/path/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this does not work on Debian, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;useradd -g root -s /bin/bash username -m&lt;br /&gt;
usermod -a -G root username&lt;br /&gt;
passwd username&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html Good OpenSSH practices] ==&lt;br /&gt;
&lt;br /&gt;
== hosts.deny ==&lt;br /&gt;
&lt;br /&gt;
This file, if enabled, will deny people&#039;s IP addresses if they fail to log in/authenticate with your server by placing it in a file called hosts.deny. If you are getting denied access from your IP address (it cuts off the connection), connect from another IP address and remove your IP address from the file.&lt;br /&gt;
&lt;br /&gt;
[http://forums.devshed.com/bsd-help-31/blocking-a-range-of-ip-s-in-hosts-deny-322368.html Blocking a range of IPs]&lt;br /&gt;
&lt;br /&gt;
== Public and Private keys ==&lt;br /&gt;
&lt;br /&gt;
The public and private key are similar to a puzzle. They are created together to use during the login/authentication process. The public key resides on the server (the remote location) The private key resides locally on your computer/server. When you attempt to login to a server, the public and private key are compared. If they &amp;quot;match&amp;quot;, then you will be allowed to login to the server location.&lt;br /&gt;
&lt;br /&gt;
Note: SSH keys can be used to authenticate to SSH services like SFTP or SSH terminal if these features are enabled for your account.&lt;br /&gt;
&lt;br /&gt;
== Run a command remotely ==&lt;br /&gt;
&lt;br /&gt;
ssh -n user@hostname &#039;command&#039;&lt;br /&gt;
&lt;br /&gt;
== Setting root password ==&lt;br /&gt;
&lt;br /&gt;
To set your SSH, Virtuozzo and Plesk root user password type &#039;&#039;&#039;passwd&#039;&#039;&#039; or &#039;&#039;&#039;passwd root&#039;&#039;&#039; and then enter the password. Again, you will not be able to see this password being typed and will need to enter it multiple times.&lt;br /&gt;
&lt;br /&gt;
== Set up a secure chroot jail ==&lt;br /&gt;
&lt;br /&gt;
http://www.achawkins.com/tech/how-to-set-up-a-secure-chrooted-jail-with-rssh/&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/12181/how-do-i-create-a-user-with-read-only-access-over-ssh-to-a-limited-subtree-of-fo Create a user with read only access over SSH to a limited subtree of folders]&lt;br /&gt;
&lt;br /&gt;
== Shell Commands ==&lt;br /&gt;
&lt;br /&gt;
Note: anything with &amp;lt;&amp;gt; around it is where you need to enter your own value and the &amp;lt;&amp;gt; should not be used. Right clicking inside PuTTY will paste any text content in your clipboard to the command line. Alternatively use SHIFT + INSERT to paste.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Command&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;What it does&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Additional Information&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|cd&lt;br /&gt;
|Used to change directory. cd / takes you back to the root directory. cd on it&#039;s own goes to your home dir.&lt;br /&gt;
| cd .. takes you back on directory (use ../.. or more for 2+ directories) , cd - takes you back to last working dir&lt;br /&gt;
|-&lt;br /&gt;
|cp&lt;br /&gt;
|Used to copy files but leave the original in place&lt;br /&gt;
|-&lt;br /&gt;
|diff&lt;br /&gt;
|This command shows the difference between two files (or directory trees)&lt;br /&gt;
|Examples: diff index.php index.backup.php , diff -qr &amp;lt;dir1&amp;gt; &amp;lt;dir2&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|/etc/init.d/&amp;lt;service&amp;gt;&lt;br /&gt;
|Use this with stop, start, restart, startall or stopall after the service name &amp;gt;&lt;br /&gt;
|Examples: /etc/init.d/apache2 restart , /etc/init.d/qmail start , /etc/init.d/psa startall , /etc/init.d/ssh (or sshd) restart&lt;br /&gt;
|-&lt;br /&gt;
|last&lt;br /&gt;
|Displays logged in users, when and where people last connected from.&lt;br /&gt;
|whoami and id show the user you are logged in as. w shows logged in users only.&lt;br /&gt;
|-&lt;br /&gt;
|ls -lah&lt;br /&gt;
|This lists the current files in the directory you are in and shows the permissions, ownerships, dates, file size, hidden files&lt;br /&gt;
|Use man ls to find out alternate options. -l uses a long listing format. -a is all. -h makes it human readable&lt;br /&gt;
|-&lt;br /&gt;
|mkdir &amp;lt;directoryname&amp;gt;&lt;br /&gt;
|This creates a directory&lt;br /&gt;
|[[Linux#File_Permissions|File Permissions]]&lt;br /&gt;
|-&lt;br /&gt;
|mv&lt;br /&gt;
|Used to permanently move a file from one file directory to another or rename a file&lt;br /&gt;
|-&lt;br /&gt;
|pwd&lt;br /&gt;
|This shows the directory you are currently in.&lt;br /&gt;
|Stands for Present Working Directory&lt;br /&gt;
|-&lt;br /&gt;
|rm&lt;br /&gt;
|Used to delete a file or empty folder&lt;br /&gt;
|Note: You cannot remove a folder with files/folder in it with -R&lt;br /&gt;
|-&lt;br /&gt;
|rm -rf &amp;lt;foldername&amp;gt;/*; rmdir &amp;lt;foldername&amp;gt;&lt;br /&gt;
|This recursively and forcibly removes a folder and anything below it&lt;br /&gt;
|To Be Filled In&lt;br /&gt;
|-&lt;br /&gt;
|touch &amp;lt;filename&amp;gt;&lt;br /&gt;
|This creates a file &amp;gt;&lt;br /&gt;
|If you want to enter the file straight after, use touch filename | vim filename&lt;br /&gt;
|-&lt;br /&gt;
|usermod&lt;br /&gt;
|This allows you to add users to groups, change their username. Do man usermod for more info.&lt;br /&gt;
|Example: usermod -a -G group username . This can be used to allow one website to access another&#039;s Virtual Host content.&lt;br /&gt;
|-&lt;br /&gt;
|vim &amp;lt;filename&amp;gt;&lt;br /&gt;
|Enters a file, press insert to edit, escape to stop editing &amp;gt;&lt;br /&gt;
|Type :q to quit without saving, :wq to quit and save, ! after to force&lt;br /&gt;
|-&lt;br /&gt;
|wc -l&lt;br /&gt;
|Wordcount. You can use this to see the amount of entries in a command.&lt;br /&gt;
|Do ls | wc -l to see amount of files in a directory, netstat -ant | wc -l to check amount of network connections&lt;br /&gt;
|-&lt;br /&gt;
|wget&lt;br /&gt;
|This grabs a file from somewhere. The example in the next column gets a PHP page.&lt;br /&gt;
|Example: wget linuxcommand.org/lts0070.php&lt;br /&gt;
|-&lt;br /&gt;
|which&lt;br /&gt;
|This shows the full path of (shell) commands.&lt;br /&gt;
|Useful for after installing software.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* If you want to wget a link that starts with https, do wget http://www.domain.co.uk/page.php --no-check-certificate&lt;br /&gt;
&lt;br /&gt;
* If you get &amp;quot;Argument list too long&amp;quot; when deleting do mv cur cur.old ; mkdir cur . You can then delete cur.old at your leisure. Alternatively if you can remove it without worrying about loss of data, cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
* If you go into the /etc/init.d/ you will see the services that are available to enable/disable.&lt;br /&gt;
&lt;br /&gt;
Using the command locate &amp;lt;file_or_folder&amp;gt; you can find where the files and directories are located. If this command shows &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;, please type updatedb and wait for it to finish and then try to locate the file again. If it fails, please see [[Linux#updatedb_.28locate_command.29|updatedb]]. &lt;br /&gt;
&lt;br /&gt;
* To reboot the server simply type reboot on it&#039;s own.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;To monitor running services/processes, CPU usage, RAM usage and other information run the command top&#039;&#039;&#039;. An alternate is called htop which you can run by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install htop&lt;br /&gt;
#or&lt;br /&gt;
yum update&lt;br /&gt;
yum install htop&lt;br /&gt;
htop (press F10 to exit)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use sed(1) to edit a file in place. E.g. to replace every &#039;e&#039; with an &#039;o&#039;, in a file named &#039;foo&#039;, you can do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sed -i.bak s/e/o/g foo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you&#039;ll get a backup of the original in a file named &#039;foo.bak&#039;, but if you want no backup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sed -i &#039;&#039; s/e/o/g foo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://en.wikipedia.org/wiki/Chattr Chattr] ===&lt;br /&gt;
&lt;br /&gt;
To check if it is protected lsattr file&amp;lt;br&amp;gt;&lt;br /&gt;
To protect a file, use chattr +i&amp;lt;br&amp;gt;&lt;br /&gt;
To remove this protection do chattr -i&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;Operation not permitted&amp;quot; you may need to do this on a folder to remove the protection on a file.&lt;br /&gt;
&lt;br /&gt;
=== Empty a file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kick user out of SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kill the process ID that has the same &amp;quot;sshd: root@tty&amp;quot;, e.g. sshd: root@pts/2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;kill processID&lt;br /&gt;
#e.g. kill 12716&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, kill use SIGTERM 15 so does a nice exit, so this will write their commands to the .bash_history file.&lt;br /&gt;
&lt;br /&gt;
=== View file ===&lt;br /&gt;
&lt;br /&gt;
Using [http://en.wikipedia.org/wiki/Less_(Unix) less] can be very useful. Use capital G and this will go to the bottom of the file. You can use spacebar to page down or B to page up.&lt;br /&gt;
&lt;br /&gt;
== Speed up SSH login ==&lt;br /&gt;
&lt;br /&gt;
vim /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
GSSAPIAuthentication=no&amp;lt;br&amp;gt;&lt;br /&gt;
UseDNS=no&lt;br /&gt;
&lt;br /&gt;
== sshd rootkit on Unix systems ==&lt;br /&gt;
&lt;br /&gt;
Feb 22, 2013 - http://kb.parallels.com/en/115589&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This issue is not related to Parallels products but all sshd-enabled systems are potentially vulnerable. Security checks are strongly advised.&lt;br /&gt;
&lt;br /&gt;
== SSH/OpenSSH Keys ==&lt;br /&gt;
&lt;br /&gt;
== SSH Port ==&lt;br /&gt;
&lt;br /&gt;
By default this is 22. This can be defined in /etc/ssh/sshd_config&lt;br /&gt;
&lt;br /&gt;
If you are getting one of the following errors when trying to start the SSH service using &#039;&#039;/etc/init.d/ssh start&#039;&#039; or go into it using &#039;&#039;ssh root@IPaddress&#039;&#039; :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;start: Job failed to start&lt;br /&gt;
ssh: connect to host port 22: Connection refused&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove the line that starts with &amp;quot;oom never&amp;quot; in /etc/init/ssh.conf&lt;br /&gt;
&lt;br /&gt;
== Wuff -- Wuff!! ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim ~/.bashrc&lt;br /&gt;
&lt;br /&gt;
alias screen=&#039;TERM=screen screen&#039;&lt;br /&gt;
&lt;br /&gt;
source ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This problem is caused the screen developers stubbornly sticking to the view that backspace should be non-destructive. Thus when your terminal, say xterm, sends a destructive backspace, screen treats it it like a delete. Here is the entry in their FAQ:&lt;br /&gt;
&lt;br /&gt;
Q: The cursor left key deletes the characters instead of just moving the cursor. A redisplay (^Al) brings everything back.&amp;lt;br&amp;gt;&lt;br /&gt;
A: Your terminal emulator (probably xterm) treats the backspace as “destructive”. You can probably change this somewhere in the setup. We can’t think of a reason why anybody would want a destructive backspace, but if you really must have it, add the line&lt;br /&gt;
&lt;br /&gt;
termcapinfo xterm ‘bc@:bs@’&lt;br /&gt;
&lt;br /&gt;
to your ~/.screenrc (replace xterm with the terminal type of your emulator, if different).&lt;br /&gt;
&lt;br /&gt;
Add that line to /etc/screenrc and you can fix it system wide.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134035</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134035"/>
		<updated>2025-01-08T16:17:08Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
For SSH, add this to ~/.bash_profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f ~/.bashrc ]; then&lt;br /&gt;
      . ~/.bashrc&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;set background=dark&lt;br /&gt;
syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134034</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134034"/>
		<updated>2025-01-08T16:05:30Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;set background=dark&lt;br /&gt;
syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=134033</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=134033"/>
		<updated>2025-01-07T18:05:37Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Increase Linux VM ext4 disk size on Proxmox 6 ===&lt;br /&gt;
&lt;br /&gt;
https://kb.vander.host/disk-management/how-to-enlarge-an-ext4-or-lvm-disk-on-an-ubuntu-proxmox-vm/&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134032</id>
		<title>MediaWiki</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134032"/>
		<updated>2025-01-03T21:56:47Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful areas for customisation are: /wiki/Special:AllMessages and [http://www.mediawiki.org/wiki/Manual:System_message#Built-in_system_messages   Built-in system messages]. You can normally just click the link from the list to edit the text.&lt;br /&gt;
&lt;br /&gt;
== Asynchronous snippet ==&lt;br /&gt;
&lt;br /&gt;
From [http://www.mediawiki.org/wiki/Extension_talk:Google_Analytics_Integration#How_to_set_the_new_asynchronous_snippet_before_the_head_tag_.28mw_.3C_1.17.29 here]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd extensions/googleAnalytics&lt;br /&gt;
cp googleAnalytics.php googleAnalytics.php.backup&lt;br /&gt;
vim googleAnalytics.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter the below text into the file and replace the UA- value below with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
if ( !defined( &#039;MEDIAWIKI&#039; ) ) {&lt;br /&gt;
        die( &#039;This file is a MediaWiki extension, it is not a valid entry point&#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$wgExtensionCredits[&#039;other&#039;][] = array(&lt;br /&gt;
        &#039;path&#039;           =&amp;gt; __FILE__,&lt;br /&gt;
        &#039;name&#039;           =&amp;gt; &#039;Google Analytics Integration&#039;,&lt;br /&gt;
        &#039;version&#039;        =&amp;gt; &#039;2.0.2&#039;,&lt;br /&gt;
        &#039;author&#039;         =&amp;gt; &#039;Tim Laqua&#039;,&lt;br /&gt;
        &#039;descriptionmsg&#039; =&amp;gt; &#039;googleanalytics-desc&#039;,&lt;br /&gt;
        &#039;url&#039;            =&amp;gt; &#039;http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration&#039;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$wgExtensionMessagesFiles[&#039;googleAnalytics&#039;] = dirname(__FILE__) . &#039;/googleAnalytics.i18n.php&#039;;&lt;br /&gt;
&lt;br /&gt;
$wgHooks[&#039;BeforePageDisplay&#039;][]  = &#039;efGoogleAnalyticsHookText&#039;;&lt;br /&gt;
$wgHooks[&#039;ParserAfterTidy&#039;][] = &#039;efGoogleAnalyticsASAC&#039;;&lt;br /&gt;
&lt;br /&gt;
# registered account&lt;br /&gt;
$wgGoogleAnalyticsAccount = &amp;quot;UA-XXXXX-X&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true&lt;br /&gt;
$wgGoogleAnalyticsAddASAC = false;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreSysops = true;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreBots = true;&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsASAC( &amp;amp;$parser, &amp;amp;$text ) {&lt;br /&gt;
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;&lt;br /&gt;
&lt;br /&gt;
        if( !empty($wgGoogleAnalyticsAccount) &amp;amp;&amp;amp; $wgGoogleAnalyticsAddASAC ) {&lt;br /&gt;
                $wgOut-&amp;gt;addScript(&#039;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;window.google_analytics_uacct = &amp;quot;&#039; . $wgGoogleAnalyticsAccount . &#039;&amp;quot;;&amp;lt;/script&amp;gt;&#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsHookText( $out ) {&lt;br /&gt;
        $out-&amp;gt;addScript( efAddGoogleAnalytics() );&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efAddGoogleAnalytics() {&lt;br /&gt;
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;&lt;br /&gt;
        if (!$wgUser-&amp;gt;isAllowed(&#039;bot&#039;) || !$wgGoogleAnalyticsIgnoreBots) {&lt;br /&gt;
                if (!$wgUser-&amp;gt;isAllowed(&#039;protect&#039;) || !$wgGoogleAnalyticsIgnoreSysops) {&lt;br /&gt;
                        if ( !empty($wgGoogleAnalyticsAccount) ) {&lt;br /&gt;
                                $funcOutput = &amp;lt;&amp;lt;&amp;lt;GASCRIPT&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
var _gaq = _gaq || [];&lt;br /&gt;
_gaq.push([&#039;_setAccount&#039;, &#039;$wgGoogleAnalyticsAccount&#039;]);&lt;br /&gt;
_gaq.push([&#039;_trackPageview&#039;]);&lt;br /&gt;
(function() {&lt;br /&gt;
var ga = document.createElement(&#039;script&#039;); ga.type = &#039;text/javascript&#039;; ga.async = true;&lt;br /&gt;
ga.src = (&#039;https:&#039; == document.location.protocol ? &#039;https://ssl&#039; : &#039;http://www&#039;) + &#039;.google-analytics.com/ga.js&#039;;&lt;br /&gt;
var s = document.getElementsByTagName(&#039;script&#039;)[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
GASCRIPT;&lt;br /&gt;
                        } else {&lt;br /&gt;
                                $funcOutput = &amp;quot;\n&amp;lt;!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --&amp;gt;&amp;quot;;&lt;br /&gt;
                        }&lt;br /&gt;
                } else {&lt;br /&gt;
                        $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for users with &#039;protect&#039; rights (I.E. sysops) --&amp;gt;&amp;quot;;&lt;br /&gt;
                }&lt;br /&gt;
        } else {&lt;br /&gt;
                $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for bots --&amp;gt;&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $funcOutput;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///Alias for efAddGoogleAnalytics - backwards compatibility.&lt;br /&gt;
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
On Unix Debian based (so Ubuntu as well), do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /var/www/sites/domain.co.uk&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz&lt;br /&gt;
tar xvzf mediawiki-*.tar.gz&lt;br /&gt;
cd mediawiki-1.20.2&lt;br /&gt;
mv mediawiki-1.20.2/* .&lt;br /&gt;
mv .gitreview .jshintignore .jshintrc ..&lt;br /&gt;
apt-get install mysql-server build-essential&lt;br /&gt;
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++&lt;br /&gt;
pecl install intl&lt;br /&gt;
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime&lt;br /&gt;
pecl install Memcache&lt;br /&gt;
pear install net_smtp&lt;br /&gt;
vim /etc/php5/apache2/php.ini # you need Apache installed first)&lt;br /&gt;
# as well as&lt;br /&gt;
vim /etc/php5/cli/php.ini&lt;br /&gt;
/Dynamic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;extension=intl.so&lt;br /&gt;
extension=memcache.so&lt;br /&gt;
memcache.hash_strategy=&amp;quot;consistent&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a caching software between APC and [http://www.gossamer-threads.com/lists/wiki/wikitech/127717?do=post_view_threaded#127717 xcache]. If you want APC, use [http://serverkb.co.uk/wiki/APC this]. If you want xcache, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install php5-xcache&lt;br /&gt;
memcached -u root -d -m 2048 -l 10.0.0.40 -p 11211&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/www/sites&lt;br /&gt;
chown root:root domain.co.uk/ -R&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
chmod 700 LocalSettings.php&lt;br /&gt;
apt-get install qmail&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will state:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;qmail will refuse to accept SMTP messages except to `hostname`.&lt;br /&gt;
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check this: http://www.mediawiki.org/wiki/Manual:Config_script&lt;br /&gt;
&lt;br /&gt;
And go to domain.co.uk/index.php and run through the configuration. Then download the LocalSettings.php file.&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Securing_database_passwords&lt;br /&gt;
&lt;br /&gt;
=== Account confirmation ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ConfirmAccount&lt;br /&gt;
&lt;br /&gt;
Upload the .tar.gz to /var/www/sites/domain.co.uk/extensions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xzf ConfirmAccount.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmAccount/ConfirmAccount.php&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file and run php maintenance/update.php&lt;br /&gt;
&lt;br /&gt;
To turn off &amp;quot;Your biography must be at least 50 words long.&amp;quot;, as this does not use $wgAccountRequestMinWords any more:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/www/sites/domain.co.uk/extensions/ConfirmAccount/ConfirmAccount.config.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&#039;Biography&#039;       =&amp;gt; array( &#039;enabled&#039; =&amp;gt; true, &#039;minWords&#039; =&amp;gt; 50 ),&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error when approving an account:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Could not create directory &amp;quot;mwstore://accountcreds-backend/accountcreds-public/1/12/123&amp;quot;.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chown www-data:www-data images/ -R&lt;br /&gt;
chmod 755 images/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also check your &amp;quot;$wgFileExtensions = {&#039;gif&#039;, &#039;png&#039;);&amp;quot; entry&lt;br /&gt;
&lt;br /&gt;
You may need to create an array, something like this:&lt;br /&gt;
&lt;br /&gt;
$wgFileExtensions = array(&#039;gif&#039;,&#039;png&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Capitalise headers and tab titles ===&lt;br /&gt;
&lt;br /&gt;
vim domain.co.uk/skins/monobook/main.css&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;.portlet h5 {&lt;br /&gt;
        background: transparent;&lt;br /&gt;
        padding: 0 1em 0 .5em;&lt;br /&gt;
        display: inline;&lt;br /&gt;
        height: 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        font-size: 91%;&lt;br /&gt;
        font-weight: normal;&lt;br /&gt;
        white-space: nowrap;&lt;br /&gt;
}&lt;br /&gt;
.portlet h6 {&lt;br /&gt;
        background: #ffae2e;&lt;br /&gt;
        border: 1px solid #2f6fab;&lt;br /&gt;
        border-style: solid solid none solid;&lt;br /&gt;
        padding: 0 1em 0 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        display: block;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-personal ul {&lt;br /&gt;
        text-transform: capitalize;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-cactions li a {&lt;br /&gt;
/*      text-transform: lowercase; */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit the Sidebar ===&lt;br /&gt;
&lt;br /&gt;
Go to http://domain.co.uk/wiki/MediaWiki:Sidebar&lt;br /&gt;
&lt;br /&gt;
=== Recaptcha installation ===&lt;br /&gt;
&lt;br /&gt;
First go [https://www.google.com/recaptcha/admin/create here] and obtain a public and private key for your wiki.&lt;br /&gt;
&lt;br /&gt;
Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmEdit/ReCaptcha.php&amp;quot;); &lt;br /&gt;
$wgCaptchaClass = &#039;ReCaptcha&#039;;&lt;br /&gt;
$wgReCaptchaPublicKey = &#039;your public key here&#039;;&lt;br /&gt;
$wgReCaptchaPrivateKey = &#039;your private key here&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Short URL configuration ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Short_URL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgScriptPath       = &amp;quot;&amp;quot;;&lt;br /&gt;
$wgArticlePath      = &#039;/wiki/$1&#039;;&lt;br /&gt;
$wgUsePathInfo      = true;&lt;br /&gt;
$wgScriptExtension  = &amp;quot;.php&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2enmod rewrite&lt;br /&gt;
/etc/init.d/apache2 restart&lt;br /&gt;
vim /etc/apache2/sites-available/domain.co.uk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;    RewriteEngine On&lt;br /&gt;
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2 [L,QSA,B]&lt;br /&gt;
&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2&amp;amp;archived=1 [L,QSA,B]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php: http://shorturls.redwerks.org&lt;br /&gt;
&lt;br /&gt;
== Old edited Special:AllMessages ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To help protect against automated page creation, please type the two words you see in the box below ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Migrating to a new server ==&lt;br /&gt;
&lt;br /&gt;
On the original server, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysqldump --default-character-set=binary --user=root databasename &amp;gt; dbdump.txt -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then copy all your content and the dbdump.txt file across to the new server. &lt;br /&gt;
&lt;br /&gt;
To delete a useless database, do this from within MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DROP DATABASE wikidb;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to create an empty database first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create database DatabaseName;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then on the new server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysql --silent --local DatabaseName &amp;lt; dbdump.txt -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;DatabaseUser&#039;@&#039;localhost&#039; identified by &#039;password&#039;;&lt;br /&gt;
GRANT ALL PRIVILEGES ON DatabaseName.* TO &#039;DatabaseUser&#039;@&#039;%&#039; IDENTIFIED BY &#039;password&#039; WITH GRANT OPTION ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your LocalSettings.php to ensure the following setting are correct:&lt;br /&gt;
&lt;br /&gt;
$wgDBtype           = &amp;quot;mysql&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBserver         = &amp;quot;localhost&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBname           = &amp;quot;DatabaseName&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBuser           = &amp;quot;DatabaseUser&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBpassword       = &amp;quot;DatabaseUserPassword*&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
== Lock down mw-config directory ==&lt;br /&gt;
&lt;br /&gt;
Access your install via command line, and set the permissions of the directory to restricted. On Linux, this is done like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 000 mw-config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sitemap ==&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ManualSitemap&lt;br /&gt;
&lt;br /&gt;
cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak&amp;lt;br&amp;gt;&lt;br /&gt;
vim maintenance/generateSitemap.php&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/User:Superxain/GenerateSitemap (from [http://www.mediawiki.org/wiki/Manual_talk:GenerateSitemap.php#A_BUG_FIX_to_work_the_Google_Webmaster_Tools here])&lt;br /&gt;
&lt;br /&gt;
== Spam accounts ==&lt;br /&gt;
&lt;br /&gt;
ServerKB over 4 years (2021 to 2025) had ~300,000 spam pages and ~20,000 spam accounts created. To save someone the hassle I went to trying to remove all these over a couple of days I documented the steps and tools I used below.&lt;br /&gt;
&lt;br /&gt;
Stats can be checked for your own MediaWiki via these pages:&lt;br /&gt;
Special:ListUsers&lt;br /&gt;
Special:Statistics&lt;br /&gt;
You will want to use these pages throughout your analysis and resolution to keep an eye on the numbers.&lt;br /&gt;
&lt;br /&gt;
If you do not wish to follow the below, you can instead export the known good pages, create a new database, update mediawiki and import the good pages.&lt;br /&gt;
&lt;br /&gt;
First recommendation, upgrade MediaWiki to the latest version possible: https://www.mediawiki.org/wiki/Manual:Upgrading&lt;br /&gt;
As always, make a backup of your database before upgrading.&lt;br /&gt;
Make sure you read the deprecated LocalSettings.php options between updates as well as disabling extensions that are not supported or up to date then enabling them after the upgrade (if compatible).&lt;br /&gt;
&lt;br /&gt;
In the case of ServerKB, I upgraded from 1.36 up to 1.42 via 1.36 &amp;gt; 1.37 &amp;gt; 1.38 &amp;gt; 1.42&lt;br /&gt;
This did require downgrading PHP from 8.3 to 8.1.&lt;br /&gt;
&lt;br /&gt;
If at any time during this process you run php scripts e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/runJobs.php&lt;br /&gt;
php maintenance/run.php update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And get the following type of errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[4758ee24ec3e12702aba0fed] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/doMaintenance.php(83): require_once(string)&lt;br /&gt;
#2 maintenance/runJobs.php(136): require_once(string)&lt;br /&gt;
#3 {main}&lt;br /&gt;
&lt;br /&gt;
[026858f401e7f387106a367e] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/run.php(49): require_once(string)&lt;br /&gt;
#2 {main}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should comment out all extensions (from both wfload and require_once) in LocalSettings.php as these were how I resolved these issues with an old unsupported captcha extension.&lt;br /&gt;
&lt;br /&gt;
During the upgrades, you will need to run this command regularly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php update.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would recommend doing this with your web server (Apache) and database (MySQL) in a stopped state, as this allows you to correct any issues that halt the update/upgrade e.g. missing extensions, missing extension files, missing LocalSettings.php&lt;br /&gt;
&lt;br /&gt;
Note: Tools like BlockAndNuke (deprecated), NukeDPL, SmiteSpam and UserMerge (only supports 1 user at a time) did not work for me as they were either not supported on my version of MediaWiki, out of date, not supported any more or just didn&#039;t work. This guide seemed good but fell short as it didn&#039;t work for me: https://www.simplecloudworks.com/how-to-delete-a-long-list-of-spam-users-in-mediawiki/&lt;br /&gt;
&lt;br /&gt;
You will then want to utilise the following scripts via command line:&lt;br /&gt;
&lt;br /&gt;
=== Deleting multiple pages on mass ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Help:Extension:Nuke&lt;br /&gt;
&lt;br /&gt;
Nuke is best used when you haven&#039;t updated anything for over 30 days but the spammers have, but you can update LocalSettings.php to increase this check threshold:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgNukeMaxAge = &amp;lt;days&amp;gt; * 86400;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Special:AncientPages and Special:RecentChanges are both useful for checking older pages vs newer spam pages.&lt;br /&gt;
&lt;br /&gt;
You can delete pages via SQL for pages edited before or after a certain date using this method: https://stackoverflow.com/questions/8839603/remove-mediawiki-pages-before-a-certain-date&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:DeleteBatch&lt;br /&gt;
&lt;br /&gt;
The best way to use DeleteBatch for &amp;quot;User&amp;quot; pages (User namespace) is to get the list of spam accounts either from the database user table (using user_name) or from Special:ListUsers 500 at a time, copying these into a notepad (to remove formatting), save the file, then open the file in Excel using the bracket symbol as the delimiter, find and replace where needed to remove text you don&#039;t want (e.g. talk contrib block)&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=CONCATENATE(&amp;quot;User:&amp;quot;, C1)&amp;quot; in Excel to add the prefix for removing user pages via DeleteBatch.&lt;br /&gt;
&lt;br /&gt;
You basically want to go from this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;MamieNewquist0  &amp;quot;&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;User:MamieNewquist0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=TRIM(A1)&amp;quot; in Excel to remove/strip spaces after usernames if needed.&lt;br /&gt;
For accounts that are just numbers, be careful when Excel auto-formats the cells with these account names as it can often strip numbers or convert them.&lt;br /&gt;
&lt;br /&gt;
Then you can call a long list of user pages from one text file like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteBatch /root/userpages.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting unused accounts ===&lt;br /&gt;
&lt;br /&gt;
Check your active users first via Special:ActiveUsers&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:RemoveUnusedAccounts.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php removeUnusedAccounts --delete --ignore-groups administrators,Administrators,administrator,bureaucrats&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this only works for accounts that have never made any edits or contributions INCLUDING deleted edits/contributions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting archived revisions ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:DeleteArchivedRevisions.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteArchivedRevisions --delete&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would also recommend running RemoveUnusedAccounts again after running DeleteArchivedRevisions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting accounts that made contributions/edits ===&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/600818/how-do-i-delete-all-non-confirmed-users-in-mediawiki&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; DELETE FROM user WHERE NOT user_name=&#039;&amp;lt;insert_your_admin_account_here&amp;gt;&#039;;&lt;br /&gt;
Query OK, 14536 rows affected (1.60 sec)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix statistics ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:InitSiteStats.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php initSiteStats --update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Follow up recommendations ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/User:Neoshinji#Prevent_spam_bots_from_registering&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual_talk:Combating_spam&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:Combating_spam#:~:text=Extension%3AAbuseFilter%20allows%20privileged%20users,links%20added%2C%20and%20so%20on.&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:ConfirmEdit#QuestyCaptcha&lt;br /&gt;
&lt;br /&gt;
If you use Cloudflare:&lt;br /&gt;
https://community.cloudflare.com/t/page-country-redirect-possible-with-cloudflare/485283&lt;br /&gt;
https://tenten.co/insight/dev/country-redirect-with-cloudflare/#:~:text=To%20redirect%20based%20on%20the,country%20variable%20for%20this.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134031</id>
		<title>MediaWiki</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134031"/>
		<updated>2025-01-03T21:42:30Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful areas for customisation are: /wiki/Special:AllMessages and [http://www.mediawiki.org/wiki/Manual:System_message#Built-in_system_messages   Built-in system messages]. You can normally just click the link from the list to edit the text.&lt;br /&gt;
&lt;br /&gt;
== Asynchronous snippet ==&lt;br /&gt;
&lt;br /&gt;
From [http://www.mediawiki.org/wiki/Extension_talk:Google_Analytics_Integration#How_to_set_the_new_asynchronous_snippet_before_the_head_tag_.28mw_.3C_1.17.29 here]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd extensions/googleAnalytics&lt;br /&gt;
cp googleAnalytics.php googleAnalytics.php.backup&lt;br /&gt;
vim googleAnalytics.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter the below text into the file and replace the UA- value below with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
if ( !defined( &#039;MEDIAWIKI&#039; ) ) {&lt;br /&gt;
        die( &#039;This file is a MediaWiki extension, it is not a valid entry point&#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$wgExtensionCredits[&#039;other&#039;][] = array(&lt;br /&gt;
        &#039;path&#039;           =&amp;gt; __FILE__,&lt;br /&gt;
        &#039;name&#039;           =&amp;gt; &#039;Google Analytics Integration&#039;,&lt;br /&gt;
        &#039;version&#039;        =&amp;gt; &#039;2.0.2&#039;,&lt;br /&gt;
        &#039;author&#039;         =&amp;gt; &#039;Tim Laqua&#039;,&lt;br /&gt;
        &#039;descriptionmsg&#039; =&amp;gt; &#039;googleanalytics-desc&#039;,&lt;br /&gt;
        &#039;url&#039;            =&amp;gt; &#039;http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration&#039;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$wgExtensionMessagesFiles[&#039;googleAnalytics&#039;] = dirname(__FILE__) . &#039;/googleAnalytics.i18n.php&#039;;&lt;br /&gt;
&lt;br /&gt;
$wgHooks[&#039;BeforePageDisplay&#039;][]  = &#039;efGoogleAnalyticsHookText&#039;;&lt;br /&gt;
$wgHooks[&#039;ParserAfterTidy&#039;][] = &#039;efGoogleAnalyticsASAC&#039;;&lt;br /&gt;
&lt;br /&gt;
# registered account&lt;br /&gt;
$wgGoogleAnalyticsAccount = &amp;quot;UA-XXXXX-X&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true&lt;br /&gt;
$wgGoogleAnalyticsAddASAC = false;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreSysops = true;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreBots = true;&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsASAC( &amp;amp;$parser, &amp;amp;$text ) {&lt;br /&gt;
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;&lt;br /&gt;
&lt;br /&gt;
        if( !empty($wgGoogleAnalyticsAccount) &amp;amp;&amp;amp; $wgGoogleAnalyticsAddASAC ) {&lt;br /&gt;
                $wgOut-&amp;gt;addScript(&#039;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;window.google_analytics_uacct = &amp;quot;&#039; . $wgGoogleAnalyticsAccount . &#039;&amp;quot;;&amp;lt;/script&amp;gt;&#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsHookText( $out ) {&lt;br /&gt;
        $out-&amp;gt;addScript( efAddGoogleAnalytics() );&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efAddGoogleAnalytics() {&lt;br /&gt;
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;&lt;br /&gt;
        if (!$wgUser-&amp;gt;isAllowed(&#039;bot&#039;) || !$wgGoogleAnalyticsIgnoreBots) {&lt;br /&gt;
                if (!$wgUser-&amp;gt;isAllowed(&#039;protect&#039;) || !$wgGoogleAnalyticsIgnoreSysops) {&lt;br /&gt;
                        if ( !empty($wgGoogleAnalyticsAccount) ) {&lt;br /&gt;
                                $funcOutput = &amp;lt;&amp;lt;&amp;lt;GASCRIPT&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
var _gaq = _gaq || [];&lt;br /&gt;
_gaq.push([&#039;_setAccount&#039;, &#039;$wgGoogleAnalyticsAccount&#039;]);&lt;br /&gt;
_gaq.push([&#039;_trackPageview&#039;]);&lt;br /&gt;
(function() {&lt;br /&gt;
var ga = document.createElement(&#039;script&#039;); ga.type = &#039;text/javascript&#039;; ga.async = true;&lt;br /&gt;
ga.src = (&#039;https:&#039; == document.location.protocol ? &#039;https://ssl&#039; : &#039;http://www&#039;) + &#039;.google-analytics.com/ga.js&#039;;&lt;br /&gt;
var s = document.getElementsByTagName(&#039;script&#039;)[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
GASCRIPT;&lt;br /&gt;
                        } else {&lt;br /&gt;
                                $funcOutput = &amp;quot;\n&amp;lt;!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --&amp;gt;&amp;quot;;&lt;br /&gt;
                        }&lt;br /&gt;
                } else {&lt;br /&gt;
                        $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for users with &#039;protect&#039; rights (I.E. sysops) --&amp;gt;&amp;quot;;&lt;br /&gt;
                }&lt;br /&gt;
        } else {&lt;br /&gt;
                $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for bots --&amp;gt;&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $funcOutput;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///Alias for efAddGoogleAnalytics - backwards compatibility.&lt;br /&gt;
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
On Unix Debian based (so Ubuntu as well), do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /var/www/sites/domain.co.uk&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz&lt;br /&gt;
tar xvzf mediawiki-*.tar.gz&lt;br /&gt;
cd mediawiki-1.20.2&lt;br /&gt;
mv mediawiki-1.20.2/* .&lt;br /&gt;
mv .gitreview .jshintignore .jshintrc ..&lt;br /&gt;
apt-get install mysql-server build-essential&lt;br /&gt;
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++&lt;br /&gt;
pecl install intl&lt;br /&gt;
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime&lt;br /&gt;
pecl install Memcache&lt;br /&gt;
pear install net_smtp&lt;br /&gt;
vim /etc/php5/apache2/php.ini # you need Apache installed first)&lt;br /&gt;
# as well as&lt;br /&gt;
vim /etc/php5/cli/php.ini&lt;br /&gt;
/Dynamic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;extension=intl.so&lt;br /&gt;
extension=memcache.so&lt;br /&gt;
memcache.hash_strategy=&amp;quot;consistent&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a caching software between APC and [http://www.gossamer-threads.com/lists/wiki/wikitech/127717?do=post_view_threaded#127717 xcache]. If you want APC, use [http://serverkb.co.uk/wiki/APC this]. If you want xcache, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install php5-xcache&lt;br /&gt;
memcached -u root -d -m 2048 -l 10.0.0.40 -p 11211&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/www/sites&lt;br /&gt;
chown root:root domain.co.uk/ -R&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
chmod 700 LocalSettings.php&lt;br /&gt;
apt-get install qmail&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will state:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;qmail will refuse to accept SMTP messages except to `hostname`.&lt;br /&gt;
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check this: http://www.mediawiki.org/wiki/Manual:Config_script&lt;br /&gt;
&lt;br /&gt;
And go to domain.co.uk/index.php and run through the configuration. Then download the LocalSettings.php file.&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Securing_database_passwords&lt;br /&gt;
&lt;br /&gt;
=== Account confirmation ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ConfirmAccount&lt;br /&gt;
&lt;br /&gt;
Upload the .tar.gz to /var/www/sites/domain.co.uk/extensions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xzf ConfirmAccount.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmAccount/ConfirmAccount.php&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file and run php maintenance/update.php&lt;br /&gt;
&lt;br /&gt;
To turn off &amp;quot;Your biography must be at least 50 words long.&amp;quot;, as this does not use $wgAccountRequestMinWords any more:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/www/sites/domain.co.uk/extensions/ConfirmAccount/ConfirmAccount.config.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&#039;Biography&#039;       =&amp;gt; array( &#039;enabled&#039; =&amp;gt; true, &#039;minWords&#039; =&amp;gt; 50 ),&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error when approving an account:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Could not create directory &amp;quot;mwstore://accountcreds-backend/accountcreds-public/1/12/123&amp;quot;.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chown www-data:www-data images/ -R&lt;br /&gt;
chmod 755 images/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also check your &amp;quot;$wgFileExtensions = {&#039;gif&#039;, &#039;png&#039;);&amp;quot; entry&lt;br /&gt;
&lt;br /&gt;
You may need to create an array, something like this:&lt;br /&gt;
&lt;br /&gt;
$wgFileExtensions = array(&#039;gif&#039;,&#039;png&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Capitalise headers and tab titles ===&lt;br /&gt;
&lt;br /&gt;
vim domain.co.uk/skins/monobook/main.css&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;.portlet h5 {&lt;br /&gt;
        background: transparent;&lt;br /&gt;
        padding: 0 1em 0 .5em;&lt;br /&gt;
        display: inline;&lt;br /&gt;
        height: 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        font-size: 91%;&lt;br /&gt;
        font-weight: normal;&lt;br /&gt;
        white-space: nowrap;&lt;br /&gt;
}&lt;br /&gt;
.portlet h6 {&lt;br /&gt;
        background: #ffae2e;&lt;br /&gt;
        border: 1px solid #2f6fab;&lt;br /&gt;
        border-style: solid solid none solid;&lt;br /&gt;
        padding: 0 1em 0 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        display: block;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-personal ul {&lt;br /&gt;
        text-transform: capitalize;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-cactions li a {&lt;br /&gt;
/*      text-transform: lowercase; */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit the Sidebar ===&lt;br /&gt;
&lt;br /&gt;
Go to http://domain.co.uk/wiki/MediaWiki:Sidebar&lt;br /&gt;
&lt;br /&gt;
=== Recaptcha installation ===&lt;br /&gt;
&lt;br /&gt;
First go [https://www.google.com/recaptcha/admin/create here] and obtain a public and private key for your wiki.&lt;br /&gt;
&lt;br /&gt;
Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmEdit/ReCaptcha.php&amp;quot;); &lt;br /&gt;
$wgCaptchaClass = &#039;ReCaptcha&#039;;&lt;br /&gt;
$wgReCaptchaPublicKey = &#039;your public key here&#039;;&lt;br /&gt;
$wgReCaptchaPrivateKey = &#039;your private key here&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Short URL configuration ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Short_URL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgScriptPath       = &amp;quot;&amp;quot;;&lt;br /&gt;
$wgArticlePath      = &#039;/wiki/$1&#039;;&lt;br /&gt;
$wgUsePathInfo      = true;&lt;br /&gt;
$wgScriptExtension  = &amp;quot;.php&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2enmod rewrite&lt;br /&gt;
/etc/init.d/apache2 restart&lt;br /&gt;
vim /etc/apache2/sites-available/domain.co.uk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;    RewriteEngine On&lt;br /&gt;
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2 [L,QSA,B]&lt;br /&gt;
&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2&amp;amp;archived=1 [L,QSA,B]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php: http://shorturls.redwerks.org&lt;br /&gt;
&lt;br /&gt;
== Old edited Special:AllMessages ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To help protect against automated page creation, please type the two words you see in the box below ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Migrating to a new server ==&lt;br /&gt;
&lt;br /&gt;
On the original server, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysqldump --default-character-set=binary --user=root databasename &amp;gt; dbdump.txt -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then copy all your content and the dbdump.txt file across to the new server. &lt;br /&gt;
&lt;br /&gt;
To delete a useless database, do this from within MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DROP DATABASE wikidb;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to create an empty database first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create database DatabaseName;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then on the new server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysql --silent --local DatabaseName &amp;lt; dbdump.txt -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;DatabaseUser&#039;@&#039;localhost&#039; identified by &#039;password&#039;;&lt;br /&gt;
GRANT ALL PRIVILEGES ON DatabaseName.* TO &#039;DatabaseUser&#039;@&#039;%&#039; IDENTIFIED BY &#039;password&#039; WITH GRANT OPTION ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your LocalSettings.php to ensure the following setting are correct:&lt;br /&gt;
&lt;br /&gt;
$wgDBtype           = &amp;quot;mysql&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBserver         = &amp;quot;localhost&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBname           = &amp;quot;DatabaseName&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBuser           = &amp;quot;DatabaseUser&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBpassword       = &amp;quot;DatabaseUserPassword*&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
== Lock down mw-config directory ==&lt;br /&gt;
&lt;br /&gt;
Access your install via command line, and set the permissions of the directory to restricted. On Linux, this is done like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 000 mw-config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sitemap ==&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ManualSitemap&lt;br /&gt;
&lt;br /&gt;
cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak&amp;lt;br&amp;gt;&lt;br /&gt;
vim maintenance/generateSitemap.php&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/User:Superxain/GenerateSitemap (from [http://www.mediawiki.org/wiki/Manual_talk:GenerateSitemap.php#A_BUG_FIX_to_work_the_Google_Webmaster_Tools here])&lt;br /&gt;
&lt;br /&gt;
== Spam accounts ==&lt;br /&gt;
&lt;br /&gt;
ServerKB over 4 years (2021 to 2025) had ~300,000 spam pages and ~20,000 spam accounts created. To save someone the hassle I went to trying to remove all these over a couple of days I documented the steps and tools I used below.&lt;br /&gt;
&lt;br /&gt;
Stats can be checked for your own MediaWiki via these pages:&lt;br /&gt;
Special:ListUsers&lt;br /&gt;
Special:Statistics&lt;br /&gt;
You will want to use these pages throughout your analysis and resolution to keep an eye on the numbers.&lt;br /&gt;
&lt;br /&gt;
If you do not wish to follow the below, you can instead export the known good pages, create a new database, update mediawiki and import the good pages.&lt;br /&gt;
&lt;br /&gt;
First recommendation, upgrade MediaWiki to the latest version possible: https://www.mediawiki.org/wiki/Manual:Upgrading&lt;br /&gt;
As always, make a backup of your database before upgrading.&lt;br /&gt;
Make sure you read the deprecated LocalSettings.php options between updates as well as disabling extensions that are not supported or up to date then enabling them after the upgrade (if compatible).&lt;br /&gt;
&lt;br /&gt;
In the case of ServerKB, I upgraded from 1.36 up to 1.42 via 1.36 &amp;gt; 1.37 &amp;gt; 1.38 &amp;gt; 1.42&lt;br /&gt;
This did require downgrading PHP from 8.3 to 8.1.&lt;br /&gt;
&lt;br /&gt;
If at any time during this process you run php scripts e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/runJobs.php&lt;br /&gt;
php maintenance/run.php update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And get the following type of errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[4758ee24ec3e12702aba0fed] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/doMaintenance.php(83): require_once(string)&lt;br /&gt;
#2 maintenance/runJobs.php(136): require_once(string)&lt;br /&gt;
#3 {main}&lt;br /&gt;
&lt;br /&gt;
[026858f401e7f387106a367e] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/run.php(49): require_once(string)&lt;br /&gt;
#2 {main}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should comment out all extensions (from both wfload and require_once) in LocalSettings.php as these were how I resolved these issues with an old unsupported captcha extension.&lt;br /&gt;
&lt;br /&gt;
During the upgrades, you will need to run this command regularly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php update.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would recommend doing this with your web server (Apache) and database (MySQL) in a stopped state, as this allows you to correct any issues that halt the update/upgrade e.g. missing extensions, missing extension files, missing LocalSettings.php&lt;br /&gt;
&lt;br /&gt;
Note: Tools like BlockAndNuke, NukeDPL, SmiteSpam and UserMerge did not work for me as they were either not supported on my version of MediaWiki, out of date, not supported any more or just didn&#039;t work. This guide seemed good but fell short as it didn&#039;t work for me: https://www.simplecloudworks.com/how-to-delete-a-long-list-of-spam-users-in-mediawiki/&lt;br /&gt;
&lt;br /&gt;
You will then want to utilise the following scripts via command line:&lt;br /&gt;
&lt;br /&gt;
=== Deleting multiple pages on mass ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Help:Extension:Nuke&lt;br /&gt;
&lt;br /&gt;
Nuke is best used when you haven&#039;t updated anything for over 30 days but the spammers have, but you can update LocalSettings.php to increase this check threshold:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgNukeMaxAge = &amp;lt;days&amp;gt; * 86400;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Special:AncientPages and Special:RecentChanges are both useful for checking older pages vs newer spam pages.&lt;br /&gt;
&lt;br /&gt;
You can delete pages via SQL for pages edited before or after a certain date using this method: https://stackoverflow.com/questions/8839603/remove-mediawiki-pages-before-a-certain-date&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:DeleteBatch&lt;br /&gt;
&lt;br /&gt;
The best way to use DeleteBatch for &amp;quot;User&amp;quot; pages (User namespace) is to get the list of spam accounts either from the database user table (using user_name) or from Special:ListUsers 500 at a time, copying these into a notepad (to remove formatting), save the file, then open the file in Excel using the bracket symbol as the delimiter, find and replace where needed to remove text you don&#039;t want (e.g. talk contrib block)&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=CONCATENATE(&amp;quot;User:&amp;quot;, C1)&amp;quot; in Excel to add the prefix for removing user pages via DeleteBatch.&lt;br /&gt;
&lt;br /&gt;
You basically want to go from this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;MamieNewquist0  &amp;quot;&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;User:MamieNewquist0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=TRIM(A1)&amp;quot; in Excel to remove/strip spaces after usernames if needed.&lt;br /&gt;
For accounts that are just numbers, be careful when Excel auto-formats the cells with these account names as it can often strip numbers or convert them.&lt;br /&gt;
&lt;br /&gt;
Then you can call a long list of user pages from one text file like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteBatch /root/userpages.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting unused accounts ===&lt;br /&gt;
&lt;br /&gt;
Check your active users first via Special:ActiveUsers&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:RemoveUnusedAccounts.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php removeUnusedAccounts --delete --ignore-groups administrators,Administrators,administrator,bureaucrats&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this only works for accounts that have never made any edits or contributions INCLUDING deleted edits/contributions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting archived revisions ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:DeleteArchivedRevisions.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteArchivedRevisions --delete&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would also recommend running RemoveUnusedAccounts again after running DeleteArchivedRevisions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting accounts that made contributions/edits ===&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/600818/how-do-i-delete-all-non-confirmed-users-in-mediawiki&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; DELETE FROM user WHERE NOT user_name=&#039;&amp;lt;insert_your_admin_account_here&amp;gt;&#039;;&lt;br /&gt;
Query OK, 14536 rows affected (1.60 sec)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix statistics ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:InitSiteStats.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php initSiteStats --update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Follow up recommendations ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/User:Neoshinji#Prevent_spam_bots_from_registering&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual_talk:Combating_spam&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:Combating_spam#:~:text=Extension%3AAbuseFilter%20allows%20privileged%20users,links%20added%2C%20and%20so%20on.&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:ConfirmEdit#QuestyCaptcha&lt;br /&gt;
&lt;br /&gt;
If you use Cloudflare:&lt;br /&gt;
https://community.cloudflare.com/t/page-country-redirect-possible-with-cloudflare/485283&lt;br /&gt;
https://tenten.co/insight/dev/country-redirect-with-cloudflare/#:~:text=To%20redirect%20based%20on%20the,country%20variable%20for%20this.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134030</id>
		<title>MediaWiki</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134030"/>
		<updated>2025-01-03T21:33:41Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful areas for customisation are: /wiki/Special:AllMessages and [http://www.mediawiki.org/wiki/Manual:System_message#Built-in_system_messages   Built-in system messages]. You can normally just click the link from the list to edit the text.&lt;br /&gt;
&lt;br /&gt;
== Asynchronous snippet ==&lt;br /&gt;
&lt;br /&gt;
From [http://www.mediawiki.org/wiki/Extension_talk:Google_Analytics_Integration#How_to_set_the_new_asynchronous_snippet_before_the_head_tag_.28mw_.3C_1.17.29 here]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd extensions/googleAnalytics&lt;br /&gt;
cp googleAnalytics.php googleAnalytics.php.backup&lt;br /&gt;
vim googleAnalytics.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter the below text into the file and replace the UA- value below with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
if ( !defined( &#039;MEDIAWIKI&#039; ) ) {&lt;br /&gt;
        die( &#039;This file is a MediaWiki extension, it is not a valid entry point&#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$wgExtensionCredits[&#039;other&#039;][] = array(&lt;br /&gt;
        &#039;path&#039;           =&amp;gt; __FILE__,&lt;br /&gt;
        &#039;name&#039;           =&amp;gt; &#039;Google Analytics Integration&#039;,&lt;br /&gt;
        &#039;version&#039;        =&amp;gt; &#039;2.0.2&#039;,&lt;br /&gt;
        &#039;author&#039;         =&amp;gt; &#039;Tim Laqua&#039;,&lt;br /&gt;
        &#039;descriptionmsg&#039; =&amp;gt; &#039;googleanalytics-desc&#039;,&lt;br /&gt;
        &#039;url&#039;            =&amp;gt; &#039;http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration&#039;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$wgExtensionMessagesFiles[&#039;googleAnalytics&#039;] = dirname(__FILE__) . &#039;/googleAnalytics.i18n.php&#039;;&lt;br /&gt;
&lt;br /&gt;
$wgHooks[&#039;BeforePageDisplay&#039;][]  = &#039;efGoogleAnalyticsHookText&#039;;&lt;br /&gt;
$wgHooks[&#039;ParserAfterTidy&#039;][] = &#039;efGoogleAnalyticsASAC&#039;;&lt;br /&gt;
&lt;br /&gt;
# registered account&lt;br /&gt;
$wgGoogleAnalyticsAccount = &amp;quot;UA-XXXXX-X&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true&lt;br /&gt;
$wgGoogleAnalyticsAddASAC = false;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreSysops = true;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreBots = true;&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsASAC( &amp;amp;$parser, &amp;amp;$text ) {&lt;br /&gt;
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;&lt;br /&gt;
&lt;br /&gt;
        if( !empty($wgGoogleAnalyticsAccount) &amp;amp;&amp;amp; $wgGoogleAnalyticsAddASAC ) {&lt;br /&gt;
                $wgOut-&amp;gt;addScript(&#039;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;window.google_analytics_uacct = &amp;quot;&#039; . $wgGoogleAnalyticsAccount . &#039;&amp;quot;;&amp;lt;/script&amp;gt;&#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsHookText( $out ) {&lt;br /&gt;
        $out-&amp;gt;addScript( efAddGoogleAnalytics() );&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efAddGoogleAnalytics() {&lt;br /&gt;
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;&lt;br /&gt;
        if (!$wgUser-&amp;gt;isAllowed(&#039;bot&#039;) || !$wgGoogleAnalyticsIgnoreBots) {&lt;br /&gt;
                if (!$wgUser-&amp;gt;isAllowed(&#039;protect&#039;) || !$wgGoogleAnalyticsIgnoreSysops) {&lt;br /&gt;
                        if ( !empty($wgGoogleAnalyticsAccount) ) {&lt;br /&gt;
                                $funcOutput = &amp;lt;&amp;lt;&amp;lt;GASCRIPT&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
var _gaq = _gaq || [];&lt;br /&gt;
_gaq.push([&#039;_setAccount&#039;, &#039;$wgGoogleAnalyticsAccount&#039;]);&lt;br /&gt;
_gaq.push([&#039;_trackPageview&#039;]);&lt;br /&gt;
(function() {&lt;br /&gt;
var ga = document.createElement(&#039;script&#039;); ga.type = &#039;text/javascript&#039;; ga.async = true;&lt;br /&gt;
ga.src = (&#039;https:&#039; == document.location.protocol ? &#039;https://ssl&#039; : &#039;http://www&#039;) + &#039;.google-analytics.com/ga.js&#039;;&lt;br /&gt;
var s = document.getElementsByTagName(&#039;script&#039;)[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
GASCRIPT;&lt;br /&gt;
                        } else {&lt;br /&gt;
                                $funcOutput = &amp;quot;\n&amp;lt;!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --&amp;gt;&amp;quot;;&lt;br /&gt;
                        }&lt;br /&gt;
                } else {&lt;br /&gt;
                        $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for users with &#039;protect&#039; rights (I.E. sysops) --&amp;gt;&amp;quot;;&lt;br /&gt;
                }&lt;br /&gt;
        } else {&lt;br /&gt;
                $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for bots --&amp;gt;&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $funcOutput;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///Alias for efAddGoogleAnalytics - backwards compatibility.&lt;br /&gt;
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
On Unix Debian based (so Ubuntu as well), do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /var/www/sites/domain.co.uk&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz&lt;br /&gt;
tar xvzf mediawiki-*.tar.gz&lt;br /&gt;
cd mediawiki-1.20.2&lt;br /&gt;
mv mediawiki-1.20.2/* .&lt;br /&gt;
mv .gitreview .jshintignore .jshintrc ..&lt;br /&gt;
apt-get install mysql-server build-essential&lt;br /&gt;
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++&lt;br /&gt;
pecl install intl&lt;br /&gt;
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime&lt;br /&gt;
pecl install Memcache&lt;br /&gt;
pear install net_smtp&lt;br /&gt;
vim /etc/php5/apache2/php.ini # you need Apache installed first)&lt;br /&gt;
# as well as&lt;br /&gt;
vim /etc/php5/cli/php.ini&lt;br /&gt;
/Dynamic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;extension=intl.so&lt;br /&gt;
extension=memcache.so&lt;br /&gt;
memcache.hash_strategy=&amp;quot;consistent&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a caching software between APC and [http://www.gossamer-threads.com/lists/wiki/wikitech/127717?do=post_view_threaded#127717 xcache]. If you want APC, use [http://serverkb.co.uk/wiki/APC this]. If you want xcache, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install php5-xcache&lt;br /&gt;
memcached -u root -d -m 2048 -l 10.0.0.40 -p 11211&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/www/sites&lt;br /&gt;
chown root:root domain.co.uk/ -R&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
chmod 700 LocalSettings.php&lt;br /&gt;
apt-get install qmail&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will state:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;qmail will refuse to accept SMTP messages except to `hostname`.&lt;br /&gt;
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check this: http://www.mediawiki.org/wiki/Manual:Config_script&lt;br /&gt;
&lt;br /&gt;
And go to domain.co.uk/index.php and run through the configuration. Then download the LocalSettings.php file.&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Securing_database_passwords&lt;br /&gt;
&lt;br /&gt;
=== Account confirmation ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ConfirmAccount&lt;br /&gt;
&lt;br /&gt;
Upload the .tar.gz to /var/www/sites/domain.co.uk/extensions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xzf ConfirmAccount.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmAccount/ConfirmAccount.php&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file and run php maintenance/update.php&lt;br /&gt;
&lt;br /&gt;
To turn off &amp;quot;Your biography must be at least 50 words long.&amp;quot;, as this does not use $wgAccountRequestMinWords any more:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/www/sites/domain.co.uk/extensions/ConfirmAccount/ConfirmAccount.config.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&#039;Biography&#039;       =&amp;gt; array( &#039;enabled&#039; =&amp;gt; true, &#039;minWords&#039; =&amp;gt; 50 ),&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error when approving an account:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Could not create directory &amp;quot;mwstore://accountcreds-backend/accountcreds-public/1/12/123&amp;quot;.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chown www-data:www-data images/ -R&lt;br /&gt;
chmod 755 images/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also check your &amp;quot;$wgFileExtensions = {&#039;gif&#039;, &#039;png&#039;);&amp;quot; entry&lt;br /&gt;
&lt;br /&gt;
You may need to create an array, something like this:&lt;br /&gt;
&lt;br /&gt;
$wgFileExtensions = array(&#039;gif&#039;,&#039;png&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Capitalise headers and tab titles ===&lt;br /&gt;
&lt;br /&gt;
vim domain.co.uk/skins/monobook/main.css&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;.portlet h5 {&lt;br /&gt;
        background: transparent;&lt;br /&gt;
        padding: 0 1em 0 .5em;&lt;br /&gt;
        display: inline;&lt;br /&gt;
        height: 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        font-size: 91%;&lt;br /&gt;
        font-weight: normal;&lt;br /&gt;
        white-space: nowrap;&lt;br /&gt;
}&lt;br /&gt;
.portlet h6 {&lt;br /&gt;
        background: #ffae2e;&lt;br /&gt;
        border: 1px solid #2f6fab;&lt;br /&gt;
        border-style: solid solid none solid;&lt;br /&gt;
        padding: 0 1em 0 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        display: block;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-personal ul {&lt;br /&gt;
        text-transform: capitalize;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-cactions li a {&lt;br /&gt;
/*      text-transform: lowercase; */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit the Sidebar ===&lt;br /&gt;
&lt;br /&gt;
Go to http://domain.co.uk/wiki/MediaWiki:Sidebar&lt;br /&gt;
&lt;br /&gt;
=== Recaptcha installation ===&lt;br /&gt;
&lt;br /&gt;
First go [https://www.google.com/recaptcha/admin/create here] and obtain a public and private key for your wiki.&lt;br /&gt;
&lt;br /&gt;
Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmEdit/ReCaptcha.php&amp;quot;); &lt;br /&gt;
$wgCaptchaClass = &#039;ReCaptcha&#039;;&lt;br /&gt;
$wgReCaptchaPublicKey = &#039;your public key here&#039;;&lt;br /&gt;
$wgReCaptchaPrivateKey = &#039;your private key here&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Short URL configuration ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Short_URL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgScriptPath       = &amp;quot;&amp;quot;;&lt;br /&gt;
$wgArticlePath      = &#039;/wiki/$1&#039;;&lt;br /&gt;
$wgUsePathInfo      = true;&lt;br /&gt;
$wgScriptExtension  = &amp;quot;.php&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2enmod rewrite&lt;br /&gt;
/etc/init.d/apache2 restart&lt;br /&gt;
vim /etc/apache2/sites-available/domain.co.uk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;    RewriteEngine On&lt;br /&gt;
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2 [L,QSA,B]&lt;br /&gt;
&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2&amp;amp;archived=1 [L,QSA,B]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php: http://shorturls.redwerks.org&lt;br /&gt;
&lt;br /&gt;
== Old edited Special:AllMessages ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To help protect against automated page creation, please type the two words you see in the box below ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Migrating to a new server ==&lt;br /&gt;
&lt;br /&gt;
On the original server, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysqldump --default-character-set=binary --user=root databasename &amp;gt; dbdump.txt -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then copy all your content and the dbdump.txt file across to the new server. &lt;br /&gt;
&lt;br /&gt;
To delete a useless database, do this from within MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DROP DATABASE wikidb;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to create an empty database first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create database DatabaseName;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then on the new server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysql --silent --local DatabaseName &amp;lt; dbdump.txt -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;DatabaseUser&#039;@&#039;localhost&#039; identified by &#039;password&#039;;&lt;br /&gt;
GRANT ALL PRIVILEGES ON DatabaseName.* TO &#039;DatabaseUser&#039;@&#039;%&#039; IDENTIFIED BY &#039;password&#039; WITH GRANT OPTION ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your LocalSettings.php to ensure the following setting are correct:&lt;br /&gt;
&lt;br /&gt;
$wgDBtype           = &amp;quot;mysql&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBserver         = &amp;quot;localhost&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBname           = &amp;quot;DatabaseName&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBuser           = &amp;quot;DatabaseUser&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBpassword       = &amp;quot;DatabaseUserPassword*&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
== Lock down mw-config directory ==&lt;br /&gt;
&lt;br /&gt;
Access your install via command line, and set the permissions of the directory to restricted. On Linux, this is done like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 000 mw-config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sitemap ==&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ManualSitemap&lt;br /&gt;
&lt;br /&gt;
cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak&amp;lt;br&amp;gt;&lt;br /&gt;
vim maintenance/generateSitemap.php&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/User:Superxain/GenerateSitemap (from [http://www.mediawiki.org/wiki/Manual_talk:GenerateSitemap.php#A_BUG_FIX_to_work_the_Google_Webmaster_Tools here])&lt;br /&gt;
&lt;br /&gt;
== Spam accounts ==&lt;br /&gt;
&lt;br /&gt;
ServerKB over 4 years (2021 to 2025) had ~300,000 spam pages and ~20,000 spam accounts created.&lt;br /&gt;
These stats can easily be checked for your own MediaWiki via these pages:&lt;br /&gt;
Special:ListUsers&lt;br /&gt;
Special:Statistics&lt;br /&gt;
You will want to use these pages throughout your analysis and resolution to keep an eye on the numbers.&lt;br /&gt;
&lt;br /&gt;
First recommendation, upgrade MediaWiki to the latest version possible: https://www.mediawiki.org/wiki/Manual:Upgrading&lt;br /&gt;
As always, make a backup of your database before upgrading.&lt;br /&gt;
Make sure you read the deprecated LocalSettings.php options between updates as well as disabling extensions that are not supported or up to date then enabling them after the upgrade (if compatible).&lt;br /&gt;
&lt;br /&gt;
In the case of ServerKB, I upgraded from 1.36 up to 1.42 via 1.36 &amp;gt; 1.37 &amp;gt; 1.38 &amp;gt; 1.42&lt;br /&gt;
This did require downgrading PHP from 8.3 to 8.1.&lt;br /&gt;
&lt;br /&gt;
If at any time during this process you run php scripts e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/runJobs.php&lt;br /&gt;
php maintenance/run.php update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And get the following type of errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[4758ee24ec3e12702aba0fed] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/doMaintenance.php(83): require_once(string)&lt;br /&gt;
#2 maintenance/runJobs.php(136): require_once(string)&lt;br /&gt;
#3 {main}&lt;br /&gt;
&lt;br /&gt;
[026858f401e7f387106a367e] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/run.php(49): require_once(string)&lt;br /&gt;
#2 {main}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should comment out all extensions (from both wfload and require_once) in LocalSettings.php as these were how I resolved these issues with an old unsupported captcha extension.&lt;br /&gt;
&lt;br /&gt;
During the upgrades, you will need to run this command regularly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php update.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would recommend doing this with your web server (Apache) and database (MySQL) in a stopped state, as this allows you to correct any issues that halt the update/upgrade e.g. missing extensions, missing extension files, missing LocalSettings.php&lt;br /&gt;
&lt;br /&gt;
Note: Tools like  SmiteSpam, UserMerge did not work for me as they were either not supported on my version of MediaWiki, out of date, not supported any more or just didn&#039;t work. This guide seemed good but fell short as it didn&#039;t work for me: https://www.simplecloudworks.com/how-to-delete-a-long-list-of-spam-users-in-mediawiki/&lt;br /&gt;
&lt;br /&gt;
You will then want to utilise the following scripts via command line:&lt;br /&gt;
&lt;br /&gt;
=== Deleting multiple pages on mass ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Help:Extension:Nuke&lt;br /&gt;
&lt;br /&gt;
Nuke is best used when you haven&#039;t updated anything for over 30 days but the spammers have, but you can update LocalSettings.php to increase this check threshold:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgNukeMaxAge = &amp;lt;days&amp;gt; * 86400;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:DeleteBatch&lt;br /&gt;
&lt;br /&gt;
The best way to use DeleteBatch for &amp;quot;User&amp;quot; pages (User namespace) is to get the list of spam accounts either from the database user table (using user_name) or from Special:ListUsers 500 at a time, copying these into a notepad (to remove formatting), save the file, then open the file in Excel using the bracket symbol as the delimiter, find and replace where needed to remove text you don&#039;t want (e.g. talk contrib block)&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=CONCATENATE(&amp;quot;User:&amp;quot;, C1)&amp;quot; in Excel to add the prefix for removing user pages via DeleteBatch.&lt;br /&gt;
&lt;br /&gt;
You basically want to go from this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;MamieNewquist0  &amp;quot;&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;User:MamieNewquist0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=TRIM(A1)&amp;quot; in Excel to remove/strip spaces after usernames if needed.&lt;br /&gt;
For accounts that are just numbers, be careful when Excel auto-formats the cells with these account names as it can often strip numbers or convert them.&lt;br /&gt;
&lt;br /&gt;
Then you can call a long list of user pages from one text file like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteBatch /root/userpages.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting unused accounts ===&lt;br /&gt;
&lt;br /&gt;
Check your active users first via Special:ActiveUsers&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:RemoveUnusedAccounts.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php removeUnusedAccounts --delete --ignore-groups administrators,Administrators,administrator,bureaucrats&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this only works for accounts that have never made any edits or contributions INCLUDING deleted edits/contributions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting archived revisions ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:DeleteArchivedRevisions.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteArchivedRevisions --delete&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would also recommend running RemoveUnusedAccounts again after running DeleteArchivedRevisions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting accounts that made contributions/edits ===&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/600818/how-do-i-delete-all-non-confirmed-users-in-mediawiki&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; DELETE FROM user WHERE NOT user_name=&#039;&amp;lt;insert_your_admin_account_here&amp;gt;&#039;;&lt;br /&gt;
Query OK, 14536 rows affected (1.60 sec)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix statistics ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:InitSiteStats.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php initSiteStats --update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Follow up recommendations ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/User:Neoshinji#Prevent_spam_bots_from_registering&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual_talk:Combating_spam&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:Combating_spam#:~:text=Extension%3AAbuseFilter%20allows%20privileged%20users,links%20added%2C%20and%20so%20on.&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:ConfirmEdit#QuestyCaptcha&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134029</id>
		<title>MediaWiki</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134029"/>
		<updated>2025-01-03T21:32:34Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful areas for customisation are: /wiki/Special:AllMessages and [http://www.mediawiki.org/wiki/Manual:System_message#Built-in_system_messages   Built-in system messages]. You can normally just click the link from the list to edit the text.&lt;br /&gt;
&lt;br /&gt;
== Asynchronous snippet ==&lt;br /&gt;
&lt;br /&gt;
From [http://www.mediawiki.org/wiki/Extension_talk:Google_Analytics_Integration#How_to_set_the_new_asynchronous_snippet_before_the_head_tag_.28mw_.3C_1.17.29 here]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd extensions/googleAnalytics&lt;br /&gt;
cp googleAnalytics.php googleAnalytics.php.backup&lt;br /&gt;
vim googleAnalytics.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter the below text into the file and replace the UA- value below with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
if ( !defined( &#039;MEDIAWIKI&#039; ) ) {&lt;br /&gt;
        die( &#039;This file is a MediaWiki extension, it is not a valid entry point&#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$wgExtensionCredits[&#039;other&#039;][] = array(&lt;br /&gt;
        &#039;path&#039;           =&amp;gt; __FILE__,&lt;br /&gt;
        &#039;name&#039;           =&amp;gt; &#039;Google Analytics Integration&#039;,&lt;br /&gt;
        &#039;version&#039;        =&amp;gt; &#039;2.0.2&#039;,&lt;br /&gt;
        &#039;author&#039;         =&amp;gt; &#039;Tim Laqua&#039;,&lt;br /&gt;
        &#039;descriptionmsg&#039; =&amp;gt; &#039;googleanalytics-desc&#039;,&lt;br /&gt;
        &#039;url&#039;            =&amp;gt; &#039;http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration&#039;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$wgExtensionMessagesFiles[&#039;googleAnalytics&#039;] = dirname(__FILE__) . &#039;/googleAnalytics.i18n.php&#039;;&lt;br /&gt;
&lt;br /&gt;
$wgHooks[&#039;BeforePageDisplay&#039;][]  = &#039;efGoogleAnalyticsHookText&#039;;&lt;br /&gt;
$wgHooks[&#039;ParserAfterTidy&#039;][] = &#039;efGoogleAnalyticsASAC&#039;;&lt;br /&gt;
&lt;br /&gt;
# registered account&lt;br /&gt;
$wgGoogleAnalyticsAccount = &amp;quot;UA-XXXXX-X&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true&lt;br /&gt;
$wgGoogleAnalyticsAddASAC = false;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreSysops = true;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreBots = true;&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsASAC( &amp;amp;$parser, &amp;amp;$text ) {&lt;br /&gt;
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;&lt;br /&gt;
&lt;br /&gt;
        if( !empty($wgGoogleAnalyticsAccount) &amp;amp;&amp;amp; $wgGoogleAnalyticsAddASAC ) {&lt;br /&gt;
                $wgOut-&amp;gt;addScript(&#039;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;window.google_analytics_uacct = &amp;quot;&#039; . $wgGoogleAnalyticsAccount . &#039;&amp;quot;;&amp;lt;/script&amp;gt;&#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsHookText( $out ) {&lt;br /&gt;
        $out-&amp;gt;addScript( efAddGoogleAnalytics() );&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efAddGoogleAnalytics() {&lt;br /&gt;
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;&lt;br /&gt;
        if (!$wgUser-&amp;gt;isAllowed(&#039;bot&#039;) || !$wgGoogleAnalyticsIgnoreBots) {&lt;br /&gt;
                if (!$wgUser-&amp;gt;isAllowed(&#039;protect&#039;) || !$wgGoogleAnalyticsIgnoreSysops) {&lt;br /&gt;
                        if ( !empty($wgGoogleAnalyticsAccount) ) {&lt;br /&gt;
                                $funcOutput = &amp;lt;&amp;lt;&amp;lt;GASCRIPT&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
var _gaq = _gaq || [];&lt;br /&gt;
_gaq.push([&#039;_setAccount&#039;, &#039;$wgGoogleAnalyticsAccount&#039;]);&lt;br /&gt;
_gaq.push([&#039;_trackPageview&#039;]);&lt;br /&gt;
(function() {&lt;br /&gt;
var ga = document.createElement(&#039;script&#039;); ga.type = &#039;text/javascript&#039;; ga.async = true;&lt;br /&gt;
ga.src = (&#039;https:&#039; == document.location.protocol ? &#039;https://ssl&#039; : &#039;http://www&#039;) + &#039;.google-analytics.com/ga.js&#039;;&lt;br /&gt;
var s = document.getElementsByTagName(&#039;script&#039;)[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
GASCRIPT;&lt;br /&gt;
                        } else {&lt;br /&gt;
                                $funcOutput = &amp;quot;\n&amp;lt;!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --&amp;gt;&amp;quot;;&lt;br /&gt;
                        }&lt;br /&gt;
                } else {&lt;br /&gt;
                        $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for users with &#039;protect&#039; rights (I.E. sysops) --&amp;gt;&amp;quot;;&lt;br /&gt;
                }&lt;br /&gt;
        } else {&lt;br /&gt;
                $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for bots --&amp;gt;&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $funcOutput;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///Alias for efAddGoogleAnalytics - backwards compatibility.&lt;br /&gt;
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
On Unix Debian based (so Ubuntu as well), do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /var/www/sites/domain.co.uk&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz&lt;br /&gt;
tar xvzf mediawiki-*.tar.gz&lt;br /&gt;
cd mediawiki-1.20.2&lt;br /&gt;
mv mediawiki-1.20.2/* .&lt;br /&gt;
mv .gitreview .jshintignore .jshintrc ..&lt;br /&gt;
apt-get install mysql-server build-essential&lt;br /&gt;
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++&lt;br /&gt;
pecl install intl&lt;br /&gt;
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime&lt;br /&gt;
pecl install Memcache&lt;br /&gt;
pear install net_smtp&lt;br /&gt;
vim /etc/php5/apache2/php.ini # you need Apache installed first)&lt;br /&gt;
# as well as&lt;br /&gt;
vim /etc/php5/cli/php.ini&lt;br /&gt;
/Dynamic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;extension=intl.so&lt;br /&gt;
extension=memcache.so&lt;br /&gt;
memcache.hash_strategy=&amp;quot;consistent&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a caching software between APC and [http://www.gossamer-threads.com/lists/wiki/wikitech/127717?do=post_view_threaded#127717 xcache]. If you want APC, use [http://serverkb.co.uk/wiki/APC this]. If you want xcache, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install php5-xcache&lt;br /&gt;
memcached -u root -d -m 2048 -l 10.0.0.40 -p 11211&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/www/sites&lt;br /&gt;
chown root:root domain.co.uk/ -R&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
chmod 700 LocalSettings.php&lt;br /&gt;
apt-get install qmail&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will state:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;qmail will refuse to accept SMTP messages except to `hostname`.&lt;br /&gt;
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check this: http://www.mediawiki.org/wiki/Manual:Config_script&lt;br /&gt;
&lt;br /&gt;
And go to domain.co.uk/index.php and run through the configuration. Then download the LocalSettings.php file.&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Securing_database_passwords&lt;br /&gt;
&lt;br /&gt;
=== Account confirmation ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ConfirmAccount&lt;br /&gt;
&lt;br /&gt;
Upload the .tar.gz to /var/www/sites/domain.co.uk/extensions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xzf ConfirmAccount.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmAccount/ConfirmAccount.php&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file and run php maintenance/update.php&lt;br /&gt;
&lt;br /&gt;
To turn off &amp;quot;Your biography must be at least 50 words long.&amp;quot;, as this does not use $wgAccountRequestMinWords any more:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/www/sites/domain.co.uk/extensions/ConfirmAccount/ConfirmAccount.config.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&#039;Biography&#039;       =&amp;gt; array( &#039;enabled&#039; =&amp;gt; true, &#039;minWords&#039; =&amp;gt; 50 ),&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error when approving an account:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Could not create directory &amp;quot;mwstore://accountcreds-backend/accountcreds-public/1/12/123&amp;quot;.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chown www-data:www-data images/ -R&lt;br /&gt;
chmod 755 images/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also check your &amp;quot;$wgFileExtensions = {&#039;gif&#039;, &#039;png&#039;);&amp;quot; entry&lt;br /&gt;
&lt;br /&gt;
You may need to create an array, something like this:&lt;br /&gt;
&lt;br /&gt;
$wgFileExtensions = array(&#039;gif&#039;,&#039;png&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Capitalise headers and tab titles ===&lt;br /&gt;
&lt;br /&gt;
vim domain.co.uk/skins/monobook/main.css&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;.portlet h5 {&lt;br /&gt;
        background: transparent;&lt;br /&gt;
        padding: 0 1em 0 .5em;&lt;br /&gt;
        display: inline;&lt;br /&gt;
        height: 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        font-size: 91%;&lt;br /&gt;
        font-weight: normal;&lt;br /&gt;
        white-space: nowrap;&lt;br /&gt;
}&lt;br /&gt;
.portlet h6 {&lt;br /&gt;
        background: #ffae2e;&lt;br /&gt;
        border: 1px solid #2f6fab;&lt;br /&gt;
        border-style: solid solid none solid;&lt;br /&gt;
        padding: 0 1em 0 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        display: block;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-personal ul {&lt;br /&gt;
        text-transform: capitalize;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-cactions li a {&lt;br /&gt;
/*      text-transform: lowercase; */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit the Sidebar ===&lt;br /&gt;
&lt;br /&gt;
Go to http://domain.co.uk/wiki/MediaWiki:Sidebar&lt;br /&gt;
&lt;br /&gt;
=== Recaptcha installation ===&lt;br /&gt;
&lt;br /&gt;
First go [https://www.google.com/recaptcha/admin/create here] and obtain a public and private key for your wiki.&lt;br /&gt;
&lt;br /&gt;
Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmEdit/ReCaptcha.php&amp;quot;); &lt;br /&gt;
$wgCaptchaClass = &#039;ReCaptcha&#039;;&lt;br /&gt;
$wgReCaptchaPublicKey = &#039;your public key here&#039;;&lt;br /&gt;
$wgReCaptchaPrivateKey = &#039;your private key here&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Short URL configuration ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Short_URL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgScriptPath       = &amp;quot;&amp;quot;;&lt;br /&gt;
$wgArticlePath      = &#039;/wiki/$1&#039;;&lt;br /&gt;
$wgUsePathInfo      = true;&lt;br /&gt;
$wgScriptExtension  = &amp;quot;.php&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2enmod rewrite&lt;br /&gt;
/etc/init.d/apache2 restart&lt;br /&gt;
vim /etc/apache2/sites-available/domain.co.uk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;    RewriteEngine On&lt;br /&gt;
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2 [L,QSA,B]&lt;br /&gt;
&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2&amp;amp;archived=1 [L,QSA,B]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php: http://shorturls.redwerks.org&lt;br /&gt;
&lt;br /&gt;
== Old edited Special:AllMessages ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To help protect against automated page creation, please type the two words you see in the box below ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Migrating to a new server ==&lt;br /&gt;
&lt;br /&gt;
On the original server, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysqldump --default-character-set=binary --user=root databasename &amp;gt; dbdump.txt -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then copy all your content and the dbdump.txt file across to the new server. &lt;br /&gt;
&lt;br /&gt;
To delete a useless database, do this from within MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DROP DATABASE wikidb;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to create an empty database first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create database DatabaseName;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then on the new server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysql --silent --local DatabaseName &amp;lt; dbdump.txt -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;DatabaseUser&#039;@&#039;localhost&#039; identified by &#039;password&#039;;&lt;br /&gt;
GRANT ALL PRIVILEGES ON DatabaseName.* TO &#039;DatabaseUser&#039;@&#039;%&#039; IDENTIFIED BY &#039;password&#039; WITH GRANT OPTION ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your LocalSettings.php to ensure the following setting are correct:&lt;br /&gt;
&lt;br /&gt;
$wgDBtype           = &amp;quot;mysql&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBserver         = &amp;quot;localhost&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBname           = &amp;quot;DatabaseName&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBuser           = &amp;quot;DatabaseUser&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBpassword       = &amp;quot;DatabaseUserPassword*&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
== Lock down mw-config directory ==&lt;br /&gt;
&lt;br /&gt;
Access your install via command line, and set the permissions of the directory to restricted. On Linux, this is done like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 000 mw-config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sitemap ==&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ManualSitemap&lt;br /&gt;
&lt;br /&gt;
cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak&amp;lt;br&amp;gt;&lt;br /&gt;
vim maintenance/generateSitemap.php&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/User:Superxain/GenerateSitemap (from [http://www.mediawiki.org/wiki/Manual_talk:GenerateSitemap.php#A_BUG_FIX_to_work_the_Google_Webmaster_Tools here])&lt;br /&gt;
&lt;br /&gt;
== Spam accounts ==&lt;br /&gt;
&lt;br /&gt;
ServerKB over 4 years (2021 to 2025) had ~300,000 spam pages and ~20,000 spam accounts created.&lt;br /&gt;
These stats can easily be checked for your own MediaWiki via these pages:&lt;br /&gt;
Special:ListUsers&lt;br /&gt;
Special:Statistics&lt;br /&gt;
You will want to use these pages throughout your analysis and resolution to keep an eye on the numbers.&lt;br /&gt;
&lt;br /&gt;
First recommendation, upgrade MediaWiki to the latest version possible: https://www.mediawiki.org/wiki/Manual:Upgrading&lt;br /&gt;
As always, make a backup of your database before upgrading.&lt;br /&gt;
Make sure you read the deprecated LocalSettings.php options between updates as well as disabling extensions that are not supported or up to date then enabling them after the upgrade (if compatible).&lt;br /&gt;
&lt;br /&gt;
In the case of ServerKB, I upgraded from 1.36 up to 1.42 via 1.36 &amp;gt; 1.37 &amp;gt; 1.38 &amp;gt; 1.42&lt;br /&gt;
This did require downgrading PHP from 8.3 to 8.1.&lt;br /&gt;
&lt;br /&gt;
If at any time during this process you run php scripts e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/runJobs.php&lt;br /&gt;
php maintenance/run.php update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And get the following type of errors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[4758ee24ec3e12702aba0fed] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/doMaintenance.php(83): require_once(string)&lt;br /&gt;
#2 maintenance/runJobs.php(136): require_once(string)&lt;br /&gt;
#3 {main}&lt;br /&gt;
&lt;br /&gt;
[026858f401e7f387106a367e] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/run.php(49): require_once(string)&lt;br /&gt;
#2 {main}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should comment out all extensions (from both wfload and require_once) in LocalSettings.php as these were how I resolved these issues with an old unsupported captcha extension.&lt;br /&gt;
&lt;br /&gt;
During the upgrades, you will need to run &amp;quot; php update.php&amp;quot; regularly. I would recommend doing this with your web server (Apache) and database (MySQL) in a stopped state, as this allows you to correct any issues that halt the update/upgrade e.g. missing extensions, missing extension files, missing LocalSettings.php&lt;br /&gt;
&lt;br /&gt;
Note: Tools like  SmiteSpam, UserMerge did not work for me as they were either not supported on my version of MediaWiki, out of date, not supported any more or just didn&#039;t work. This guide seemed good but fell short as it didn&#039;t work for me: https://www.simplecloudworks.com/how-to-delete-a-long-list-of-spam-users-in-mediawiki/&lt;br /&gt;
&lt;br /&gt;
You will then want to utilise the following scripts via command line:&lt;br /&gt;
&lt;br /&gt;
=== Deleting multiple pages on mass ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Help:Extension:Nuke&lt;br /&gt;
&lt;br /&gt;
Nuke is best used when you haven&#039;t updated anything for over 30 days but the spammers have, but you can update LocalSettings.php to increase this check threshold:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgNukeMaxAge = &amp;lt;days&amp;gt; * 86400;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:DeleteBatch&lt;br /&gt;
&lt;br /&gt;
The best way to use DeleteBatch for &amp;quot;User&amp;quot; pages (User namespace) is to get the list of spam accounts either from the database user table (using user_name) or from Special:ListUsers 500 at a time, copying these into a notepad (to remove formatting), save the file, then open the file in Excel using the bracket symbol as the delimiter, find and replace where needed to remove text you don&#039;t want (e.g. talk contrib block)&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=CONCATENATE(&amp;quot;User:&amp;quot;, C1)&amp;quot; in Excel to add the prefix for removing user pages via DeleteBatch.&lt;br /&gt;
&lt;br /&gt;
You basically want to go from this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;MamieNewquist0  &amp;quot;&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;User:MamieNewquist0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=TRIM(A1)&amp;quot; in Excel to remove/strip spaces after usernames if needed.&lt;br /&gt;
For accounts that are just numbers, be careful when Excel auto-formats the cells with these account names as it can often strip numbers or convert them.&lt;br /&gt;
&lt;br /&gt;
Then you can call a long list of user pages from one text file like so:&lt;br /&gt;
&lt;br /&gt;
php maintenance/run.php deleteBatch /root/userpages.txt&lt;br /&gt;
&lt;br /&gt;
=== Deleting unused accounts ===&lt;br /&gt;
&lt;br /&gt;
Check your active users first via Special:ActiveUsers&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:RemoveUnusedAccounts.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php removeUnusedAccounts --delete --ignore-groups administrators,Administrators,administrator,bureaucrats&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: this only works for accounts that have never made any edits or contributions INCLUDING deleted edits/contributions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting archived revisions ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:DeleteArchivedRevisions.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php deleteArchivedRevisions --delete&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would also recommend running RemoveUnusedAccounts again after running DeleteArchivedRevisions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting accounts that made contributions/edits ===&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/600818/how-do-i-delete-all-non-confirmed-users-in-mediawiki&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; DELETE FROM user WHERE NOT user_name=&#039;&amp;lt;insert_your_admin_account_here&amp;gt;&#039;;&lt;br /&gt;
Query OK, 14536 rows affected (1.60 sec)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix statistics ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:InitSiteStats.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;php maintenance/run.php initSiteStats --update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Follow up recommendations ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/User:Neoshinji#Prevent_spam_bots_from_registering&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual_talk:Combating_spam&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:Combating_spam#:~:text=Extension%3AAbuseFilter%20allows%20privileged%20users,links%20added%2C%20and%20so%20on.&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:ConfirmEdit#QuestyCaptcha&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134028</id>
		<title>MediaWiki</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MediaWiki&amp;diff=134028"/>
		<updated>2025-01-03T21:30:57Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful areas for customisation are: /wiki/Special:AllMessages and [http://www.mediawiki.org/wiki/Manual:System_message#Built-in_system_messages   Built-in system messages]. You can normally just click the link from the list to edit the text.&lt;br /&gt;
&lt;br /&gt;
== Asynchronous snippet ==&lt;br /&gt;
&lt;br /&gt;
From [http://www.mediawiki.org/wiki/Extension_talk:Google_Analytics_Integration#How_to_set_the_new_asynchronous_snippet_before_the_head_tag_.28mw_.3C_1.17.29 here]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd extensions/googleAnalytics&lt;br /&gt;
cp googleAnalytics.php googleAnalytics.php.backup&lt;br /&gt;
vim googleAnalytics.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter the below text into the file and replace the UA- value below with your own.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
if ( !defined( &#039;MEDIAWIKI&#039; ) ) {&lt;br /&gt;
        die( &#039;This file is a MediaWiki extension, it is not a valid entry point&#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$wgExtensionCredits[&#039;other&#039;][] = array(&lt;br /&gt;
        &#039;path&#039;           =&amp;gt; __FILE__,&lt;br /&gt;
        &#039;name&#039;           =&amp;gt; &#039;Google Analytics Integration&#039;,&lt;br /&gt;
        &#039;version&#039;        =&amp;gt; &#039;2.0.2&#039;,&lt;br /&gt;
        &#039;author&#039;         =&amp;gt; &#039;Tim Laqua&#039;,&lt;br /&gt;
        &#039;descriptionmsg&#039; =&amp;gt; &#039;googleanalytics-desc&#039;,&lt;br /&gt;
        &#039;url&#039;            =&amp;gt; &#039;http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration&#039;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$wgExtensionMessagesFiles[&#039;googleAnalytics&#039;] = dirname(__FILE__) . &#039;/googleAnalytics.i18n.php&#039;;&lt;br /&gt;
&lt;br /&gt;
$wgHooks[&#039;BeforePageDisplay&#039;][]  = &#039;efGoogleAnalyticsHookText&#039;;&lt;br /&gt;
$wgHooks[&#039;ParserAfterTidy&#039;][] = &#039;efGoogleAnalyticsASAC&#039;;&lt;br /&gt;
&lt;br /&gt;
# registered account&lt;br /&gt;
$wgGoogleAnalyticsAccount = &amp;quot;UA-XXXXX-X&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true&lt;br /&gt;
$wgGoogleAnalyticsAddASAC = false;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreSysops = true;&lt;br /&gt;
$wgGoogleAnalyticsIgnoreBots = true;&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsASAC( &amp;amp;$parser, &amp;amp;$text ) {&lt;br /&gt;
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;&lt;br /&gt;
&lt;br /&gt;
        if( !empty($wgGoogleAnalyticsAccount) &amp;amp;&amp;amp; $wgGoogleAnalyticsAddASAC ) {&lt;br /&gt;
                $wgOut-&amp;gt;addScript(&#039;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;window.google_analytics_uacct = &amp;quot;&#039; . $wgGoogleAnalyticsAccount . &#039;&amp;quot;;&amp;lt;/script&amp;gt;&#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efGoogleAnalyticsHookText( $out ) {&lt;br /&gt;
        $out-&amp;gt;addScript( efAddGoogleAnalytics() );&lt;br /&gt;
        return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function efAddGoogleAnalytics() {&lt;br /&gt;
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;&lt;br /&gt;
        if (!$wgUser-&amp;gt;isAllowed(&#039;bot&#039;) || !$wgGoogleAnalyticsIgnoreBots) {&lt;br /&gt;
                if (!$wgUser-&amp;gt;isAllowed(&#039;protect&#039;) || !$wgGoogleAnalyticsIgnoreSysops) {&lt;br /&gt;
                        if ( !empty($wgGoogleAnalyticsAccount) ) {&lt;br /&gt;
                                $funcOutput = &amp;lt;&amp;lt;&amp;lt;GASCRIPT&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
var _gaq = _gaq || [];&lt;br /&gt;
_gaq.push([&#039;_setAccount&#039;, &#039;$wgGoogleAnalyticsAccount&#039;]);&lt;br /&gt;
_gaq.push([&#039;_trackPageview&#039;]);&lt;br /&gt;
(function() {&lt;br /&gt;
var ga = document.createElement(&#039;script&#039;); ga.type = &#039;text/javascript&#039;; ga.async = true;&lt;br /&gt;
ga.src = (&#039;https:&#039; == document.location.protocol ? &#039;https://ssl&#039; : &#039;http://www&#039;) + &#039;.google-analytics.com/ga.js&#039;;&lt;br /&gt;
var s = document.getElementsByTagName(&#039;script&#039;)[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
GASCRIPT;&lt;br /&gt;
                        } else {&lt;br /&gt;
                                $funcOutput = &amp;quot;\n&amp;lt;!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. --&amp;gt;&amp;quot;;&lt;br /&gt;
                        }&lt;br /&gt;
                } else {&lt;br /&gt;
                        $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for users with &#039;protect&#039; rights (I.E. sysops) --&amp;gt;&amp;quot;;&lt;br /&gt;
                }&lt;br /&gt;
        } else {&lt;br /&gt;
                $funcOutput = &amp;quot;\n&amp;lt;!-- Google Analytics tracking is disabled for bots --&amp;gt;&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return $funcOutput;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///Alias for efAddGoogleAnalytics - backwards compatibility.&lt;br /&gt;
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
On Unix Debian based (so Ubuntu as well), do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /var/www/sites/domain.co.uk&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
wget http://download.wikimedia.org/mediawiki/1.20/mediawiki-1.20.2.tar.gz&lt;br /&gt;
tar xvzf mediawiki-*.tar.gz&lt;br /&gt;
cd mediawiki-1.20.2&lt;br /&gt;
mv mediawiki-1.20.2/* .&lt;br /&gt;
mv .gitreview .jshintignore .jshintrc ..&lt;br /&gt;
apt-get install mysql-server build-essential&lt;br /&gt;
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++&lt;br /&gt;
pecl install intl&lt;br /&gt;
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime&lt;br /&gt;
pecl install Memcache&lt;br /&gt;
pear install net_smtp&lt;br /&gt;
vim /etc/php5/apache2/php.ini # you need Apache installed first)&lt;br /&gt;
# as well as&lt;br /&gt;
vim /etc/php5/cli/php.ini&lt;br /&gt;
/Dynamic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;extension=intl.so&lt;br /&gt;
extension=memcache.so&lt;br /&gt;
memcache.hash_strategy=&amp;quot;consistent&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a caching software between APC and [http://www.gossamer-threads.com/lists/wiki/wikitech/127717?do=post_view_threaded#127717 xcache]. If you want APC, use [http://serverkb.co.uk/wiki/APC this]. If you want xcache, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install php5-xcache&lt;br /&gt;
memcached -u root -d -m 2048 -l 10.0.0.40 -p 11211&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/www/sites&lt;br /&gt;
chown root:root domain.co.uk/ -R&lt;br /&gt;
cd /var/www/sites/domain.co.uk&lt;br /&gt;
chmod 700 LocalSettings.php&lt;br /&gt;
apt-get install qmail&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will state:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;qmail will refuse to accept SMTP messages except to `hostname`.&lt;br /&gt;
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check this: http://www.mediawiki.org/wiki/Manual:Config_script&lt;br /&gt;
&lt;br /&gt;
And go to domain.co.uk/index.php and run through the configuration. Then download the LocalSettings.php file.&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Securing_database_passwords&lt;br /&gt;
&lt;br /&gt;
=== Account confirmation ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ConfirmAccount&lt;br /&gt;
&lt;br /&gt;
Upload the .tar.gz to /var/www/sites/domain.co.uk/extensions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xzf ConfirmAccount.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmAccount/ConfirmAccount.php&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file and run php maintenance/update.php&lt;br /&gt;
&lt;br /&gt;
To turn off &amp;quot;Your biography must be at least 50 words long.&amp;quot;, as this does not use $wgAccountRequestMinWords any more:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/www/sites/domain.co.uk/extensions/ConfirmAccount/ConfirmAccount.config.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&#039;Biography&#039;       =&amp;gt; array( &#039;enabled&#039; =&amp;gt; true, &#039;minWords&#039; =&amp;gt; 50 ),&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error when approving an account:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Could not create directory &amp;quot;mwstore://accountcreds-backend/accountcreds-public/1/12/123&amp;quot;.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chown www-data:www-data images/ -R&lt;br /&gt;
chmod 755 images/ -R&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also check your &amp;quot;$wgFileExtensions = {&#039;gif&#039;, &#039;png&#039;);&amp;quot; entry&lt;br /&gt;
&lt;br /&gt;
You may need to create an array, something like this:&lt;br /&gt;
&lt;br /&gt;
$wgFileExtensions = array(&#039;gif&#039;,&#039;png&#039;);&lt;br /&gt;
&lt;br /&gt;
=== Capitalise headers and tab titles ===&lt;br /&gt;
&lt;br /&gt;
vim domain.co.uk/skins/monobook/main.css&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;.portlet h5 {&lt;br /&gt;
        background: transparent;&lt;br /&gt;
        padding: 0 1em 0 .5em;&lt;br /&gt;
        display: inline;&lt;br /&gt;
        height: 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        font-size: 91%;&lt;br /&gt;
        font-weight: normal;&lt;br /&gt;
        white-space: nowrap;&lt;br /&gt;
}&lt;br /&gt;
.portlet h6 {&lt;br /&gt;
        background: #ffae2e;&lt;br /&gt;
        border: 1px solid #2f6fab;&lt;br /&gt;
        border-style: solid solid none solid;&lt;br /&gt;
        padding: 0 1em 0 1em;&lt;br /&gt;
/*      text-transform: lowercase; /* force text to lowercase */&lt;br /&gt;
/*      text-transform: uppercase; /* force text to uppercase */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
        display: block;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-personal ul {&lt;br /&gt;
        text-transform: capitalize;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#p-cactions li a {&lt;br /&gt;
/*      text-transform: lowercase; */&lt;br /&gt;
        text-transform: capitalize; /* force text to proper case */&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit the Sidebar ===&lt;br /&gt;
&lt;br /&gt;
Go to http://domain.co.uk/wiki/MediaWiki:Sidebar&lt;br /&gt;
&lt;br /&gt;
=== Recaptcha installation ===&lt;br /&gt;
&lt;br /&gt;
First go [https://www.google.com/recaptcha/admin/create here] and obtain a public and private key for your wiki.&lt;br /&gt;
&lt;br /&gt;
Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;require_once(&amp;quot;$IP/extensions/ConfirmEdit/ReCaptcha.php&amp;quot;); &lt;br /&gt;
$wgCaptchaClass = &#039;ReCaptcha&#039;;&lt;br /&gt;
$wgReCaptchaPublicKey = &#039;your public key here&#039;;&lt;br /&gt;
$wgReCaptchaPrivateKey = &#039;your private key here&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Short URL configuration ===&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Manual:Short_URL&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim LocalSettings.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$wgScriptPath       = &amp;quot;&amp;quot;;&lt;br /&gt;
$wgArticlePath      = &#039;/wiki/$1&#039;;&lt;br /&gt;
$wgUsePathInfo      = true;&lt;br /&gt;
$wgScriptExtension  = &amp;quot;.php&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2enmod rewrite&lt;br /&gt;
/etc/init.d/apache2 restart&lt;br /&gt;
vim /etc/apache2/sites-available/domain.co.uk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;    RewriteEngine On&lt;br /&gt;
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2 [L,QSA,B]&lt;br /&gt;
&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f&lt;br /&gt;
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d&lt;br /&gt;
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&amp;amp;width=$2&amp;amp;archived=1 [L,QSA,B]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php: http://shorturls.redwerks.org&lt;br /&gt;
&lt;br /&gt;
== Old edited Special:AllMessages ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;To help protect against automated page creation, please type the two words you see in the box below ([[Special:Captcha/help|more info]]):&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Migrating to a new server ==&lt;br /&gt;
&lt;br /&gt;
On the original server, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysqldump --default-character-set=binary --user=root databasename &amp;gt; dbdump.txt -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then copy all your content and the dbdump.txt file across to the new server. &lt;br /&gt;
&lt;br /&gt;
To delete a useless database, do this from within MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DROP DATABASE wikidb;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to create an empty database first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create database DatabaseName;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then on the new server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&lt;br /&gt;
or&lt;br /&gt;
mysql --silent --local DatabaseName &amp;lt; dbdump.txt -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;DatabaseUser&#039;@&#039;localhost&#039; identified by &#039;password&#039;;&lt;br /&gt;
GRANT ALL PRIVILEGES ON DatabaseName.* TO &#039;DatabaseUser&#039;@&#039;%&#039; IDENTIFIED BY &#039;password&#039; WITH GRANT OPTION ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your LocalSettings.php to ensure the following setting are correct:&lt;br /&gt;
&lt;br /&gt;
$wgDBtype           = &amp;quot;mysql&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBserver         = &amp;quot;localhost&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBname           = &amp;quot;DatabaseName&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBuser           = &amp;quot;DatabaseUser&amp;quot;;&amp;lt;br&amp;gt;&lt;br /&gt;
$wgDBpassword       = &amp;quot;DatabaseUserPassword*&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
== Lock down mw-config directory ==&lt;br /&gt;
&lt;br /&gt;
Access your install via command line, and set the permissions of the directory to restricted. On Linux, this is done like so:&lt;br /&gt;
&lt;br /&gt;
chmod 000 mw-config&lt;br /&gt;
&lt;br /&gt;
== Sitemap ==&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/Extension:ManualSitemap&lt;br /&gt;
&lt;br /&gt;
cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak&amp;lt;br&amp;gt;&lt;br /&gt;
vim maintenance/generateSitemap.php&lt;br /&gt;
&lt;br /&gt;
http://www.mediawiki.org/wiki/User:Superxain/GenerateSitemap (from [http://www.mediawiki.org/wiki/Manual_talk:GenerateSitemap.php#A_BUG_FIX_to_work_the_Google_Webmaster_Tools here])&lt;br /&gt;
&lt;br /&gt;
== Spam accounts ==&lt;br /&gt;
&lt;br /&gt;
ServerKB over 4 years (2021 to 2025) had ~300,000 spam pages and ~20,000 spam accounts created.&lt;br /&gt;
These stats can easily be checked for your own MediaWiki via these pages:&lt;br /&gt;
Special:ListUsers&lt;br /&gt;
Special:Statistics&lt;br /&gt;
You will want to use these pages throughout your analysis and resolution to keep an eye on the numbers.&lt;br /&gt;
&lt;br /&gt;
First recommendation, upgrade MediaWiki to the latest version possible: https://www.mediawiki.org/wiki/Manual:Upgrading&lt;br /&gt;
As always, make a backup of your database before upgrading.&lt;br /&gt;
Make sure you read the deprecated LocalSettings.php options between updates as well as disabling extensions that are not supported or up to date then enabling them after the upgrade (if compatible).&lt;br /&gt;
&lt;br /&gt;
In the case of ServerKB, I upgraded from 1.36 up to 1.42 via 1.36 &amp;gt; 1.37 &amp;gt; 1.38 &amp;gt; 1.42&lt;br /&gt;
This did require downgrading PHP from 8.3 to 8.1.&lt;br /&gt;
&lt;br /&gt;
If at any time during this process you run php scripts e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;php maintenance/runJobs.php&amp;quot;&lt;br /&gt;
&amp;quot;php maintenance/run.php update&amp;quot;&lt;br /&gt;
&lt;br /&gt;
And get the following type of errors:&lt;br /&gt;
&lt;br /&gt;
[4758ee24ec3e12702aba0fed] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/doMaintenance.php(83): require_once(string)&lt;br /&gt;
#2 maintenance/runJobs.php(136): require_once(string)&lt;br /&gt;
#3 {main}&lt;br /&gt;
&lt;br /&gt;
[026858f401e7f387106a367e] [no req]   Error: Call to a member function setHook() on null&lt;br /&gt;
Backtrace:&lt;br /&gt;
from extensions/analytics.php(23)&lt;br /&gt;
#0 includes/Setup.php(571): wfAnalytics()&lt;br /&gt;
#1 maintenance/run.php(49): require_once(string)&lt;br /&gt;
#2 {main}&lt;br /&gt;
&lt;br /&gt;
You should comment out all extensions (from both wfload and require_once) in LocalSettings.php as these were how I resolved these issues with an old unsupported captcha extension.&lt;br /&gt;
&lt;br /&gt;
During the upgrades, you will need to run &amp;quot; php update.php&amp;quot; regularly. I would recommend doing this with your web server (Apache) and database (MySQL) in a stopped state, as this allows you to correct any issues that halt the update/upgrade e.g. missing extensions, missing extension files, missing LocalSettings.php&lt;br /&gt;
&lt;br /&gt;
Note: Tools like  SmiteSpam, UserMerge did not work for me as they were either not supported on my version of MediaWiki, out of date, not supported any more or just didn&#039;t work. This guide seemed good but fell short as it didn&#039;t work for me: https://www.simplecloudworks.com/how-to-delete-a-long-list-of-spam-users-in-mediawiki/&lt;br /&gt;
&lt;br /&gt;
You will then want to utilise the following scripts via command line:&lt;br /&gt;
&lt;br /&gt;
=== Deleting multiple pages on mass ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Help:Extension:Nuke&lt;br /&gt;
&lt;br /&gt;
Nuke is best used when you haven&#039;t updated anything for over 30 days but the spammers have, but you can update LocalSettings.php to increase this check threshold:&lt;br /&gt;
&lt;br /&gt;
$wgNukeMaxAge = &amp;lt;days&amp;gt; * 86400;&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:DeleteBatch&lt;br /&gt;
&lt;br /&gt;
The best way to use DeleteBatch for &amp;quot;User&amp;quot; pages (User namespace) is to get the list of spam accounts either from the database user table (using user_name) or from Special:ListUsers 500 at a time, copying these into a notepad (to remove formatting), save the file, then open the file in Excel using the bracket symbol as the delimiter, find and replace where needed to remove text you don&#039;t want (e.g. talk contrib block)&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=CONCATENATE(&amp;quot;User:&amp;quot;, C1)&amp;quot; in Excel to add the prefix for removing user pages via DeleteBatch.&lt;br /&gt;
&lt;br /&gt;
You basically want to go from this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;MamieNewquist0  &amp;quot;&lt;br /&gt;
&lt;br /&gt;
to this:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;User:MamieNewquist0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;=TRIM(A1)&amp;quot; in Excel to remove/strip spaces after usernames if needed.&lt;br /&gt;
For accounts that are just numbers, be careful when Excel auto-formats the cells with these account names as it can often strip numbers or convert them.&lt;br /&gt;
&lt;br /&gt;
Then you can call a long list of user pages from one text file like so:&lt;br /&gt;
&lt;br /&gt;
php maintenance/run.php deleteBatch /root/userpages.txt&lt;br /&gt;
&lt;br /&gt;
=== Deleting unused accounts ===&lt;br /&gt;
&lt;br /&gt;
Check your active users first via Special:ActiveUsers&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:RemoveUnusedAccounts.php&lt;br /&gt;
&lt;br /&gt;
php maintenance/run.php removeUnusedAccounts --delete --ignore-groups administrators,Administrators,administrator,bureaucrats&lt;br /&gt;
&lt;br /&gt;
Note: this only works for accounts that have never made any edits or contributions INCLUDING deleted edits/contributions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting archived revisions ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:DeleteArchivedRevisions.php&lt;br /&gt;
&lt;br /&gt;
php maintenance/run.php deleteArchivedRevisions --delete&lt;br /&gt;
&lt;br /&gt;
I would also recommend running RemoveUnusedAccounts again after running DeleteArchivedRevisions.&lt;br /&gt;
&lt;br /&gt;
=== Deleting accounts that made contributions/edits ===&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/600818/how-do-i-delete-all-non-confirmed-users-in-mediawiki&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; DELETE FROM user WHERE NOT user_name=&#039;&amp;lt;insert_your_admin_account_here&amp;gt;&#039;;&lt;br /&gt;
Query OK, 14536 rows affected (1.60 sec)&lt;br /&gt;
&lt;br /&gt;
=== Fix statistics ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:InitSiteStats.php&lt;br /&gt;
&lt;br /&gt;
php maintenance/run.php initSiteStats --update&lt;br /&gt;
&lt;br /&gt;
=== Follow up recommendations ===&lt;br /&gt;
&lt;br /&gt;
https://www.mediawiki.org/wiki/User:Neoshinji#Prevent_spam_bots_from_registering&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual_talk:Combating_spam&lt;br /&gt;
https://www.mediawiki.org/wiki/Manual:Combating_spam#:~:text=Extension%3AAbuseFilter%20allows%20privileged%20users,links%20added%2C%20and%20so%20on.&lt;br /&gt;
https://www.mediawiki.org/wiki/Extension:ConfirmEdit#QuestyCaptcha&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=User_talk:SPAMUSER2025&amp;diff=134025</id>
		<title>User talk:SPAMUSER2025</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=User_talk:SPAMUSER2025&amp;diff=134025"/>
		<updated>2025-01-02T22:55:47Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: Rootadminacc moved page User talk:%login% to User talk:SPAMUSER2025 without leaving a redirect: Automatically moved page while renaming the user &amp;quot;%login%&amp;quot; to &amp;quot;SPAMUSER2025&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;%About_Yourself%&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=1142</id>
		<title>Minecraft</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=1142"/>
		<updated>2020-04-06T15:33:06Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Server host/IP: mc.bywatercraft.co.uk / 188.165.120.188&amp;lt;br&amp;gt;&lt;br /&gt;
Website name: bywatercraft.co.uk -/&amp;gt; bywatercraft.com&lt;br /&gt;
&lt;br /&gt;
Currently the Bywater Craft Minecraft server is running Spigot 1.8.8. We have now updated the plugins to be compatible with 1.8.7.&lt;br /&gt;
&lt;br /&gt;
Load Minecraft:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/usr/bin/java -Djline.terminal=jline.UnsupportedTerminal -client -Xmx7132M -jar spigot.jar nogui -d yyyy-MM-dd HH:mm:ss -nojline&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n minecraft&lt;br /&gt;
cd /home/user&lt;br /&gt;
./MCMA2_Linux_x86_64 | tee yourminecraft.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to connect from elsewhere to view the above output/console load the screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh user@localhost -pXXXX&lt;br /&gt;
tmux ls&lt;br /&gt;
tmux attach 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To kill the process on boot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps -ef | grep tmux | grep -v grep | awk &#039;{print $2}&#039; | xargs kill -9&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using CTRL + D will quit screen and close any processes running within it.&amp;lt;br&amp;gt;&lt;br /&gt;
To exit safely do CTRL + B, let go, then press D on it&#039;s own. &lt;br /&gt;
&lt;br /&gt;
When downloading a backup from McMyAdmin, it comes in the mcb format. Change it to .zip and you can then unzip it into a folder and restore to the server.&lt;br /&gt;
&lt;br /&gt;
== Allowing PvP ==&lt;br /&gt;
&lt;br /&gt;
Personally, for WorldGuard&#039;s pvp flag to work we had to ensure:&lt;br /&gt;
&lt;br /&gt;
* Essentials plugin had pvp = true&lt;br /&gt;
* McMyAdmin control panel had Configuration &amp;gt; Game Settings &amp;gt; Allow Player vs Player combat&lt;br /&gt;
* server.properties file had pvp = true&lt;br /&gt;
* WorldGuard had __global__ set to pvp deny&lt;br /&gt;
* WorldGuard then could have specific regions set to pvp allow&lt;br /&gt;
&lt;br /&gt;
== Backpack ==&lt;br /&gt;
&lt;br /&gt;
Reduce/downgrade Backpack space:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /Minecraft/plugins/Backpack/backpacks/world&lt;br /&gt;
ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the value next to &amp;quot;contents-amount:&amp;quot; in the user&#039;s .yml file.&lt;br /&gt;
&lt;br /&gt;
== Bungeecord ==&lt;br /&gt;
&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord/&amp;lt;br&amp;gt;&lt;br /&gt;
https://www.spigotmc.org/wiki/bungeecord-configuration-guide/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord-installation/#installing-bungeecord-on-linux&lt;br /&gt;
&lt;br /&gt;
To end Bungeecord script, type end and hit enter.&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=0ViRZPLuBiA How to use and install BungeeCord]&lt;br /&gt;
&lt;br /&gt;
== Buycraft ==&lt;br /&gt;
&lt;br /&gt;
=== Edit Store welcome page ===&lt;br /&gt;
&lt;br /&gt;
Webstore &amp;gt; General settings &amp;gt; Homepage description&lt;br /&gt;
&lt;br /&gt;
== Chat ==&lt;br /&gt;
&lt;br /&gt;
/tell PlayerName will whisper a message to a player. This option will not show in a console.&lt;br /&gt;
&lt;br /&gt;
/msg PayerName will show it as YourPlayerName -&amp;gt; Me to the other Player but be private&lt;br /&gt;
&lt;br /&gt;
=== Prefix and Suffix ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Never&#039;&#039;&#039; use McMyAdmin&#039;s Prefix and Suffix boxes, as you likely will not be able to remove them after you have set them without removing the group and re-adding it.&lt;br /&gt;
&lt;br /&gt;
== Check server&#039;s TPS ==&lt;br /&gt;
&lt;br /&gt;
Ticks Per Second&lt;br /&gt;
&lt;br /&gt;
If you use Bukkit/Essentials, do /lag&lt;br /&gt;
&lt;br /&gt;
== ColorMe ==&lt;br /&gt;
&lt;br /&gt;
If you add or remove a player to players.yml manually, keep a copy of the text you entered or of the file from which the text was removed. Sometimes when you do /color reload it will import an old version of the file from before the change you made. To resolve this:&lt;br /&gt;
&lt;br /&gt;
* make a copy of the text you added or the entire file not including the text you remove&lt;br /&gt;
* run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; players.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
* in config.yml set updateConfig: to true from the default of false&lt;br /&gt;
* /color reload&lt;br /&gt;
* now add or remove the text you did before, run the above command and it should work&lt;br /&gt;
&lt;br /&gt;
Also, it may be worth keeping updateConfig: as true always&lt;br /&gt;
&lt;br /&gt;
=== Colour and type ===&lt;br /&gt;
&lt;br /&gt;
To use both colour and formatting/type such as bold, itallic, strikethrough and underline at the same time, use the colour first then the formatting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;amplified: &#039;&amp;amp;6&amp;amp;oModerator&amp;amp;f&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
/prefix me &amp;amp;6&amp;amp;oModerator&lt;br /&gt;
&lt;br /&gt;
== Command Block ==&lt;br /&gt;
&lt;br /&gt;
Quick FAQ/Guide: http://hypixel.net/wiki/command-block/&lt;br /&gt;
&lt;br /&gt;
== Connection reset ==&lt;br /&gt;
&lt;br /&gt;
[Metrics]&lt;br /&gt;
&lt;br /&gt;
Set opt-out to true in plugins/PluginMetrics/config.yml&lt;br /&gt;
&lt;br /&gt;
This by default is false.&lt;br /&gt;
&lt;br /&gt;
In minecraft.log &amp;quot;[INFO] Connection reset&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;touch reset.sh ; chmod +x reset.sh ; vim reset.sh&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565 &amp;gt;&amp;gt; reset.log&lt;br /&gt;
echo -e &amp;quot;\n-------------------------------------------------------------------------------------------&amp;quot;&lt;br /&gt;
date +%R&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do the following in two separate SSH windows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f minecraft/install/directory/logs/minecraft.log&lt;br /&gt;
watch -n 1 ./reset.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then match up the times, and block the IP address from the server list website that is causing the message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A INPUT -s 50.116.54.77 -j DROP&lt;br /&gt;
iptables-save&lt;br /&gt;
iptables -L&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Lava ===&lt;br /&gt;
&amp;lt;!-- WorldProtect had to be disabled for this.--&amp;gt;&lt;br /&gt;
Allowing lava seems to be easiest by creating a group that can do it and then doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Allow lava buckets&lt;br /&gt;
[lavabucket]&lt;br /&gt;
allow&lt;br /&gt;
ignore-groups=Everyone&lt;br /&gt;
on-use=notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below method seems to fail&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ignore-perms=worldguard.lavabucket.exempt&lt;br /&gt;
ignore-groups=admins,mods,Lava&lt;br /&gt;
on-use=deny,tell,notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Current errors ==&lt;br /&gt;
&lt;br /&gt;
[WARNING] Can&#039;t keep up! Did the system time change, or is the server overloaded?&lt;br /&gt;
&lt;br /&gt;
May be due to TPS, /lag&lt;br /&gt;
&lt;br /&gt;
=== Current issues ===&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== DynMap ==&lt;br /&gt;
&lt;br /&gt;
To remove a map from rendering on the Dynamic Map web page, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&lt;br /&gt;
/map mapdelete _worldname_:_mapname_&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or remove the folder from /home/user/Minecraft/plugins/dynmap/web/tiles/worldname&lt;br /&gt;
&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Configuring-Maps-and-Worlds-using-dmap Configuring Maps and Worlds using dmap]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Component-Configuration Component Configuration]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://dev.bukkit.org/server-mods/dynmap/pages/faq/ FAQ]&lt;br /&gt;
&lt;br /&gt;
Render all:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap fullrender&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please be warned if you run a full render with the template set as the [https://github.com/webbukkit/dynmap/wiki/HD-Map-Configuration highest one for HD], hi_boost_xhi, then on a server with 8GB of RAM it will cause ~45-65% RAM usage.&lt;br /&gt;
&lt;br /&gt;
Pause render: &lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Disable world render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dmap worldset WorldName enabled:false&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hide a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap hide PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap show PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/webbukkit/dynmap/wiki/Web-UI-Parameters&lt;br /&gt;
&lt;br /&gt;
http://bywatercraft.co.uk:8123/?worldname=world&amp;amp;mapname=surface&lt;br /&gt;
&lt;br /&gt;
The Dynmap WorldGuard plugin that shows the WorldGuard region areas on the Dynamic Map shows a green border when there is no owner as it is not claimed.&lt;br /&gt;
&lt;br /&gt;
This will stop a render in progress and purge the tiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap purgeworld Le_Monde&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enjin ==&lt;br /&gt;
&lt;br /&gt;
* domain.co.uk//admin/games/minecraft-plugin/gid/6207-0&lt;br /&gt;
* Click [http://dev.bukkit.org/server-mods/vault Vault]&lt;br /&gt;
* If using Unix download the Vault.jar by doing wget http://dev.bukkit.org/media/files/655/849/Vault.jar&lt;br /&gt;
* Download the Enjin plugin&lt;br /&gt;
* Upload it via FTP to your server and it&#039;s Minecraft plugins directory&lt;br /&gt;
* Click Add Server&lt;br /&gt;
* Note down the enjinkey&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
If your site expires you will need to set the Custom Domain Name again.&lt;br /&gt;
&lt;br /&gt;
Go to http://site5659999cd2a04.enjin.com/dashboard/website/dns?site_id=722890&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Essentials | Essentials]] ==&lt;br /&gt;
&lt;br /&gt;
== Fixed errors ==&lt;br /&gt;
&lt;br /&gt;
=== Failed to start the minecraft server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Loading libraries, please wait...&lt;br /&gt;
Failed to start the minecraft server&lt;br /&gt;
java.lang.NullPointerException&lt;br /&gt;
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move your usercache.json file to another folder and try start/restart the server again&lt;br /&gt;
&lt;br /&gt;
=== FirstJoinPlus ===&lt;br /&gt;
&lt;br /&gt;
Could not pass event FirstJoinEvent to FirstJoinPlus v1.8.2&lt;br /&gt;
&lt;br /&gt;
Set your first join point again using /firstjoinplus setspawn&lt;br /&gt;
&lt;br /&gt;
Setting debug to true will treat every join as if it was a first join, so don&#039;t keep it on permanently!&lt;br /&gt;
&lt;br /&gt;
=== Modifyworld pass event ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] Could not pass event InventoryClickEvent to Modifyworld v1.19.4 org.bukkit.event.EventException&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fix: Disable the Modifyworld plugin and allow people to edit the world via the essentials.build permission.&lt;br /&gt;
&lt;br /&gt;
Notes: http://www.minecraftforum.net/topic/1763125-severe-could-not-pass-event-inventoryclickevent-to-modifyworld-v1194&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/PEXPlugins/PermissionsEx/wiki/Modifyworld#wiki-mw-configuration&lt;br /&gt;
&lt;br /&gt;
=== NoSplosion will cause Endermen to NOT spawn ===&lt;br /&gt;
&lt;br /&gt;
Disables all explosions vanilla or mods (Tekkit etc...) and fire from destroying blocks as well as Endermen from spawning. All explosions and fire still damage players but do not damage the environment.&lt;br /&gt;
&lt;br /&gt;
=== Your configuration might be outdated! ===&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then reload the server configuration or NCP plugin itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/reload&lt;br /&gt;
/ncp reload&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check if the config is different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;diff config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Give items ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftinfo.com/IDList.htm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/give [playername] [data-value] [amount]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftwiki.net/wiki/Data_values&lt;br /&gt;
&lt;br /&gt;
== Install Feed The Beast on a Unix server ==&lt;br /&gt;
&lt;br /&gt;
Add a user and make a directory specifically for the mod, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;add user ftb&lt;br /&gt;
mkdir server&lt;br /&gt;
cd /home/ftb/server&lt;br /&gt;
su ftb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&lt;br /&gt;
su user&lt;br /&gt;
cd ~/server&lt;br /&gt;
wget http://www.creeperrepo.net/direct/FTB2/6ce418a51b200ece8cb3c509ba9e094a/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv modpacks^Ultimate^1_0_1^Ultimate_Server.zip Ultimate_Server.zip&lt;br /&gt;
unzip Ultimate_Server.zip&lt;br /&gt;
vim ServerStart.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the values as you see fit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x ServerStart.sh&lt;br /&gt;
./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will error out if you&#039;re already running a Minecraft server on the default port 25565. If it does, do CTRL + C. To change this, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim server.properties&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the server-port to something that is not 25565. Then make sure the user:group ownership is correct on the server folder and all files and directories below it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CTRL + B then d to quit the tmux session.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
If you get something like below, you likely need to disable some mods (for me it was mods/railcraft.jar and mods/MineFactoryReloaded.jar):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] [ForgeModLoader] Detected leaking worlds in memory. There are 4 worlds that appear to be persisting.&lt;br /&gt;
A mod is likely caching the world incorrectly&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 7debb392 (world) has leaked.&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 3e6abeb4 (world) has leaked.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;mkdir McMyAdmin&lt;br /&gt;
cd McMyAdmin&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/MCMA2_glibc25.zip&lt;br /&gt;
unzip MCMA2_glibc25.zip&lt;br /&gt;
rm MCMA2_glibc25.zip&lt;br /&gt;
./MCMA2_Linux_x86_64 -configonly -setpass NEWADMINPASSWORD&lt;br /&gt;
vim McMyAdmin.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the Port and Server.Address to something other than 8080 and the Java.Memory value to as much RAM as you want/can use. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.creeperrepo.net/direct/FTB2/3be5e192a47685f491605e902dae3460/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv *press tab* FTB-Beta-A.jar ~/ftb/McMyAdmin/Minecraft&lt;br /&gt;
./MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
java -Xms1G -Xmx1G -jar ftbserver.jar nogui --&amp;gt;&lt;br /&gt;
== Install Votifier ==&lt;br /&gt;
&lt;br /&gt;
Install the plugin as normal by placing the .jar file in your plugins folder: http://dev.bukkit.org/server-mods/votifier&lt;br /&gt;
&lt;br /&gt;
Then reload the server and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat plugins/Votifier/rsa/public.key&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the code into the area of the server listing website you are using.&lt;br /&gt;
&lt;br /&gt;
=== [http://dev.bukkit.org/server-mods/votifier/forum/vote-listeners/48844-simple-vote-listener-perform-commands-and-timed-commands/#posts SimpleVoteListener] ===&lt;br /&gt;
&lt;br /&gt;
SimpleVoteListener can perform commands and broadcast messages&lt;br /&gt;
&lt;br /&gt;
== Load MCMyAdmin and Minecraft on server start ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh -p port user@localhost&lt;br /&gt;
crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press insert and add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;@reboot screen -dmS minecraft /home/mc/MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:wq&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then if you wish do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exit&lt;br /&gt;
touch /etc/init.d/minecraftd ; chown user:user /etc/init.d/minecraftd&lt;br /&gt;
vim /etc/init.d/minecraftd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Other options are to use:&lt;br /&gt;
#screen -S minecraft /home/mc/MCMA2_Linux_x86_64&lt;br /&gt;
#screen -dmS minecraft sh -c &#039;/home/mc/MCMA2_Linux_x86_64 ; exec bash&#039;&lt;br /&gt;
&lt;br /&gt;
## don&#039;t remove windows from the window list as soon as window process exits.&lt;br /&gt;
zombie kr #  k: destory window, r: resurrect window --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lock chests ==&lt;br /&gt;
&lt;br /&gt;
Use LWC or Lockette. &lt;br /&gt;
&lt;br /&gt;
To reload LWC, do /lwc admin reload&lt;br /&gt;
&lt;br /&gt;
To snoop in a chest with Lockette and to do this without a broadcast message, edit this file:&lt;br /&gt;
&lt;br /&gt;
/home/user/Minecraft/plugins/Lockette/config.yml&lt;br /&gt;
&lt;br /&gt;
And edit the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allow-admin-snoop: true&lt;br /&gt;
broadcast-snoop-target: &#039;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill all MCMA processes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results of the above command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;for a in `!!`&lt;br /&gt;
for a in `ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}`&lt;br /&gt;
&amp;gt; do&lt;br /&gt;
&amp;gt; kill -9 $a&lt;br /&gt;
&amp;gt; done&lt;br /&gt;
ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/McMyAdmin | McMyAdmin]] ==&lt;br /&gt;
&lt;br /&gt;
== Migrate from one *nix server to another ==&lt;br /&gt;
&lt;br /&gt;
scp / rsync the data in the Minecraft directory across. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install unzip&lt;br /&gt;
apt-get install openjdk-7-jre openjdk-7-jdk&lt;br /&gt;
cd /usr/local&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/etc.zip&lt;br /&gt;
unzip etc.zip&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to serverIPaddress:8080 in your browser. To login, check the details in McMyAdmin.conf. To change the password you &#039;&#039;&#039;need to stop McMyAdmin&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
/quit in console&lt;br /&gt;
&lt;br /&gt;
The file stores the password as MD5, to convert your password use this: http://www.md5hashgenerator.com/index.php&lt;br /&gt;
&lt;br /&gt;
== [http://media-mcw.cursecdn.com/thumb/4/4a/Mob_spawning_ranges.png/800px-Mob_spawning_ranges.png Mob Spawning Ranges] ==&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiverse | Multiverse]] ==&lt;br /&gt;
&lt;br /&gt;
This page has been moved to the above link as our server does not used Multiverse any more, it used Multiworld.&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiworld | Multiworld]] ==&lt;br /&gt;
&lt;br /&gt;
== NCore ==&lt;br /&gt;
&lt;br /&gt;
Plugin list: http://www.ribesg.fr/&lt;br /&gt;
&lt;br /&gt;
=== NEnchantingEgg ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NEnchantingEgg Documentation]&lt;br /&gt;
&lt;br /&gt;
=== nTheEndAgain ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NTheEndAgain Documentation]&lt;br /&gt;
&lt;br /&gt;
Shortcut instead of /ntheendagain -&amp;gt; /nend&lt;br /&gt;
&lt;br /&gt;
=== Check amount of dragons ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain nb world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Regen the world ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain regen world_the_end&lt;br /&gt;
/ntheendagain respawn world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Respawn the dragon ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain respawnEnderDragon world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Redstone ==&lt;br /&gt;
&lt;br /&gt;
=== [http://i.imgur.com/uM7O1l.png Powering a column of pistons] ===&lt;br /&gt;
&lt;br /&gt;
== Reload command ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftforum.net/topic/1506590-warning-cant-keep-up-did-the-system-time-change-or-is-the-server-overloaded&lt;br /&gt;
&lt;br /&gt;
v&lt;br /&gt;
&lt;br /&gt;
http://forums.bukkit.org/threads/petition-to-remove-the-reload-command.43212&lt;br /&gt;
&lt;br /&gt;
== Remote Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Colour code errors in console/log such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[12:21:32 INFO]: CONSOLE: Forcing save..←[m&lt;br /&gt;
[12:21:32 INFO]: CONSOLE: Save complete.←[m&lt;br /&gt;
←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1&lt;br /&gt;
G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K[12:21&lt;br /&gt;
:32 INFO]: ←[0;35;1m[Server←[0;35;1m] Save is complete.←[m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is due to the MinecraftRKitPlugin.jar file in your plugins folder. This is as of Release 10, Alpha 15.3 of the toolkit wrapper and happens on both Windows ([http://forums.bukkit.org/threads/console-format-issue.205024/ example]) and Unix (my own) ([https://forums.bukkit.org/threads/weird-multicraft-bukkit-error.127851/ example 2]).&lt;br /&gt;
&lt;br /&gt;
== Restart required ==&lt;br /&gt;
&lt;br /&gt;
If you use PermissionsBukkit with McMyAdmin, if you make a change you normally need to restart the Minecraft server to get it to see the changes. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;huge&#039;&#039;&#039; advantage of setting the Permissions Export to PermissionsEx is when a permission is added to McMyAdmin it automatically reloads the configuration, this is shown in the console by:&lt;br /&gt;
&lt;br /&gt;
[INFO] Permissions file successfully reloaded&amp;lt;br&amp;gt;&lt;br /&gt;
[INFO] Permissions reloaded&lt;br /&gt;
&lt;br /&gt;
If you op or de-op a player from ops.txt and the Administrators group in McMyAdmin.&lt;br /&gt;
&lt;br /&gt;
To set negative permissions in PermissionsEx, use - -permission before the other permissions.&lt;br /&gt;
&lt;br /&gt;
== Restore backup from McMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir BACKUPOFWORLDShhmm&lt;br /&gt;
cp -v world world_nether world_the_end BACKUPOFWORLDShhmm/ -R&lt;br /&gt;
mkdir movedawayworlds&lt;br /&gt;
mv world world_nether world_the_end movedawayworlds&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restore the backup via the McMyAdmin control panel.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To check when a player was last online, their IP address, what world they are in, do:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
/seen playername&lt;br /&gt;
&lt;br /&gt;
Useful:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -xr mcmonitor&lt;br /&gt;
CTRL A + D&lt;br /&gt;
screen -xr mysqlmcmon&lt;br /&gt;
&lt;br /&gt;
cd /home/mc/Minecraft&lt;br /&gt;
cat server.log | grep &amp;quot;YYYY-MM-DD&amp;quot; | grep User | grep -v indestructible&lt;br /&gt;
cat server.log | grep User | grep -v &#039;indestructible\|fell from a high place&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hawkeye ===&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/bukkit-plugins/hawkeye/pages/other-information/usage/ Usage]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Log everything:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Install Hawkeye by doing this manually or through a server control panel. In Unix, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/home/user/Minecraft/plugins/HawkEye# cat config.yml&lt;br /&gt;
&lt;br /&gt;
log:&lt;br /&gt;
  lava-bucket: true&lt;br /&gt;
  pvp-death: true&lt;br /&gt;
  other-death: true&lt;br /&gt;
  chat: true&lt;br /&gt;
  join: true&lt;br /&gt;
  open-container: true&lt;br /&gt;
  container-transaction: true&lt;br /&gt;
  teleport: true&lt;br /&gt;
  sign-place: true&lt;br /&gt;
  sign-break: true&lt;br /&gt;
  flint-steel: true&lt;br /&gt;
  block-place: true&lt;br /&gt;
  block-break: true&lt;br /&gt;
  enderman-pickup: true&lt;br /&gt;
  spawnmob-egg: true&lt;br /&gt;
  crop-trample: true&lt;br /&gt;
general:&lt;br /&gt;
  max-lines: 0&lt;br /&gt;
  log-item-drops-on-death: true&lt;br /&gt;
  cleanse-period: 20m&lt;br /&gt;
  cleanse-age: 0&lt;br /&gt;
  delete-data-on-rollback: true&lt;br /&gt;
  log-ip-addresses: true&lt;br /&gt;
  debug: false&lt;br /&gt;
  debug-level: low&lt;br /&gt;
  max-radius: 0&lt;br /&gt;
  give-user-tool: true&lt;br /&gt;
  tool-block: &#039;17&#039;&lt;br /&gt;
  default-here-radius: 5&lt;br /&gt;
  default-tool-command: &#039;&#039;&lt;br /&gt;
  check-for-updates: true&lt;br /&gt;
  log-delay: 2&lt;br /&gt;
mysql:&lt;br /&gt;
  hawkeye-table: hawkeye&lt;br /&gt;
  port: 3306&lt;br /&gt;
  player-table: hawk_players&lt;br /&gt;
  username: root&lt;br /&gt;
  world-table: hawk_worlds&lt;br /&gt;
  hostname: localhost&lt;br /&gt;
  max-connections: 10&lt;br /&gt;
  password: &#039;InsertMySQLPasswordHere&#039;&lt;br /&gt;
  database: hawkminecraft #you can rename this if you wish&lt;br /&gt;
ignore-worlds:&lt;br /&gt;
- thisworldisignored&lt;br /&gt;
- soisthisone&lt;br /&gt;
command-filter:&lt;br /&gt;
- /login&lt;br /&gt;
- /restartsrv&lt;br /&gt;
- /register&lt;br /&gt;
- /spawn&lt;br /&gt;
block-filter:&lt;br /&gt;
- NONE&lt;br /&gt;
containertransaction-filter:&lt;br /&gt;
  chest: true&lt;br /&gt;
  doublechest: true&lt;br /&gt;
  furnace: true&lt;br /&gt;
  dispenser: true&lt;br /&gt;
version: 1.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database hawkeye;&lt;br /&gt;
show databases;&lt;br /&gt;
use hawkeye&lt;br /&gt;
show tables;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be empty. If so (more than likely), log into your minecraft server and do /reload. Then go back into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use hawkeye&lt;br /&gt;
show tables;&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| Tables_in_hawkeye       |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| hawk_players            |&lt;br /&gt;
| hawk_worlds             |&lt;br /&gt;
| hawkeye                 |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
select * from hawk_worlds;&lt;br /&gt;
select * from hawkeye;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you can now do /hawk in game. To check a block, do /hawk tool , then left click a block and it will show you the block information.&lt;br /&gt;
&lt;br /&gt;
==== Get table structure and players ====&lt;br /&gt;
&lt;br /&gt;
desc hawkeye;&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
&lt;br /&gt;
==== Look at logs ====&lt;br /&gt;
&lt;br /&gt;
Via a web interface: http://dev.bukkit.org/bukkit-plugins/hawkeye-reload/pages/web-interface-setup/&lt;br /&gt;
&lt;br /&gt;
If you do a search and get this error message you need to re-download the interface:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Error! Unknown column &#039;date&#039; in &#039;where clause&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Via SQL: &lt;br /&gt;
&lt;br /&gt;
select * from hawkeye ORDER BY data_id DESC LIMIT 100000;&lt;br /&gt;
&lt;br /&gt;
== See region information ==&lt;br /&gt;
&lt;br /&gt;
/region info area&lt;br /&gt;
&lt;br /&gt;
It should output something like:&lt;br /&gt;
&lt;br /&gt;
Region: area, type: shape, Priority: X&amp;lt;br&amp;gt;&lt;br /&gt;
Flags: use: ALLOW, mob-spawning: DENY (OR ALLOW)&amp;lt;br&amp;gt;&lt;br /&gt;
Bound: (x) (z)&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftwiki.net/wiki/Server.properties server.properties] file ==&lt;br /&gt;
&lt;br /&gt;
== Set flyspeed ==&lt;br /&gt;
&lt;br /&gt;
Default is 1&lt;br /&gt;
&lt;br /&gt;
For yourself:&lt;br /&gt;
&lt;br /&gt;
/flyspeeed 2&lt;br /&gt;
&lt;br /&gt;
For others:&lt;br /&gt;
&lt;br /&gt;
/flyspeed 2 playername&lt;br /&gt;
&lt;br /&gt;
== Setting spawn ==&lt;br /&gt;
&lt;br /&gt;
On Bywater Craft where we have multiple spawn plugins, to set spawn you need to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/mw setspawn&lt;br /&gt;
/setspawn&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set warps ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/setwarp NewWarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp WarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have per-warp-permission set to true in the config.yml then you can limit what warps players can use. This also controls what players would see with /warp, hence why both essentials.warp and essentials.warp.list are used.&lt;br /&gt;
&lt;br /&gt;
== Set world for SkyGridMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim SkyGrid.jar/config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;world: WorldName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching 09/09/14 - 28/11/14 (old) ==&lt;br /&gt;
&lt;br /&gt;
This was changed as of November 28th 2014: http://www.spigotmc.org/threads/bukkit-craftbukkit-spigot-1-8.36598/&lt;br /&gt;
&lt;br /&gt;
Please now use http://www.spigotmc.org/threads/buildtools-updates-information.42865/ for Minecraft 1.8+&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd ~/spigotwork&lt;br /&gt;
java -jar ~/spigotwork/SpigotPatcher-1.0.jar ~/spigotwork/spigot1649.jar ~/spigotwork/spigot-YYYYMMDDa.bps ~/spigotwork/spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&lt;br /&gt;
rm ../Minecraft/spigot.jar&lt;br /&gt;
mv spigot.jar ../Minecraft/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside the spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;java -jar SpigotPatcher-1.0.jar spigot1649.jar spigot-YYYYMMDD.bps spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching - new ==&lt;br /&gt;
&lt;br /&gt;
Inside your spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir 1.XX-XBuildTools&lt;br /&gt;
rm BuildTools.jar&lt;br /&gt;
wget &amp;quot;https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar&amp;quot; -O BuildTools.jar&lt;br /&gt;
java -jar BuildTools.jar&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If needed run this first outside of McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exec java -jar spigot.jar --forceUpgrade nogui | tee test.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftforum.net/videos/view-51785-how-to-synchronize-nether-portals Synchronise Nether Portals] ==&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/server-mods/ascii-bukkit-menu/ ASCII SSH Bukkit Menu] (via screen)&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/Ahtenus/minecraft-init Init script]&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
[[Linux#tmux | Using it]]&lt;br /&gt;
&lt;br /&gt;
http://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen/13954#13954&lt;br /&gt;
&lt;br /&gt;
== Update CraftBukkit ==&lt;br /&gt;
&lt;br /&gt;
Stop the server, then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit.jar versioncraftbukkit.jar&lt;br /&gt;
wget http://dl.bukkit.org/latest-rb/craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or download the development/beta build and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit-dev.jar craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the server&lt;br /&gt;
&lt;br /&gt;
Log out and back into MCMyAdmin.&lt;br /&gt;
&lt;br /&gt;
== World Edit ==&lt;br /&gt;
&lt;br /&gt;
Place .schematic files in /home/user/Minecraft/plugins/WorldEdit/schematics&lt;br /&gt;
&lt;br /&gt;
Import them by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//schematic load filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you can do //paste in Minecraft to paste it into the world where you are.&lt;br /&gt;
&lt;br /&gt;
=== Fill an area ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select position 1 and 2. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//set block&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unbind a tool/block ===&lt;br /&gt;
&lt;br /&gt;
If for example you accidentally do //fill block (e.g. sand), and each time you right click with a tool/block or your hand, clear it by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== World Guard ==&lt;br /&gt;
&lt;br /&gt;
http://wiki.sk89q.com/wiki/WorldEdit/Selection&lt;br /&gt;
&lt;br /&gt;
https://bukkit.org/threads/worldguard-not-expanding-regions.20974/&lt;br /&gt;
&lt;br /&gt;
To protect an area, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then click the first position then the second position with the wooden axe.&lt;br /&gt;
&lt;br /&gt;
If you only do one layer, you can do //expand to go up or down, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//expand UpValue DownValue up&lt;br /&gt;
//expand 10 0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would expand up 10 blocks from the single layer but do 0 down.&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define newnameforarea owner&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Owner can be left blank.&lt;br /&gt;
&lt;br /&gt;
To get information on the area you just created, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region info newnameforarea&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Allow fire spread/tick ===&lt;br /&gt;
&lt;br /&gt;
In config.yml:&lt;br /&gt;
&lt;br /&gt;
Set high-frequency-flags to true&amp;lt;br&amp;gt;&lt;br /&gt;
Set disable-all-fire-spread to false&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag __global__ fire-spread allow&lt;br /&gt;
/rg flag __global__ lava-fire allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this still doesn&#039;t work, if you have Essentials then set these in config.yml:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fire-spread: true&lt;br /&gt;
lava-fire-spread: true&lt;br /&gt;
flint-fire: true&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit world regions from outside (and inside) that world ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w ExactWorldName RegionName FlagName allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to use the blocked-cmds flag and want to block multiple commands separate them by commas:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w world MyHome blocked-cmds /tp,/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Entry flag for groups ===&lt;br /&gt;
&lt;br /&gt;
Due to inheritance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag chestroomdoor entry deny&lt;br /&gt;
/rg flag chestroomdoor entry -g nonmembers&lt;br /&gt;
/rg addmember chestroomdoor g:citizen&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets round inheritance by denying all except members from a certain group up the inheritance tree.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you have:&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;vip&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:vip&lt;br /&gt;
/region flag doorway entry -g nonmembers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is not in the vip group for the doorway.&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;guest&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:guest&lt;br /&gt;
/region flag doorway entry -g members&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is in the members field, guest in this case, group for the doorway. Everyone else would be allowed.&lt;br /&gt;
&lt;br /&gt;
Then you&#039;d add the permission node &amp;quot;group.guest&amp;quot; to the guest group in your permissions plugin&#039;s config.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Guest&amp;quot; isn&#039;t a group - http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags#Group&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg removemember chestroomdoor playername&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Group inheritance ====&lt;br /&gt;
&lt;br /&gt;
Important note about the below example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag regionname entry deny&lt;br /&gt;
/rg addmember regionname g:groupname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands should deny entry to groups not added as members or owners.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keep in mind that if you use any inheritance system in your permissions (for example: builder inherits default permissions), any groups that inherit the same permissions as the allowed group will also be allowed entrance to the region.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Your best bet is to eliminate the inheritances and give each group their own group.groupname permission. This allows worldguard to see separate groups.&lt;br /&gt;
&lt;br /&gt;
The same goes with the exit flag.&lt;br /&gt;
&lt;br /&gt;
=== Flint &amp;amp; Steel doesn&#039;t work ===&lt;br /&gt;
&lt;br /&gt;
If it returns the message:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You&#039;re not allowed to use that here&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Do this in-game:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region flag -w world __global__ lighter allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: http://forums.bukkit.org/threads/i-need-help-with-allowing-flint-steel.152990/&lt;br /&gt;
&lt;br /&gt;
=== Rename region ===&lt;br /&gt;
&lt;br /&gt;
You cannot do this without editing the database manually. If the area is not too big, just remove it and re-add it.&lt;br /&gt;
&lt;br /&gt;
If you do edit the entry in the id column of the region table of the worldguard (by default) database, just do /worldguard reload in-game after you have changed it.&lt;br /&gt;
&lt;br /&gt;
=== Set flags ===&lt;br /&gt;
&lt;br /&gt;
To set flags, see this page: http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags&lt;br /&gt;
&lt;br /&gt;
To stop building and PvP but to allow use, you would do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag areaname build deny&lt;br /&gt;
/rg flag areaname pvp deny&lt;br /&gt;
/rg flag areaname use allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [http://dev.bukkit.org/bukkit-plugins/worldguard-block-restricter WorldGuard Block Restricter] ====&lt;br /&gt;
&lt;br /&gt;
This requires [http://dev.bukkit.org/bukkit-plugins/worldguard-custom-flags WorldGuard Custom Flags] installing too.&lt;br /&gt;
&lt;br /&gt;
To only allow a specific type of block you need to:&lt;br /&gt;
&lt;br /&gt;
* set build allow in WorldGuard: /rg flag areaname build allow&lt;br /&gt;
* then deny all blocks via WorldGuard Block Restricter using /rg flag areaname deny-blocks any&lt;br /&gt;
* then allow the blocks you want via WorldGuard Block Restricter using /rg flag areaname allow-blocks dirt&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Main_Page&amp;diff=1141</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Main_Page&amp;diff=1141"/>
		<updated>2020-04-03T07:36:23Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to Server Knowledge Base. This is a developing Wiki for knowledge on servers, technical information and is a place to contribute to a compendium of information. A lot of the guides here may be based around using &#039;&#039;&#039;[[SSH]]&#039;&#039;&#039; so may be worth reading that guide first.&lt;br /&gt;
&lt;br /&gt;
If there is anything you would like adding to this wiki, please contact the admin.&lt;br /&gt;
&lt;br /&gt;
General technology information is placed &#039;&#039;&#039;[[General|here]]&#039;&#039;&#039;. So far this is only being written and developed by one person.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Topic List ==&lt;br /&gt;
&lt;br /&gt;
* [[Apache]] - A web server for Linux. Alternatives: [http://www.nginx.org Nginx] | [http://www.litespeedtech.com LiteSpeed] | [http://www.lighttpd.net Lighttpd] | [http://www.hiawatha-webserver.org Hiawatha] | [http://www.cherokee-project.com/ Cherokee]&lt;br /&gt;
* [[cPanel]] (2082/2083) and [[WHM | WHM/Web Host Manager]] (2086/2087)&lt;br /&gt;
* [[DNS]] - Domain Name System/Server&lt;br /&gt;
* [[Excel]]&lt;br /&gt;
* [[FTP]] - File Transfer Protocol&lt;br /&gt;
* [[Linux]]/Unix: [[CentOS]], [[Debian]], [[Fedora]], [[openSUSE]], [[Ubuntu]]&lt;br /&gt;
* [[Jira]]&lt;br /&gt;
* [[Mail]] | [[Qmail]] - A Mail Transfer Agent&lt;br /&gt;
* [[MediaWiki]] | [[Minecraft]]&lt;br /&gt;
* [[MySQL]] - A Structured Query Language for databases&lt;br /&gt;
* [[Networking]]&lt;br /&gt;
* [[OpenStack]]&lt;br /&gt;
* [[PHP]] - Hypertext Preprocessor&lt;br /&gt;
* [[Plesk]] - Domains, databases, mail, application/software control panel (8443) - Parallels Product. [http://www.parallels.com/uk/products/plesk/lifecycle Control Panel Lifecyle]&lt;br /&gt;
* [[Resource Usage]]&lt;br /&gt;
* [[Rsync]]&lt;br /&gt;
* [[Security]] | [[Scripts]] | [http://serverkb.co.uk/tools Tools]&lt;br /&gt;
&amp;lt;!--[[Services]]--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;[[SSH]]&#039;&#039;&#039; - Secure Shell, a network protocol for secure data communication&lt;br /&gt;
* [[SSL]] - Secure Socket Layer | &#039;&#039;&#039;[[Useful_Tools_and_Links#SSL | SSL Tools]]&#039;&#039;&#039;&lt;br /&gt;
* [[Virtuozzo]] - Server management control panel (4643) - Parallels Product&lt;br /&gt;
* [[Windows]]: [[Server 2003]] | [[Windows_Web|Web]] (free) | [[Server 2008 R2 &amp;amp; Hyper-V]]&lt;br /&gt;
* [[Wordpress]] - A popular Content Management Systems&lt;br /&gt;
&lt;br /&gt;
== [[Useful_Tools_and_Links|Useful Tools and Links]] ==&lt;br /&gt;
&lt;br /&gt;
Note: This website will display best in full screen due to &amp;lt; pre &amp;gt;&amp;lt; /pre &amp;gt; boxes.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=1140</id>
		<title>Minecraft</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Minecraft&amp;diff=1140"/>
		<updated>2019-09-16T12:24:24Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Spigot patching - new */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Server host/IP: mc.bywatercraft.co.uk / 188.165.120.188&amp;lt;br&amp;gt;&lt;br /&gt;
Website name: bywatercraft.co.uk -/&amp;gt; bywatercraft.com&lt;br /&gt;
&lt;br /&gt;
Currently the Bywater Craft Minecraft server is running Spigot 1.8.8. We have now updated the plugins to be compatible with 1.8.7.&lt;br /&gt;
&lt;br /&gt;
Load Minecraft:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/usr/bin/java -Djline.terminal=jline.UnsupportedTerminal -client -Xmx7132M -jar spigot.jar nogui -d yyyy-MM-dd HH:mm:ss -nojline&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n minecraft&lt;br /&gt;
cd /home/user&lt;br /&gt;
./MCMA2_Linux_x86_64 | tee yourminecraft.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to connect from elsewhere to view the above output/console load the screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh user@localhost -pXXXX&lt;br /&gt;
tmux ls&lt;br /&gt;
tmux attach 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To kill the process on boot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps -ef | grep tmux | grep -v grep | awk &#039;{print $2}&#039; | xargs kill -9&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using CTRL + D will quit screen and close any processes running within it.&amp;lt;br&amp;gt;&lt;br /&gt;
To exit safely do CTRL + B, let go, then press D on it&#039;s own. &lt;br /&gt;
&lt;br /&gt;
When downloading a backup from McMyAdmin, it comes in the mcb format. Change it to .zip and you can then unzip it into a folder and restore to the server.&lt;br /&gt;
&lt;br /&gt;
== Allowing PvP ==&lt;br /&gt;
&lt;br /&gt;
Personally, for WorldGuard&#039;s pvp flag to work we had to ensure:&lt;br /&gt;
&lt;br /&gt;
* Essentials plugin had pvp = true&lt;br /&gt;
* McMyAdmin control panel had Configuration &amp;gt; Game Settings &amp;gt; Allow Player vs Player combat&lt;br /&gt;
* server.properties file had pvp = true&lt;br /&gt;
* WorldGuard had __global__ set to pvp deny&lt;br /&gt;
* WorldGuard then could have specific regions set to pvp allow&lt;br /&gt;
&lt;br /&gt;
== Backpack ==&lt;br /&gt;
&lt;br /&gt;
Reduce/downgrade Backpack space:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /Minecraft/plugins/Backpack/backpacks/world&lt;br /&gt;
ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the value next to &amp;quot;contents-amount:&amp;quot; in the user&#039;s .yml file.&lt;br /&gt;
&lt;br /&gt;
== Bungeecord ==&lt;br /&gt;
&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord/&lt;br /&gt;
https://www.spigotmc.org/wiki/bungeecord-configuration-guide/&lt;br /&gt;
http://www.spigotmc.org/wiki/bungeecord-installation/#installing-bungeecord-on-linux&lt;br /&gt;
&lt;br /&gt;
To end Bungeecord script, type end and hit enter.&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=0ViRZPLuBiA How to use and install BungeeCord]&lt;br /&gt;
&lt;br /&gt;
== Buycraft ==&lt;br /&gt;
&lt;br /&gt;
=== Edit Store welcome page ===&lt;br /&gt;
&lt;br /&gt;
Webstore &amp;gt; General settings &amp;gt; Homepage description&lt;br /&gt;
&lt;br /&gt;
== Chat ==&lt;br /&gt;
&lt;br /&gt;
/tell PlayerName will whisper a message to a player. This option will not show in a console.&lt;br /&gt;
&lt;br /&gt;
/msg PayerName will show it as YourPlayerName -&amp;gt; Me to the other Player but be private&lt;br /&gt;
&lt;br /&gt;
=== Prefix and Suffix ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Never&#039;&#039;&#039; use McMyAdmin&#039;s Prefix and Suffix boxes, as you likely will not be able to remove them after you have set them without removing the group and re-adding it.&lt;br /&gt;
&lt;br /&gt;
== Check server&#039;s TPS ==&lt;br /&gt;
&lt;br /&gt;
Ticks Per Second&lt;br /&gt;
&lt;br /&gt;
If you use Bukkit/Essentials, do /lag&lt;br /&gt;
&lt;br /&gt;
== ColorMe ==&lt;br /&gt;
&lt;br /&gt;
If you add or remove a player to players.yml manually, keep a copy of the text you entered or of the file from which the text was removed. Sometimes when you do /color reload it will import an old version of the file from before the change you made. To resolve this:&lt;br /&gt;
&lt;br /&gt;
* make a copy of the text you added or the entire file not including the text you remove&lt;br /&gt;
* run the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; players.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
* in config.yml set updateConfig: to true from the default of false&lt;br /&gt;
* /color reload&lt;br /&gt;
* now add or remove the text you did before, run the above command and it should work&lt;br /&gt;
&lt;br /&gt;
Also, it may be worth keeping updateConfig: as true always&lt;br /&gt;
&lt;br /&gt;
=== Colour and type ===&lt;br /&gt;
&lt;br /&gt;
To use both colour and formatting/type such as bold, itallic, strikethrough and underline at the same time, use the colour first then the formatting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;amplified: &#039;&amp;amp;6&amp;amp;oModerator&amp;amp;f&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
/prefix me &amp;amp;6&amp;amp;oModerator&lt;br /&gt;
&lt;br /&gt;
== Command Block ==&lt;br /&gt;
&lt;br /&gt;
Quick FAQ/Guide: http://hypixel.net/wiki/command-block/&lt;br /&gt;
&lt;br /&gt;
== Connection reset ==&lt;br /&gt;
&lt;br /&gt;
[Metrics]&lt;br /&gt;
&lt;br /&gt;
Set opt-out to true in plugins/PluginMetrics/config.yml&lt;br /&gt;
&lt;br /&gt;
This by default is false.&lt;br /&gt;
&lt;br /&gt;
In minecraft.log &amp;quot;[INFO] Connection reset&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;touch reset.sh ; chmod +x reset.sh ; vim reset.sh&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565 &amp;gt;&amp;gt; reset.log&lt;br /&gt;
echo -e &amp;quot;\n-------------------------------------------------------------------------------------------&amp;quot;&lt;br /&gt;
date +%R&lt;br /&gt;
netstat -pantu | grep -v LISTEN | grep 25565&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do the following in two separate SSH windows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f minecraft/install/directory/logs/minecraft.log&lt;br /&gt;
watch -n 1 ./reset.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then match up the times, and block the IP address from the server list website that is causing the message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A INPUT -s 50.116.54.77 -j DROP&lt;br /&gt;
iptables-save&lt;br /&gt;
iptables -L&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Lava ===&lt;br /&gt;
&amp;lt;!-- WorldProtect had to be disabled for this.--&amp;gt;&lt;br /&gt;
Allowing lava seems to be easiest by creating a group that can do it and then doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Allow lava buckets&lt;br /&gt;
[lavabucket]&lt;br /&gt;
allow&lt;br /&gt;
ignore-groups=Everyone&lt;br /&gt;
on-use=notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below method seems to fail&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ignore-perms=worldguard.lavabucket.exempt&lt;br /&gt;
ignore-groups=admins,mods,Lava&lt;br /&gt;
on-use=deny,tell,notify,log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Current errors ==&lt;br /&gt;
&lt;br /&gt;
[WARNING] Can&#039;t keep up! Did the system time change, or is the server overloaded?&lt;br /&gt;
&lt;br /&gt;
May be due to TPS, /lag&lt;br /&gt;
&lt;br /&gt;
=== Current issues ===&lt;br /&gt;
&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== DynMap ==&lt;br /&gt;
&lt;br /&gt;
To remove a map from rendering on the Dynamic Map web page, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&lt;br /&gt;
/map mapdelete _worldname_:_mapname_&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or remove the folder from /home/user/Minecraft/plugins/dynmap/web/tiles/worldname&lt;br /&gt;
&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Configuring-Maps-and-Worlds-using-dmap Configuring Maps and Worlds using dmap]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/webbukkit/dynmap/wiki/Component-Configuration Component Configuration]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://dev.bukkit.org/server-mods/dynmap/pages/faq/ FAQ]&lt;br /&gt;
&lt;br /&gt;
Render all:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap fullrender&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please be warned if you run a full render with the template set as the [https://github.com/webbukkit/dynmap/wiki/HD-Map-Configuration highest one for HD], hi_boost_xhi, then on a server with 8GB of RAM it will cause ~45-65% RAM usage.&lt;br /&gt;
&lt;br /&gt;
Pause render: &lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap pause none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Disable world render:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dmap worldset WorldName enabled:false&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hide a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap hide PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show a player:&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap show PlayerName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/webbukkit/dynmap/wiki/Web-UI-Parameters&lt;br /&gt;
&lt;br /&gt;
http://bywatercraft.co.uk:8123/?worldname=world&amp;amp;mapname=surface&lt;br /&gt;
&lt;br /&gt;
The Dynmap WorldGuard plugin that shows the WorldGuard region areas on the Dynamic Map shows a green border when there is no owner as it is not claimed.&lt;br /&gt;
&lt;br /&gt;
This will stop a render in progress and purge the tiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dynmap purgeworld Le_Monde&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enjin ==&lt;br /&gt;
&lt;br /&gt;
* domain.co.uk//admin/games/minecraft-plugin/gid/6207-0&lt;br /&gt;
* Click [http://dev.bukkit.org/server-mods/vault Vault]&lt;br /&gt;
* If using Unix download the Vault.jar by doing wget http://dev.bukkit.org/media/files/655/849/Vault.jar&lt;br /&gt;
* Download the Enjin plugin&lt;br /&gt;
* Upload it via FTP to your server and it&#039;s Minecraft plugins directory&lt;br /&gt;
* Click Add Server&lt;br /&gt;
* Note down the enjinkey&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
If your site expires you will need to set the Custom Domain Name again.&lt;br /&gt;
&lt;br /&gt;
Go to http://site5659999cd2a04.enjin.com/dashboard/website/dns?site_id=722890&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Essentials | Essentials]] ==&lt;br /&gt;
&lt;br /&gt;
== Fixed errors ==&lt;br /&gt;
&lt;br /&gt;
=== Failed to start the minecraft server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Loading libraries, please wait...&lt;br /&gt;
Failed to start the minecraft server&lt;br /&gt;
java.lang.NullPointerException&lt;br /&gt;
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Move your usercache.json file to another folder and try start/restart the server again&lt;br /&gt;
&lt;br /&gt;
=== FirstJoinPlus ===&lt;br /&gt;
&lt;br /&gt;
Could not pass event FirstJoinEvent to FirstJoinPlus v1.8.2&lt;br /&gt;
&lt;br /&gt;
Set your first join point again using /firstjoinplus setspawn&lt;br /&gt;
&lt;br /&gt;
Setting debug to true will treat every join as if it was a first join, so don&#039;t keep it on permanently!&lt;br /&gt;
&lt;br /&gt;
=== Modifyworld pass event ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] Could not pass event InventoryClickEvent to Modifyworld v1.19.4 org.bukkit.event.EventException&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fix: Disable the Modifyworld plugin and allow people to edit the world via the essentials.build permission.&lt;br /&gt;
&lt;br /&gt;
Notes: http://www.minecraftforum.net/topic/1763125-severe-could-not-pass-event-inventoryclickevent-to-modifyworld-v1194&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/PEXPlugins/PermissionsEx/wiki/Modifyworld#wiki-mw-configuration&lt;br /&gt;
&lt;br /&gt;
=== NoSplosion will cause Endermen to NOT spawn ===&lt;br /&gt;
&lt;br /&gt;
Disables all explosions vanilla or mods (Tekkit etc...) and fire from destroying blocks as well as Endermen from spawning. All explosions and fire still damage players but do not damage the environment.&lt;br /&gt;
&lt;br /&gt;
=== Your configuration might be outdated! ===&lt;br /&gt;
&lt;br /&gt;
The best thing to do is just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then reload the server configuration or NCP plugin itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/reload&lt;br /&gt;
/ncp reload&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then check if the config is different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;diff config.yml old.config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Give items ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftinfo.com/IDList.htm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/give [playername] [data-value] [amount]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftwiki.net/wiki/Data_values&lt;br /&gt;
&lt;br /&gt;
== Install Feed The Beast on a Unix server ==&lt;br /&gt;
&lt;br /&gt;
Add a user and make a directory specifically for the mod, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;add user ftb&lt;br /&gt;
mkdir server&lt;br /&gt;
cd /home/ftb/server&lt;br /&gt;
su ftb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&lt;br /&gt;
su user&lt;br /&gt;
cd ~/server&lt;br /&gt;
wget http://www.creeperrepo.net/direct/FTB2/6ce418a51b200ece8cb3c509ba9e094a/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv modpacks^Ultimate^1_0_1^Ultimate_Server.zip Ultimate_Server.zip&lt;br /&gt;
unzip Ultimate_Server.zip&lt;br /&gt;
vim ServerStart.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the values as you see fit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x ServerStart.sh&lt;br /&gt;
./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It will error out if you&#039;re already running a Minecraft server on the default port 25565. If it does, do CTRL + C. To change this, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim server.properties&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the server-port to something that is not 25565. Then make sure the user:group ownership is correct on the server folder and all files and directories below it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./ServerStart.sh | tee ftb.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CTRL + B then d to quit the tmux session.&lt;br /&gt;
&lt;br /&gt;
=== Errors ===&lt;br /&gt;
&lt;br /&gt;
If you get something like below, you likely need to disable some mods (for me it was mods/railcraft.jar and mods/MineFactoryReloaded.jar):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[SEVERE] [ForgeModLoader] Detected leaking worlds in memory. There are 4 worlds that appear to be persisting.&lt;br /&gt;
A mod is likely caching the world incorrectly&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 7debb392 (world) has leaked.&lt;br /&gt;
2013-04-23 15:54:59 [SEVERE] [ForgeModLoader] The world 3e6abeb4 (world) has leaked.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;mkdir McMyAdmin&lt;br /&gt;
cd McMyAdmin&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/MCMA2_glibc25.zip&lt;br /&gt;
unzip MCMA2_glibc25.zip&lt;br /&gt;
rm MCMA2_glibc25.zip&lt;br /&gt;
./MCMA2_Linux_x86_64 -configonly -setpass NEWADMINPASSWORD&lt;br /&gt;
vim McMyAdmin.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the Port and Server.Address to something other than 8080 and the Java.Memory value to as much RAM as you want/can use. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.creeperrepo.net/direct/FTB2/3be5e192a47685f491605e902dae3460/modpacks%5EUltimate%5E1_0_1%5EUltimate_Server.zip&lt;br /&gt;
mv *press tab* FTB-Beta-A.jar ~/ftb/McMyAdmin/Minecraft&lt;br /&gt;
./MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
java -Xms1G -Xmx1G -jar ftbserver.jar nogui --&amp;gt;&lt;br /&gt;
== Install Votifier ==&lt;br /&gt;
&lt;br /&gt;
Install the plugin as normal by placing the .jar file in your plugins folder: http://dev.bukkit.org/server-mods/votifier&lt;br /&gt;
&lt;br /&gt;
Then reload the server and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat plugins/Votifier/rsa/public.key&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the code into the area of the server listing website you are using.&lt;br /&gt;
&lt;br /&gt;
=== [http://dev.bukkit.org/server-mods/votifier/forum/vote-listeners/48844-simple-vote-listener-perform-commands-and-timed-commands/#posts SimpleVoteListener] ===&lt;br /&gt;
&lt;br /&gt;
SimpleVoteListener can perform commands and broadcast messages&lt;br /&gt;
&lt;br /&gt;
== Load MCMyAdmin and Minecraft on server start ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh -p port user@localhost&lt;br /&gt;
crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press insert and add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;@reboot screen -dmS minecraft /home/mc/MCMA2_Linux_x86_64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:wq&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then if you wish do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exit&lt;br /&gt;
touch /etc/init.d/minecraftd ; chown user:user /etc/init.d/minecraftd&lt;br /&gt;
vim /etc/init.d/minecraftd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Other options are to use:&lt;br /&gt;
#screen -S minecraft /home/mc/MCMA2_Linux_x86_64&lt;br /&gt;
#screen -dmS minecraft sh -c &#039;/home/mc/MCMA2_Linux_x86_64 ; exec bash&#039;&lt;br /&gt;
&lt;br /&gt;
## don&#039;t remove windows from the window list as soon as window process exits.&lt;br /&gt;
zombie kr #  k: destory window, r: resurrect window --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lock chests ==&lt;br /&gt;
&lt;br /&gt;
Use LWC or Lockette. &lt;br /&gt;
&lt;br /&gt;
To reload LWC, do /lwc admin reload&lt;br /&gt;
&lt;br /&gt;
To snoop in a chest with Lockette and to do this without a broadcast message, edit this file:&lt;br /&gt;
&lt;br /&gt;
/home/user/Minecraft/plugins/Lockette/config.yml&lt;br /&gt;
&lt;br /&gt;
And edit the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allow-admin-snoop: true&lt;br /&gt;
broadcast-snoop-target: &#039;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill all MCMA processes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Results of the above command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;for a in `!!`&lt;br /&gt;
for a in `ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}`&lt;br /&gt;
&amp;gt; do&lt;br /&gt;
&amp;gt; kill -9 $a&lt;br /&gt;
&amp;gt; done&lt;br /&gt;
ps aux|grep MC|grep x86|awk {&#039;print $2&#039;}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/McMyAdmin | McMyAdmin]] ==&lt;br /&gt;
&lt;br /&gt;
== Migrate from one *nix server to another ==&lt;br /&gt;
&lt;br /&gt;
scp / rsync the data in the Minecraft directory across. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install unzip&lt;br /&gt;
apt-get install openjdk-7-jre openjdk-7-jdk&lt;br /&gt;
cd /usr/local&lt;br /&gt;
wget http://mcmyadmin.com/Downloads/etc.zip&lt;br /&gt;
unzip etc.zip&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to serverIPaddress:8080 in your browser. To login, check the details in McMyAdmin.conf. To change the password you &#039;&#039;&#039;need to stop McMyAdmin&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
/quit in console&lt;br /&gt;
&lt;br /&gt;
The file stores the password as MD5, to convert your password use this: http://www.md5hashgenerator.com/index.php&lt;br /&gt;
&lt;br /&gt;
== [http://media-mcw.cursecdn.com/thumb/4/4a/Mob_spawning_ranges.png/800px-Mob_spawning_ranges.png Mob Spawning Ranges] ==&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiverse | Multiverse]] ==&lt;br /&gt;
&lt;br /&gt;
This page has been moved to the above link as our server does not used Multiverse any more, it used Multiworld.&lt;br /&gt;
&lt;br /&gt;
== [[Minecraft/Multiworld | Multiworld]] ==&lt;br /&gt;
&lt;br /&gt;
== NCore ==&lt;br /&gt;
&lt;br /&gt;
Plugin list: http://www.ribesg.fr/&lt;br /&gt;
&lt;br /&gt;
=== NEnchantingEgg ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NEnchantingEgg Documentation]&lt;br /&gt;
&lt;br /&gt;
=== nTheEndAgain ===&lt;br /&gt;
&lt;br /&gt;
[http://www.ribesg.fr/bukkit/NTheEndAgain Documentation]&lt;br /&gt;
&lt;br /&gt;
Shortcut instead of /ntheendagain -&amp;gt; /nend&lt;br /&gt;
&lt;br /&gt;
=== Check amount of dragons ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain nb world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Regen the world ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain regen world_the_end&lt;br /&gt;
/ntheendagain respawn world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Respawn the dragon ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/ntheendagain respawnEnderDragon world_the_end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Redstone ==&lt;br /&gt;
&lt;br /&gt;
=== [http://i.imgur.com/uM7O1l.png Powering a column of pistons] ===&lt;br /&gt;
&lt;br /&gt;
== Reload command ==&lt;br /&gt;
&lt;br /&gt;
http://www.minecraftforum.net/topic/1506590-warning-cant-keep-up-did-the-system-time-change-or-is-the-server-overloaded&lt;br /&gt;
&lt;br /&gt;
v&lt;br /&gt;
&lt;br /&gt;
http://forums.bukkit.org/threads/petition-to-remove-the-reload-command.43212&lt;br /&gt;
&lt;br /&gt;
== Remote Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Colour code errors in console/log such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[12:21:32 INFO]: CONSOLE: Forcing save..←[m&lt;br /&gt;
[12:21:32 INFO]: CONSOLE: Save complete.←[m&lt;br /&gt;
←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1&lt;br /&gt;
G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K←[1G←[K[12:21&lt;br /&gt;
:32 INFO]: ←[0;35;1m[Server←[0;35;1m] Save is complete.←[m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is due to the MinecraftRKitPlugin.jar file in your plugins folder. This is as of Release 10, Alpha 15.3 of the toolkit wrapper and happens on both Windows ([http://forums.bukkit.org/threads/console-format-issue.205024/ example]) and Unix (my own) ([https://forums.bukkit.org/threads/weird-multicraft-bukkit-error.127851/ example 2]).&lt;br /&gt;
&lt;br /&gt;
== Restart required ==&lt;br /&gt;
&lt;br /&gt;
If you use PermissionsBukkit with McMyAdmin, if you make a change you normally need to restart the Minecraft server to get it to see the changes. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;huge&#039;&#039;&#039; advantage of setting the Permissions Export to PermissionsEx is when a permission is added to McMyAdmin it automatically reloads the configuration, this is shown in the console by:&lt;br /&gt;
&lt;br /&gt;
[INFO] Permissions file successfully reloaded&amp;lt;br&amp;gt;&lt;br /&gt;
[INFO] Permissions reloaded&lt;br /&gt;
&lt;br /&gt;
If you op or de-op a player from ops.txt and the Administrators group in McMyAdmin.&lt;br /&gt;
&lt;br /&gt;
To set negative permissions in PermissionsEx, use - -permission before the other permissions.&lt;br /&gt;
&lt;br /&gt;
== Restore backup from McMyAdmin ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir BACKUPOFWORLDShhmm&lt;br /&gt;
cp -v world world_nether world_the_end BACKUPOFWORLDShhmm/ -R&lt;br /&gt;
mkdir movedawayworlds&lt;br /&gt;
mv world world_nether world_the_end movedawayworlds&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restore the backup via the McMyAdmin control panel.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To check when a player was last online, their IP address, what world they are in, do:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
/seen playername&lt;br /&gt;
&lt;br /&gt;
Useful:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -xr mcmonitor&lt;br /&gt;
CTRL A + D&lt;br /&gt;
screen -xr mysqlmcmon&lt;br /&gt;
&lt;br /&gt;
cd /home/mc/Minecraft&lt;br /&gt;
cat server.log | grep &amp;quot;YYYY-MM-DD&amp;quot; | grep User | grep -v indestructible&lt;br /&gt;
cat server.log | grep User | grep -v &#039;indestructible\|fell from a high place&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hawkeye ===&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/bukkit-plugins/hawkeye/pages/other-information/usage/ Usage]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Log everything:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Install Hawkeye by doing this manually or through a server control panel. In Unix, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/home/user/Minecraft/plugins/HawkEye# cat config.yml&lt;br /&gt;
&lt;br /&gt;
log:&lt;br /&gt;
  lava-bucket: true&lt;br /&gt;
  pvp-death: true&lt;br /&gt;
  other-death: true&lt;br /&gt;
  chat: true&lt;br /&gt;
  join: true&lt;br /&gt;
  open-container: true&lt;br /&gt;
  container-transaction: true&lt;br /&gt;
  teleport: true&lt;br /&gt;
  sign-place: true&lt;br /&gt;
  sign-break: true&lt;br /&gt;
  flint-steel: true&lt;br /&gt;
  block-place: true&lt;br /&gt;
  block-break: true&lt;br /&gt;
  enderman-pickup: true&lt;br /&gt;
  spawnmob-egg: true&lt;br /&gt;
  crop-trample: true&lt;br /&gt;
general:&lt;br /&gt;
  max-lines: 0&lt;br /&gt;
  log-item-drops-on-death: true&lt;br /&gt;
  cleanse-period: 20m&lt;br /&gt;
  cleanse-age: 0&lt;br /&gt;
  delete-data-on-rollback: true&lt;br /&gt;
  log-ip-addresses: true&lt;br /&gt;
  debug: false&lt;br /&gt;
  debug-level: low&lt;br /&gt;
  max-radius: 0&lt;br /&gt;
  give-user-tool: true&lt;br /&gt;
  tool-block: &#039;17&#039;&lt;br /&gt;
  default-here-radius: 5&lt;br /&gt;
  default-tool-command: &#039;&#039;&lt;br /&gt;
  check-for-updates: true&lt;br /&gt;
  log-delay: 2&lt;br /&gt;
mysql:&lt;br /&gt;
  hawkeye-table: hawkeye&lt;br /&gt;
  port: 3306&lt;br /&gt;
  player-table: hawk_players&lt;br /&gt;
  username: root&lt;br /&gt;
  world-table: hawk_worlds&lt;br /&gt;
  hostname: localhost&lt;br /&gt;
  max-connections: 10&lt;br /&gt;
  password: &#039;InsertMySQLPasswordHere&#039;&lt;br /&gt;
  database: hawkminecraft #you can rename this if you wish&lt;br /&gt;
ignore-worlds:&lt;br /&gt;
- thisworldisignored&lt;br /&gt;
- soisthisone&lt;br /&gt;
command-filter:&lt;br /&gt;
- /login&lt;br /&gt;
- /restartsrv&lt;br /&gt;
- /register&lt;br /&gt;
- /spawn&lt;br /&gt;
block-filter:&lt;br /&gt;
- NONE&lt;br /&gt;
containertransaction-filter:&lt;br /&gt;
  chest: true&lt;br /&gt;
  doublechest: true&lt;br /&gt;
  furnace: true&lt;br /&gt;
  dispenser: true&lt;br /&gt;
version: 1.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database hawkeye;&lt;br /&gt;
show databases;&lt;br /&gt;
use hawkeye&lt;br /&gt;
show tables;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may be empty. If so (more than likely), log into your minecraft server and do /reload. Then go back into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use hawkeye&lt;br /&gt;
show tables;&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| Tables_in_hawkeye       |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
| hawk_players            |&lt;br /&gt;
| hawk_worlds             |&lt;br /&gt;
| hawkeye                 |&lt;br /&gt;
+-------------------------+&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
select * from hawk_worlds;&lt;br /&gt;
select * from hawkeye;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you can now do /hawk in game. To check a block, do /hawk tool , then left click a block and it will show you the block information.&lt;br /&gt;
&lt;br /&gt;
==== Get table structure and players ====&lt;br /&gt;
&lt;br /&gt;
desc hawkeye;&lt;br /&gt;
select * from hawk_players;&lt;br /&gt;
&lt;br /&gt;
==== Look at logs ====&lt;br /&gt;
&lt;br /&gt;
Via a web interface: http://dev.bukkit.org/bukkit-plugins/hawkeye-reload/pages/web-interface-setup/&lt;br /&gt;
&lt;br /&gt;
If you do a search and get this error message you need to re-download the interface:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Error! Unknown column &#039;date&#039; in &#039;where clause&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Via SQL: &lt;br /&gt;
&lt;br /&gt;
select * from hawkeye ORDER BY data_id DESC LIMIT 100000;&lt;br /&gt;
&lt;br /&gt;
== See region information ==&lt;br /&gt;
&lt;br /&gt;
/region info area&lt;br /&gt;
&lt;br /&gt;
It should output something like:&lt;br /&gt;
&lt;br /&gt;
Region: area, type: shape, Priority: X&amp;lt;br&amp;gt;&lt;br /&gt;
Flags: use: ALLOW, mob-spawning: DENY (OR ALLOW)&amp;lt;br&amp;gt;&lt;br /&gt;
Bound: (x) (z)&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftwiki.net/wiki/Server.properties server.properties] file ==&lt;br /&gt;
&lt;br /&gt;
== Set flyspeed ==&lt;br /&gt;
&lt;br /&gt;
Default is 1&lt;br /&gt;
&lt;br /&gt;
For yourself:&lt;br /&gt;
&lt;br /&gt;
/flyspeeed 2&lt;br /&gt;
&lt;br /&gt;
For others:&lt;br /&gt;
&lt;br /&gt;
/flyspeed 2 playername&lt;br /&gt;
&lt;br /&gt;
== Setting spawn ==&lt;br /&gt;
&lt;br /&gt;
On Bywater Craft where we have multiple spawn plugins, to set spawn you need to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/mw setspawn&lt;br /&gt;
/setspawn&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set warps ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/setwarp NewWarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp WarpName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List warps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have per-warp-permission set to true in the config.yml then you can limit what warps players can use. This also controls what players would see with /warp, hence why both essentials.warp and essentials.warp.list are used.&lt;br /&gt;
&lt;br /&gt;
== Set world for SkyGridMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim SkyGrid.jar/config.yml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;world: WorldName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching 09/09/14 - 28/11/14 (old) ==&lt;br /&gt;
&lt;br /&gt;
This was changed as of November 28th 2014: http://www.spigotmc.org/threads/bukkit-craftbukkit-spigot-1-8.36598/&lt;br /&gt;
&lt;br /&gt;
Please now use http://www.spigotmc.org/threads/buildtools-updates-information.42865/ for Minecraft 1.8+&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd ~/spigotwork&lt;br /&gt;
java -jar ~/spigotwork/SpigotPatcher-1.0.jar ~/spigotwork/spigot1649.jar ~/spigotwork/spigot-YYYYMMDDa.bps ~/spigotwork/spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&lt;br /&gt;
rm ../Minecraft/spigot.jar&lt;br /&gt;
mv spigot.jar ../Minecraft/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside the spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;java -jar SpigotPatcher-1.0.jar spigot1649.jar spigot-YYYYMMDD.bps spigot-patched.jar ; mv spigot-patched.jar spigot.jar ; chown user:user spigot.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Spigot patching - new ==&lt;br /&gt;
&lt;br /&gt;
Inside your spigotwork folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir 1.XX-XBuildTools&lt;br /&gt;
rm BuildTools.jar&lt;br /&gt;
wget &amp;quot;https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar&amp;quot; -O BuildTools.jar&lt;br /&gt;
java -jar BuildTools.jar&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If needed run this first outside of McMyAdmin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;exec java -jar spigot.jar --forceUpgrade nogui | tee test.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.minecraftforum.net/videos/view-51785-how-to-synchronize-nether-portals Synchronise Nether Portals] ==&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[http://dev.bukkit.org/server-mods/ascii-bukkit-menu/ ASCII SSH Bukkit Menu] (via screen)&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/Ahtenus/minecraft-init Init script]&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
[[Linux#tmux | Using it]]&lt;br /&gt;
&lt;br /&gt;
http://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen/13954#13954&lt;br /&gt;
&lt;br /&gt;
== Update CraftBukkit ==&lt;br /&gt;
&lt;br /&gt;
Stop the server, then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit.jar versioncraftbukkit.jar&lt;br /&gt;
wget http://dl.bukkit.org/latest-rb/craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or download the development/beta build and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv craftbukkit-dev.jar craftbukkit.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the server&lt;br /&gt;
&lt;br /&gt;
Log out and back into MCMyAdmin.&lt;br /&gt;
&lt;br /&gt;
== World Edit ==&lt;br /&gt;
&lt;br /&gt;
Place .schematic files in /home/user/Minecraft/plugins/WorldEdit/schematics&lt;br /&gt;
&lt;br /&gt;
Import them by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//schematic load filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you can do //paste in Minecraft to paste it into the world where you are.&lt;br /&gt;
&lt;br /&gt;
=== Fill an area ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select position 1 and 2. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//set block&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unbind a tool/block ===&lt;br /&gt;
&lt;br /&gt;
If for example you accidentally do //fill block (e.g. sand), and each time you right click with a tool/block or your hand, clear it by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/none&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== World Guard ==&lt;br /&gt;
&lt;br /&gt;
http://wiki.sk89q.com/wiki/WorldEdit/Selection&lt;br /&gt;
&lt;br /&gt;
https://bukkit.org/threads/worldguard-not-expanding-regions.20974/&lt;br /&gt;
&lt;br /&gt;
To protect an area, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//wand&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then click the first position then the second position with the wooden axe.&lt;br /&gt;
&lt;br /&gt;
If you only do one layer, you can do //expand to go up or down, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;//expand UpValue DownValue up&lt;br /&gt;
//expand 10 0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would expand up 10 blocks from the single layer but do 0 down.&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define newnameforarea owner&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Owner can be left blank.&lt;br /&gt;
&lt;br /&gt;
To get information on the area you just created, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region info newnameforarea&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Allow fire spread/tick ===&lt;br /&gt;
&lt;br /&gt;
In config.yml:&lt;br /&gt;
&lt;br /&gt;
Set high-frequency-flags to true&amp;lt;br&amp;gt;&lt;br /&gt;
Set disable-all-fire-spread to false&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag __global__ fire-spread allow&lt;br /&gt;
/rg flag __global__ lava-fire allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this still doesn&#039;t work, if you have Essentials then set these in config.yml:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fire-spread: true&lt;br /&gt;
lava-fire-spread: true&lt;br /&gt;
flint-fire: true&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Edit world regions from outside (and inside) that world ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w ExactWorldName RegionName FlagName allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to use the blocked-cmds flag and want to block multiple commands separate them by commas:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag -w world MyHome blocked-cmds /tp,/warp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Entry flag for groups ===&lt;br /&gt;
&lt;br /&gt;
Due to inheritance&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag chestroomdoor entry deny&lt;br /&gt;
/rg flag chestroomdoor entry -g nonmembers&lt;br /&gt;
/rg addmember chestroomdoor g:citizen&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets round inheritance by denying all except members from a certain group up the inheritance tree.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you have:&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;vip&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:vip&lt;br /&gt;
/region flag doorway entry -g nonmembers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is not in the vip group for the doorway.&lt;br /&gt;
&lt;br /&gt;
Region name: doorway&amp;lt;br&amp;gt;&lt;br /&gt;
Group name: &#039;&#039;&#039;guest&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Flag: entry deny&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region define doorway&lt;br /&gt;
/region flag doorway entry deny&lt;br /&gt;
/region addmember doorway g:guest&lt;br /&gt;
/region flag doorway entry -g members&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would stop entry to everyone who is in the members field, guest in this case, group for the doorway. Everyone else would be allowed.&lt;br /&gt;
&lt;br /&gt;
Then you&#039;d add the permission node &amp;quot;group.guest&amp;quot; to the guest group in your permissions plugin&#039;s config.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Guest&amp;quot; isn&#039;t a group - http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags#Group&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg removemember chestroomdoor playername&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Group inheritance ====&lt;br /&gt;
&lt;br /&gt;
Important note about the below example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag regionname entry deny&lt;br /&gt;
/rg addmember regionname g:groupname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands should deny entry to groups not added as members or owners.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keep in mind that if you use any inheritance system in your permissions (for example: builder inherits default permissions), any groups that inherit the same permissions as the allowed group will also be allowed entrance to the region.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Your best bet is to eliminate the inheritances and give each group their own group.groupname permission. This allows worldguard to see separate groups.&lt;br /&gt;
&lt;br /&gt;
The same goes with the exit flag.&lt;br /&gt;
&lt;br /&gt;
=== Flint &amp;amp; Steel doesn&#039;t work ===&lt;br /&gt;
&lt;br /&gt;
If it returns the message:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You&#039;re not allowed to use that here&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Do this in-game:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/region flag -w world __global__ lighter allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: http://forums.bukkit.org/threads/i-need-help-with-allowing-flint-steel.152990/&lt;br /&gt;
&lt;br /&gt;
=== Rename region ===&lt;br /&gt;
&lt;br /&gt;
You cannot do this without editing the database manually. If the area is not too big, just remove it and re-add it.&lt;br /&gt;
&lt;br /&gt;
If you do edit the entry in the id column of the region table of the worldguard (by default) database, just do /worldguard reload in-game after you have changed it.&lt;br /&gt;
&lt;br /&gt;
=== Set flags ===&lt;br /&gt;
&lt;br /&gt;
To set flags, see this page: http://wiki.sk89q.com/wiki/WorldGuard/Regions/Flags&lt;br /&gt;
&lt;br /&gt;
To stop building and PvP but to allow use, you would do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/rg flag areaname build deny&lt;br /&gt;
/rg flag areaname pvp deny&lt;br /&gt;
/rg flag areaname use allow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [http://dev.bukkit.org/bukkit-plugins/worldguard-block-restricter WorldGuard Block Restricter] ====&lt;br /&gt;
&lt;br /&gt;
This requires [http://dev.bukkit.org/bukkit-plugins/worldguard-custom-flags WorldGuard Custom Flags] installing too.&lt;br /&gt;
&lt;br /&gt;
To only allow a specific type of block you need to:&lt;br /&gt;
&lt;br /&gt;
* set build allow in WorldGuard: /rg flag areaname build allow&lt;br /&gt;
* then deny all blocks via WorldGuard Block Restricter using /rg flag areaname deny-blocks any&lt;br /&gt;
* then allow the blocks you want via WorldGuard Block Restricter using /rg flag areaname allow-blocks dirt&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1139</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1139"/>
		<updated>2019-07-08T10:13:44Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== Clear last login info ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1138</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1138"/>
		<updated>2019-07-08T10:13:17Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* CLI/bash Commands and scripting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== ==&lt;br /&gt;
&lt;br /&gt;
[https://www.cyberciti.biz/faq/howto-display-clear-last-login-information/ Clear last login info]&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1137</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1137"/>
		<updated>2019-06-26T15:05:11Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Mount NFS drive */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&amp;lt;br&amp;gt;&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&amp;lt;br&amp;gt;&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1136</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1136"/>
		<updated>2019-06-26T15:04:45Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Move files into your home directory not owned by your own user */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount NFS drive ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install nfs-common&lt;br /&gt;
cd /media&lt;br /&gt;
mount -t nfs HostName:/export/ftpbackup/ServiceName /FolderMount&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above contains variables, which you will need to substitute with your own values.&lt;br /&gt;
&lt;br /&gt;
HostName: The host name of your backup storage&lt;br /&gt;
ServiceName: The name of your server (e.g. ns0000000.ip-123-123-123.net)&lt;br /&gt;
FolderMount: The folder where you want to mount the NFS share&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
mount -t nfs ftpback-xxx1-123.ovh.net:/export/ftpbackup/ns123456.ip-XX-XXX-XXX.eu /media/YourNewFolder&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Useful_Tools_and_Links&amp;diff=1135</id>
		<title>Useful Tools and Links</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Useful_Tools_and_Links&amp;diff=1135"/>
		<updated>2019-06-25T15:41:24Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Security */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== DNS ==&lt;br /&gt;
&lt;br /&gt;
* [http://mxtoolbox.com/SuperTool.aspx/ Super Tool]&lt;br /&gt;
* [http://dns.squish.net/ Live Traversal]&lt;br /&gt;
* [http://www.intodns.com/ Report]&lt;br /&gt;
* [http://www.whatsmydns.net/ What&#039;s my DNS]&lt;br /&gt;
* [http://www.dnsqueries.com/en/domain_check.php Health Check]&lt;br /&gt;
* [http://dnscheck.pingdom.com/ Pingdom Check]&lt;br /&gt;
* [http://www.sput.nl/internet/ipv6/chkip6rev.html IPv6 Reverse DNS]&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
* [http://wiki.centos.org/HowTos/Nagios Nagios] - You generally need another server to monitor your target server to use this.&lt;br /&gt;
* [http://www.cacti.net/ Cacti for Networking]&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
&lt;br /&gt;
* [http://network-tools.com Network-Tools.com] (great for checking propagation externally)&lt;br /&gt;
* [http://www.dnsqueries.com/en Extra Network tools]&lt;br /&gt;
* [http://www.pingplotter.com Ping Plotter]&lt;br /&gt;
* [http://www.yougetsignal.com/tools/open-ports/ Port Scanner]&lt;br /&gt;
&lt;br /&gt;
== Performance ==&lt;br /&gt;
&lt;br /&gt;
* [http://tools.pingdom.com/fpt/ Ping and trace route your domain/IP address]&lt;br /&gt;
* Get a performance report of your domain: [http://gtmetrix.com Tool 1] | [http://www.webpagetest.org Tool 2]&lt;br /&gt;
* [[Error Logging]]&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.unmaskparasites.com/ Website Security Check 1]&lt;br /&gt;
* [http://sitecheck.sucuri.net/scanner/ Website Security Check 2]&lt;br /&gt;
* [http://www.codeproject.com/Articles/42434/Webserver-Security-Check General Webserver Check]&lt;br /&gt;
* [http://www.rfxn.com/projects/linux-malware-detect/ Linux Malware Detect]&lt;br /&gt;
* [http://www.passwordmeter.com Password Strength Test]&lt;br /&gt;
* [https://www.securitymetrics.com/portscan.adp Port Scan]&lt;br /&gt;
* [http://sectools.org/ Security Tools]&lt;br /&gt;
* [http://strongpasswordgenerator.com Strong Password Generator]&lt;br /&gt;
* [https://www.safetydetective.com/blog/free-security-tools-that-you-need-to-start-using-now/ Free Security Tools]&lt;br /&gt;
&lt;br /&gt;
== SSL ==&lt;br /&gt;
&lt;br /&gt;
* [https://www.ssllabs.com/ssltest/index.html SSLLabs SSL Checker]&lt;br /&gt;
* [https://www.sslshopper.com/certificate-key-matcher.html Check if Certicate and Private Key match]&lt;br /&gt;
* [http://www.sslshopper.com/ssl-checker.html/ SSL-Checker]&lt;br /&gt;
* [http://www.sslshopper.com/certificate-decoder.html SSL Certificate Decoder]&lt;br /&gt;
* [http://support.citrix.com/article/CTX124783 PKCS to PEM converter]&lt;br /&gt;
* [https://www.sslshopper.com/ssl-converter.html SSL Converter]&lt;br /&gt;
&lt;br /&gt;
== Spam ==&lt;br /&gt;
&lt;br /&gt;
* [http://whatismyipaddress.com/blacklist-check Blacklist Check 1]&lt;br /&gt;
* [http://mxtoolbox.com/blacklists.aspx Blacklist Check 2]&lt;br /&gt;
* [http://www.blacklistalert.org/ Blacklist Check 3]&lt;br /&gt;
&lt;br /&gt;
[[Spam_Help | Help with Spam]]&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* [http://tools.whois.net/whoisbyip WHOIS IP]&lt;br /&gt;
* [http://multirbl.valli.org IP Check for sending mailservers]&lt;br /&gt;
* [http://validator.w3.org/checklink Broken Link Scanner]&lt;br /&gt;
* [http://uptime.netcraft.com/up/graph What&#039;s That Site Running]&lt;br /&gt;
* [http://www.basekit.com/ Build a Website]&lt;br /&gt;
* [http://www.connectionstrings.com Connection Strings]&lt;br /&gt;
* [http://error101.co.uk Error 101]&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Useful_Tools_and_Links&amp;diff=1134</id>
		<title>Useful Tools and Links</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Useful_Tools_and_Links&amp;diff=1134"/>
		<updated>2019-06-25T15:41:05Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== DNS ==&lt;br /&gt;
&lt;br /&gt;
* [http://mxtoolbox.com/SuperTool.aspx/ Super Tool]&lt;br /&gt;
* [http://dns.squish.net/ Live Traversal]&lt;br /&gt;
* [http://www.intodns.com/ Report]&lt;br /&gt;
* [http://www.whatsmydns.net/ What&#039;s my DNS]&lt;br /&gt;
* [http://www.dnsqueries.com/en/domain_check.php Health Check]&lt;br /&gt;
* [http://dnscheck.pingdom.com/ Pingdom Check]&lt;br /&gt;
* [http://www.sput.nl/internet/ipv6/chkip6rev.html IPv6 Reverse DNS]&lt;br /&gt;
&lt;br /&gt;
== Monitoring ==&lt;br /&gt;
&lt;br /&gt;
* [http://wiki.centos.org/HowTos/Nagios Nagios] - You generally need another server to monitor your target server to use this.&lt;br /&gt;
* [http://www.cacti.net/ Cacti for Networking]&lt;br /&gt;
&lt;br /&gt;
== Network ==&lt;br /&gt;
&lt;br /&gt;
* [http://network-tools.com Network-Tools.com] (great for checking propagation externally)&lt;br /&gt;
* [http://www.dnsqueries.com/en Extra Network tools]&lt;br /&gt;
* [http://www.pingplotter.com Ping Plotter]&lt;br /&gt;
* [http://www.yougetsignal.com/tools/open-ports/ Port Scanner]&lt;br /&gt;
&lt;br /&gt;
== Performance ==&lt;br /&gt;
&lt;br /&gt;
* [http://tools.pingdom.com/fpt/ Ping and trace route your domain/IP address]&lt;br /&gt;
* Get a performance report of your domain: [http://gtmetrix.com Tool 1] | [http://www.webpagetest.org Tool 2]&lt;br /&gt;
* [[Error Logging]]&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.unmaskparasites.com/ Website Security Check 1]&lt;br /&gt;
* [http://sitecheck.sucuri.net/scanner/ Website Security Check 2]&lt;br /&gt;
* [http://www.codeproject.com/Articles/42434/Webserver-Security-Check General Webserver Check]&lt;br /&gt;
* [http://www.rfxn.com/projects/linux-malware-detect/ Linux Malware Detect]&lt;br /&gt;
* [http://www.passwordmeter.com Password Strength Test]&lt;br /&gt;
* [https://www.securitymetrics.com/portscan.adp Port Scan]&lt;br /&gt;
* [http://sectools.org/ Security Tools]&lt;br /&gt;
* [http://strongpasswordgenerator.com Strong Password Generator]&lt;br /&gt;
* [https://www.safetydetective.com/blog/free-security-tools-that-you-need-to-start-using-now/]&lt;br /&gt;
&lt;br /&gt;
== SSL ==&lt;br /&gt;
&lt;br /&gt;
* [https://www.ssllabs.com/ssltest/index.html SSLLabs SSL Checker]&lt;br /&gt;
* [https://www.sslshopper.com/certificate-key-matcher.html Check if Certicate and Private Key match]&lt;br /&gt;
* [http://www.sslshopper.com/ssl-checker.html/ SSL-Checker]&lt;br /&gt;
* [http://www.sslshopper.com/certificate-decoder.html SSL Certificate Decoder]&lt;br /&gt;
* [http://support.citrix.com/article/CTX124783 PKCS to PEM converter]&lt;br /&gt;
* [https://www.sslshopper.com/ssl-converter.html SSL Converter]&lt;br /&gt;
&lt;br /&gt;
== Spam ==&lt;br /&gt;
&lt;br /&gt;
* [http://whatismyipaddress.com/blacklist-check Blacklist Check 1]&lt;br /&gt;
* [http://mxtoolbox.com/blacklists.aspx Blacklist Check 2]&lt;br /&gt;
* [http://www.blacklistalert.org/ Blacklist Check 3]&lt;br /&gt;
&lt;br /&gt;
[[Spam_Help | Help with Spam]]&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* [http://tools.whois.net/whoisbyip WHOIS IP]&lt;br /&gt;
* [http://multirbl.valli.org IP Check for sending mailservers]&lt;br /&gt;
* [http://validator.w3.org/checklink Broken Link Scanner]&lt;br /&gt;
* [http://uptime.netcraft.com/up/graph What&#039;s That Site Running]&lt;br /&gt;
* [http://www.basekit.com/ Build a Website]&lt;br /&gt;
* [http://www.connectionstrings.com Connection Strings]&lt;br /&gt;
* [http://error101.co.uk Error 101]&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1133</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1133"/>
		<updated>2019-06-18T10:50:27Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* .bashrc */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bash_history ==&lt;br /&gt;
&lt;br /&gt;
Change Epoch time in .bash_history:&lt;br /&gt;
&lt;br /&gt;
https://askubuntu.com/questions/391082/how-to-see-time-stamps-in-bash-history/391087&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1132</id>
		<title>Resource Usage</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1132"/>
		<updated>2019-06-17T11:49:19Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* General Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Disk Usage ==&lt;br /&gt;
&lt;br /&gt;
Note: If you have a file/files open and your disk space appears full, do a reboot and it will close the open file/s. This is a true indication of disk space then.&lt;br /&gt;
&lt;br /&gt;
To check overall disk usage run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h&lt;br /&gt;
df -h&lt;br /&gt;
df -h | grep -v &#039;loop\|nas\|/run/\|tmpfs\|udev&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h --max-depth=1 | grep G&lt;br /&gt;
du -kh | grep G&lt;br /&gt;
du -khs * | grep G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using grep looks down one directory and looks for GB disk usage, use M for MB, K for KB.&amp;lt;br&amp;gt;&lt;br /&gt;
*To dive down more directories change the max depth value.&lt;br /&gt;
&lt;br /&gt;
Use the below command to show number of files in target directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -1 target|wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Inodes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -i&lt;br /&gt;
find . -xdev -type f | cut -d &amp;quot;/&amp;quot; -f 2 | sort | uniq -c | sort -n&lt;br /&gt;
cd /directory that is the largest&lt;br /&gt;
#run find command again&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disk check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install smartmontools&lt;br /&gt;
smartctl -H /dev/sda&lt;br /&gt;
smartctl -A /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will check the health of the hard drive. If you use RAID the software may not be able to pick it up. If you are getting errors, check you know what your HDD type you have by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl --scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do not trust df, to check the HDDs use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fdisk -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server uses SCSI, you may need to the following each time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl -d scsi /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternative is mdadm but be careful, do not install it unless you know what you are doing as it will prompt you with questions via a GUI straight away.&lt;br /&gt;
&lt;br /&gt;
=== Empty a file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; /file/path&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This always exits true, but produces no output. Good for large old log files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;More complicated options&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*Changing the second n option specifies the amount of results you want to show.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du --max-depth=1|sort -nr|head -n10 #this prints out the largest value at the top&lt;br /&gt;
du --max-depth=1|sort -n|tail -n5 #this prints out the largest value at the bottom&lt;br /&gt;
&lt;br /&gt;
du --max-depth=20|sort -nr|head -n20&amp;gt;diskusage.txt #this outputs the top 20 results into a file&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1|sort -nr|tail -n10 #this prints out the smallest value at the bottom, good for temp directories&lt;br /&gt;
du --max-depth=1|sort -n|head -n10 #this prints out the smallest value at the top&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1 -h * |sort -n -k 1 |egrep &#039;M|G&#039;&lt;br /&gt;
du -sh *&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/&lt;br /&gt;
&lt;br /&gt;
If the server is Windows, you can use Performance monitor which is built into Windows to run on the server to monitor free space along with disk read/writes. You may wish to install http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx as it will provide a greater overview as to what is writing to the server and when.&lt;br /&gt;
&lt;br /&gt;
If there is a program writing to the temporary directory it may be putting the files in there and then removing them once they are finished being used hence the fluctuation.&lt;br /&gt;
&lt;br /&gt;
=== NCDU ===&lt;br /&gt;
&lt;br /&gt;
A useful tool for Unix is called ncdu: &amp;quot;NCurses Disk Usage&amp;quot;.&lt;br /&gt;
https://linux.die.net/man/1/ncdu&lt;br /&gt;
&lt;br /&gt;
This allows you to discover the overall usage, please note this can take a while depending on the amount of data you have.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From root (cd /) run one of the following commands to install and run ncdu:&lt;br /&gt;
&lt;br /&gt;
CentOS (you may need to enable the EPEL repository):&lt;br /&gt;
&amp;lt;pre&amp;gt;yum search ncdu&lt;br /&gt;
yum install ncdu.x86_64&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install ncdu&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exlcuding a directory in ncdu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ncdu --exclude /home/mc/Minecraft/plugins/dynmap/web/tiles/world&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Truncate ===&lt;br /&gt;
&lt;br /&gt;
You can truncate files via SSH:&lt;br /&gt;
&lt;br /&gt;
truncate -s 0 myfile.txt&lt;br /&gt;
&lt;br /&gt;
Progressive truncation just uses different parameters for -s (size). For instance, -s 100G or -s 100M.&lt;br /&gt;
&lt;br /&gt;
Echo is another tool that can truncate a file.&lt;br /&gt;
&lt;br /&gt;
echo &amp;gt; myfile.txt&lt;br /&gt;
&lt;br /&gt;
Useful commands on home NAS&#039; when it hangs when deleting extremely large files via SSH or UI.&lt;br /&gt;
&lt;br /&gt;
== General Usage ==&lt;br /&gt;
&lt;br /&gt;
iotop&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt install sysstat&lt;br /&gt;
iotop&lt;br /&gt;
iostat | grep -v loop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://htop.sourceforge.net/index.php?page=faq htop FAQ]&lt;br /&gt;
&lt;br /&gt;
On Linux:&lt;br /&gt;
&amp;lt;pre&amp;gt;top&lt;br /&gt;
apt-get install htop&lt;br /&gt;
#or&lt;br /&gt;
yum install htop&lt;br /&gt;
#then&lt;br /&gt;
htop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
apt-get install goaccess&lt;br /&gt;
&lt;br /&gt;
Also look at http://serverkb.co.uk/wiki/Scripts&lt;br /&gt;
&lt;br /&gt;
On Windows use Task Manager and Performance Monitor.&lt;br /&gt;
&lt;br /&gt;
Munin and Graphite are good for system management.&lt;br /&gt;
&lt;br /&gt;
== Memory available ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Display the top ten running processes - sorted by memory usage:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
ps aux --sort -rss | head&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;free -m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows you the available and currently used memory (RAM) in MB. So 1900-2000 is 1-2GB. On a Shared/VPS environment normally half the Total and you get your Soft Limit (guaranteed), the full amount is your Hard Limit (burstable, not guaranteed).&lt;br /&gt;
&lt;br /&gt;
cat /proc/user_beancounters &lt;br /&gt;
&lt;br /&gt;
You will see something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Version: 2.5&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  | barrier               limit                        |      failcnt&lt;br /&gt;
328178:    kmemsize         |  4348996  | 4366996  | 16384000              18022400                     |           0&lt;br /&gt;
           lockedpages      |  0        |       0  | 4096                  4096                         |           0&lt;br /&gt;
           privvmpages      |  68233    |   68262  | 153600                153600                       |       34995&lt;br /&gt;
&lt;br /&gt;
or for example on an 8GB of RAM server:&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  barrier               limit                          |    failcnt&lt;br /&gt;
506378:    kmemsize         |  62055413 | 62490301 9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           lockedpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           privvmpages      |  384054   |  384315  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dummy            |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numproc          |  205      |     208  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           physpages        |  119511   |  119641  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           vmguarpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           oomguarpages     |  119513   |  119643  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numtcpsock       |  34       |      36  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numflock         |  21       |      23  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numpty           |  1        |       1  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numsiginfo       |  4        |       5  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcpsndbuf        |  601840   |  648400  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcprcvbuf        |  557056   |  589824  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           othersockbuf     |  2132376  | 2133680  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dgramrcvbuf      |  0        |    2608  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numothersock     |  947      |     949  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dcachesize       |  3301507  | 3312775  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numfile          |  20555    |   20630  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numiptent        |  15       |      15  9223372036854775807   9223372036854775807            |         0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take a look at the numbers left to the first Pipe (|) in the held column: These stand for the actual usage. Right of the last pipe: Failcounts. Having failcounts inidicates that a service is consuming all the ram.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1131</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1131"/>
		<updated>2019-06-13T10:17:19Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* read */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need the -n for echo to allow input next to echo instead of a line below.&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1130</id>
		<title>Resource Usage</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1130"/>
		<updated>2019-06-12T08:08:55Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Disk Usage ==&lt;br /&gt;
&lt;br /&gt;
Note: If you have a file/files open and your disk space appears full, do a reboot and it will close the open file/s. This is a true indication of disk space then.&lt;br /&gt;
&lt;br /&gt;
To check overall disk usage run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h&lt;br /&gt;
df -h&lt;br /&gt;
df -h | grep -v &#039;loop\|nas\|/run/\|tmpfs\|udev&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h --max-depth=1 | grep G&lt;br /&gt;
du -kh | grep G&lt;br /&gt;
du -khs * | grep G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using grep looks down one directory and looks for GB disk usage, use M for MB, K for KB.&amp;lt;br&amp;gt;&lt;br /&gt;
*To dive down more directories change the max depth value.&lt;br /&gt;
&lt;br /&gt;
Use the below command to show number of files in target directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -1 target|wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Inodes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -i&lt;br /&gt;
find . -xdev -type f | cut -d &amp;quot;/&amp;quot; -f 2 | sort | uniq -c | sort -n&lt;br /&gt;
cd /directory that is the largest&lt;br /&gt;
#run find command again&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disk check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install smartmontools&lt;br /&gt;
smartctl -H /dev/sda&lt;br /&gt;
smartctl -A /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will check the health of the hard drive. If you use RAID the software may not be able to pick it up. If you are getting errors, check you know what your HDD type you have by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl --scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do not trust df, to check the HDDs use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fdisk -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server uses SCSI, you may need to the following each time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl -d scsi /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternative is mdadm but be careful, do not install it unless you know what you are doing as it will prompt you with questions via a GUI straight away.&lt;br /&gt;
&lt;br /&gt;
=== Empty a file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; /file/path&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This always exits true, but produces no output. Good for large old log files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;More complicated options&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*Changing the second n option specifies the amount of results you want to show.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du --max-depth=1|sort -nr|head -n10 #this prints out the largest value at the top&lt;br /&gt;
du --max-depth=1|sort -n|tail -n5 #this prints out the largest value at the bottom&lt;br /&gt;
&lt;br /&gt;
du --max-depth=20|sort -nr|head -n20&amp;gt;diskusage.txt #this outputs the top 20 results into a file&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1|sort -nr|tail -n10 #this prints out the smallest value at the bottom, good for temp directories&lt;br /&gt;
du --max-depth=1|sort -n|head -n10 #this prints out the smallest value at the top&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1 -h * |sort -n -k 1 |egrep &#039;M|G&#039;&lt;br /&gt;
du -sh *&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/&lt;br /&gt;
&lt;br /&gt;
If the server is Windows, you can use Performance monitor which is built into Windows to run on the server to monitor free space along with disk read/writes. You may wish to install http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx as it will provide a greater overview as to what is writing to the server and when.&lt;br /&gt;
&lt;br /&gt;
If there is a program writing to the temporary directory it may be putting the files in there and then removing them once they are finished being used hence the fluctuation.&lt;br /&gt;
&lt;br /&gt;
=== NCDU ===&lt;br /&gt;
&lt;br /&gt;
A useful tool for Unix is called ncdu: &amp;quot;NCurses Disk Usage&amp;quot;.&lt;br /&gt;
https://linux.die.net/man/1/ncdu&lt;br /&gt;
&lt;br /&gt;
This allows you to discover the overall usage, please note this can take a while depending on the amount of data you have.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From root (cd /) run one of the following commands to install and run ncdu:&lt;br /&gt;
&lt;br /&gt;
CentOS (you may need to enable the EPEL repository):&lt;br /&gt;
&amp;lt;pre&amp;gt;yum search ncdu&lt;br /&gt;
yum install ncdu.x86_64&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install ncdu&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exlcuding a directory in ncdu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ncdu --exclude /home/mc/Minecraft/plugins/dynmap/web/tiles/world&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Truncate ===&lt;br /&gt;
&lt;br /&gt;
You can truncate files via SSH:&lt;br /&gt;
&lt;br /&gt;
truncate -s 0 myfile.txt&lt;br /&gt;
&lt;br /&gt;
Progressive truncation just uses different parameters for -s (size). For instance, -s 100G or -s 100M.&lt;br /&gt;
&lt;br /&gt;
Echo is another tool that can truncate a file.&lt;br /&gt;
&lt;br /&gt;
echo &amp;gt; myfile.txt&lt;br /&gt;
&lt;br /&gt;
Useful commands on home NAS&#039; when it hangs when deleting extremely large files via SSH or UI.&lt;br /&gt;
&lt;br /&gt;
== General Usage ==&lt;br /&gt;
&lt;br /&gt;
[http://htop.sourceforge.net/index.php?page=faq htop FAQ]&lt;br /&gt;
&lt;br /&gt;
On Linux:&lt;br /&gt;
&amp;lt;pre&amp;gt;top&lt;br /&gt;
apt-get install htop&lt;br /&gt;
#or&lt;br /&gt;
yum install htop&lt;br /&gt;
#then&lt;br /&gt;
htop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
apt-get install goaccess&lt;br /&gt;
&lt;br /&gt;
Also look at http://serverkb.co.uk/wiki/Scripts&lt;br /&gt;
&lt;br /&gt;
On Windows use Task Manager and Performance Monitor.&lt;br /&gt;
&lt;br /&gt;
Munin and Graphite are good for system management.&lt;br /&gt;
&lt;br /&gt;
== Memory available ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Display the top ten running processes - sorted by memory usage:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
ps aux --sort -rss | head&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;free -m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows you the available and currently used memory (RAM) in MB. So 1900-2000 is 1-2GB. On a Shared/VPS environment normally half the Total and you get your Soft Limit (guaranteed), the full amount is your Hard Limit (burstable, not guaranteed).&lt;br /&gt;
&lt;br /&gt;
cat /proc/user_beancounters &lt;br /&gt;
&lt;br /&gt;
You will see something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Version: 2.5&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  | barrier               limit                        |      failcnt&lt;br /&gt;
328178:    kmemsize         |  4348996  | 4366996  | 16384000              18022400                     |           0&lt;br /&gt;
           lockedpages      |  0        |       0  | 4096                  4096                         |           0&lt;br /&gt;
           privvmpages      |  68233    |   68262  | 153600                153600                       |       34995&lt;br /&gt;
&lt;br /&gt;
or for example on an 8GB of RAM server:&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  barrier               limit                          |    failcnt&lt;br /&gt;
506378:    kmemsize         |  62055413 | 62490301 9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           lockedpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           privvmpages      |  384054   |  384315  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dummy            |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numproc          |  205      |     208  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           physpages        |  119511   |  119641  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           vmguarpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           oomguarpages     |  119513   |  119643  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numtcpsock       |  34       |      36  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numflock         |  21       |      23  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numpty           |  1        |       1  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numsiginfo       |  4        |       5  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcpsndbuf        |  601840   |  648400  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcprcvbuf        |  557056   |  589824  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           othersockbuf     |  2132376  | 2133680  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dgramrcvbuf      |  0        |    2608  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numothersock     |  947      |     949  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dcachesize       |  3301507  | 3312775  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numfile          |  20555    |   20630  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numiptent        |  15       |      15  9223372036854775807   9223372036854775807            |         0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take a look at the numbers left to the first Pipe (|) in the held column: These stand for the actual usage. Right of the last pipe: Failcounts. Having failcounts inidicates that a service is consuming all the ram.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1129</id>
		<title>Resource Usage</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Resource_Usage&amp;diff=1129"/>
		<updated>2019-06-12T08:07:33Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Disk Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Disk Usage ==&lt;br /&gt;
&lt;br /&gt;
Note: If you have a file/files open and your disk space appears full, do a reboot and it will close the open file/s. This is a true indication of disk space then.&lt;br /&gt;
&lt;br /&gt;
To check overall disk usage run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h&lt;br /&gt;
df -h&lt;br /&gt;
du -h --max-depth=1 | grep G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du -h --max-depth=1 | grep G&lt;br /&gt;
du -kh | grep G&lt;br /&gt;
du -khs * | grep G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using grep looks down one directory and looks for GB disk usage, use M for MB, K for KB.&amp;lt;br&amp;gt;&lt;br /&gt;
*To dive down more directories change the max depth value.&lt;br /&gt;
&lt;br /&gt;
Use the below command to show number of files in target directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -1 target|wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Inodes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -i&lt;br /&gt;
find . -xdev -type f | cut -d &amp;quot;/&amp;quot; -f 2 | sort | uniq -c | sort -n&lt;br /&gt;
cd /directory that is the largest&lt;br /&gt;
#run find command again&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disk check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install smartmontools&lt;br /&gt;
smartctl -H /dev/sda&lt;br /&gt;
smartctl -A /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will check the health of the hard drive. If you use RAID the software may not be able to pick it up. If you are getting errors, check you know what your HDD type you have by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl --scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do not trust df, to check the HDDs use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;fdisk -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server uses SCSI, you may need to the following each time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;smartctl -d scsi /dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternative is mdadm but be careful, do not install it unless you know what you are doing as it will prompt you with questions via a GUI straight away.&lt;br /&gt;
&lt;br /&gt;
=== Empty a file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:&amp;gt; /file/path&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This always exits true, but produces no output. Good for large old log files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;More complicated options&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*Changing the second n option specifies the amount of results you want to show.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;du --max-depth=1|sort -nr|head -n10 #this prints out the largest value at the top&lt;br /&gt;
du --max-depth=1|sort -n|tail -n5 #this prints out the largest value at the bottom&lt;br /&gt;
&lt;br /&gt;
du --max-depth=20|sort -nr|head -n20&amp;gt;diskusage.txt #this outputs the top 20 results into a file&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1|sort -nr|tail -n10 #this prints out the smallest value at the bottom, good for temp directories&lt;br /&gt;
du --max-depth=1|sort -n|head -n10 #this prints out the smallest value at the top&lt;br /&gt;
&lt;br /&gt;
du --max-depth=1 -h * |sort -n -k 1 |egrep &#039;M|G&#039;&lt;br /&gt;
du -sh *&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/&lt;br /&gt;
&lt;br /&gt;
If the server is Windows, you can use Performance monitor which is built into Windows to run on the server to monitor free space along with disk read/writes. You may wish to install http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx as it will provide a greater overview as to what is writing to the server and when.&lt;br /&gt;
&lt;br /&gt;
If there is a program writing to the temporary directory it may be putting the files in there and then removing them once they are finished being used hence the fluctuation.&lt;br /&gt;
&lt;br /&gt;
=== NCDU ===&lt;br /&gt;
&lt;br /&gt;
A useful tool for Unix is called ncdu: &amp;quot;NCurses Disk Usage&amp;quot;.&lt;br /&gt;
https://linux.die.net/man/1/ncdu&lt;br /&gt;
&lt;br /&gt;
This allows you to discover the overall usage, please note this can take a while depending on the amount of data you have.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From root (cd /) run one of the following commands to install and run ncdu:&lt;br /&gt;
&lt;br /&gt;
CentOS (you may need to enable the EPEL repository):&lt;br /&gt;
&amp;lt;pre&amp;gt;yum search ncdu&lt;br /&gt;
yum install ncdu.x86_64&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install ncdu&lt;br /&gt;
cd / #or the directory you want to check&lt;br /&gt;
ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exlcuding a directory in ncdu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ncdu --exclude /home/mc/Minecraft/plugins/dynmap/web/tiles/world&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Truncate ===&lt;br /&gt;
&lt;br /&gt;
You can truncate files via SSH:&lt;br /&gt;
&lt;br /&gt;
truncate -s 0 myfile.txt&lt;br /&gt;
&lt;br /&gt;
Progressive truncation just uses different parameters for -s (size). For instance, -s 100G or -s 100M.&lt;br /&gt;
&lt;br /&gt;
Echo is another tool that can truncate a file.&lt;br /&gt;
&lt;br /&gt;
echo &amp;gt; myfile.txt&lt;br /&gt;
&lt;br /&gt;
Useful commands on home NAS&#039; when it hangs when deleting extremely large files via SSH or UI.&lt;br /&gt;
&lt;br /&gt;
== General Usage ==&lt;br /&gt;
&lt;br /&gt;
[http://htop.sourceforge.net/index.php?page=faq htop FAQ]&lt;br /&gt;
&lt;br /&gt;
On Linux:&lt;br /&gt;
&amp;lt;pre&amp;gt;top&lt;br /&gt;
apt-get install htop&lt;br /&gt;
#or&lt;br /&gt;
yum install htop&lt;br /&gt;
#then&lt;br /&gt;
htop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
apt-get install goaccess&lt;br /&gt;
&lt;br /&gt;
Also look at http://serverkb.co.uk/wiki/Scripts&lt;br /&gt;
&lt;br /&gt;
On Windows use Task Manager and Performance Monitor.&lt;br /&gt;
&lt;br /&gt;
Munin and Graphite are good for system management.&lt;br /&gt;
&lt;br /&gt;
== Memory available ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Display the top ten running processes - sorted by memory usage:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
ps aux --sort -rss | head&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;free -m&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows you the available and currently used memory (RAM) in MB. So 1900-2000 is 1-2GB. On a Shared/VPS environment normally half the Total and you get your Soft Limit (guaranteed), the full amount is your Hard Limit (burstable, not guaranteed).&lt;br /&gt;
&lt;br /&gt;
cat /proc/user_beancounters &lt;br /&gt;
&lt;br /&gt;
You will see something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Version: 2.5&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  | barrier               limit                        |      failcnt&lt;br /&gt;
328178:    kmemsize         |  4348996  | 4366996  | 16384000              18022400                     |           0&lt;br /&gt;
           lockedpages      |  0        |       0  | 4096                  4096                         |           0&lt;br /&gt;
           privvmpages      |  68233    |   68262  | 153600                153600                       |       34995&lt;br /&gt;
&lt;br /&gt;
or for example on an 8GB of RAM server:&lt;br /&gt;
&lt;br /&gt;
uid        resource         |  held     | maxheld  barrier               limit                          |    failcnt&lt;br /&gt;
506378:    kmemsize         |  62055413 | 62490301 9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           lockedpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           privvmpages      |  384054   |  384315  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           shmpages         |  1687     |    1687  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dummy            |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numproc          |  205      |     208  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           physpages        |  119511   |  119641  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           vmguarpages      |  0        |       0  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           oomguarpages     |  119513   |  119643  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numtcpsock       |  34       |      36  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numflock         |  21       |      23  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numpty           |  1        |       1  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numsiginfo       |  4        |       5  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcpsndbuf        |  601840   |  648400  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           tcprcvbuf        |  557056   |  589824  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           othersockbuf     |  2132376  | 2133680  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dgramrcvbuf      |  0        |    2608  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numothersock     |  947      |     949  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           dcachesize       |  3301507  | 3312775  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numfile          |  20555    |   20630  9223372036854775807   9223372036854775807            |         0&lt;br /&gt;
           numiptent        |  15       |      15  9223372036854775807   9223372036854775807            |         0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take a look at the numbers left to the first Pipe (|) in the held column: These stand for the actual usage. Right of the last pipe: Failcounts. Having failcounts inidicates that a service is consuming all the ram.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Scripts&amp;diff=1128</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Scripts&amp;diff=1128"/>
		<updated>2019-06-12T08:00:53Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* betterqmqmtool.sh - http://serverkb.co.uk/tools/betterqmqtool.sh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are located at http://serverkb.co.uk/tools/&lt;br /&gt;
&lt;br /&gt;
Read the README.txt for further information on these tools. The number count below is only counting .sh and .pl files.&lt;br /&gt;
&lt;br /&gt;
All of these can be retrieved by clicking the Topic Header on this page, right clicking the link - Copy Link Address, then do either:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget serverkb.co.uk/tools/linktofile.sh&lt;br /&gt;
wget -O - serverkb.co.uk/tools/linktofile.sh | bash&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== accounts.sh - [http://serverkb.co.uk/tools/accounts.sh Plesk Accounts] ==&lt;br /&gt;
&lt;br /&gt;
The accounts script is only used on Linux servers with Plesk below version 11 (11+ encrypts passwords) and can retrieve Plesk, FTP and email passwords. To use it you need to do the following within [[SSH]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/accounts.sh ; chmod +x accounts.sh&lt;br /&gt;
./accounts.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Written by Leon_Teale, modified by Byron Galietta and Sam Teale. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== advancedmonitor.sh - [http://serverkb.co.uk/tools/advancedmonitor.sh Advanced Service Monitor] ==&lt;br /&gt;
&lt;br /&gt;
This is a more advanced version a previous service monitor script , giving more output and debug possibilities.&lt;br /&gt;
&lt;br /&gt;
This script will monitor and start/restart a specific service that you specify. By default it will do Apache, the Linux web server. To use it, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / root ; wget http://serverkb.co.uk/tools/advancedmonitor.sh ; chmod +x advancedmonitor.sh&lt;br /&gt;
crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In here add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;10 * * * * /root/advancedmonitor.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace the admin email address with yours by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim advancedmonitor.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace apache2 with httpd within it if your server calls Apache httpd instead.&lt;br /&gt;
&lt;br /&gt;
To start another service edit the following field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service=&amp;quot;apache2&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example for MySQL have service=&amp;quot;mysql&amp;quot; instead (or mysqld)&lt;br /&gt;
&lt;br /&gt;
== betterqmqmtool.sh - http://serverkb.co.uk/tools/betterqmqtool.sh ==&lt;br /&gt;
&lt;br /&gt;
This is just a better version of the well known qmqtool from here: http://jeremy.kister.net/code/qmqtool/files/&lt;br /&gt;
&lt;br /&gt;
qmqtool manages qmail queue&lt;br /&gt;
&lt;br /&gt;
== chrootdbdump.sh - [http://serverkb.co.uk/tools/sqldump.sh SQL Backup for chroot] ==&lt;br /&gt;
&lt;br /&gt;
This backs up databases from a chrooted Linux environment and places them in a folder called /sqlbak&lt;br /&gt;
&lt;br /&gt;
Before using it please do:&lt;br /&gt;
&lt;br /&gt;
chroot /usr/fs&lt;br /&gt;
&lt;br /&gt;
=== chrootdbdumptoemail.sh - [http://serverkb.co.uk/tools/sqldumpmail.sh Email version] ===&lt;br /&gt;
&lt;br /&gt;
== dbdump.sh - [http://serverkb.co.uk/tools/databasedump.sh Backup/dump databases on a Plesk server] ==&lt;br /&gt;
&lt;br /&gt;
This backs up all databases as &#039;&#039;&#039;.sql files and a .tar.gz&#039;&#039;&#039; containing all excluding information_schema, atmail and horde on a &#039;&#039;&#039;Plesk&#039;&#039;&#039; Linux server but does not email you them.&lt;br /&gt;
&lt;br /&gt;
=== dbdumponeemail.sh - [http://serverkb.co.uk/tools/dbdumponeemail.sh Email version] ===&lt;br /&gt;
&lt;br /&gt;
This backs up all databases as &#039;&#039;&#039;.sql files and a .tar.gz&#039;&#039;&#039; containing all .sql excluding information_schema, atmail and horde on a Linux server with the &#039;&#039;&#039;Plesk control but &#039;&#039;&#039;does email you them.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== dbdumpsepemails.sh - [http://serverkb.co.uk/tools/dbdumpsepemails.sh Only .sql files]===&lt;br /&gt;
&lt;br /&gt;
Use this script if you only want .sql files in separate emails and not the extra one with all MySQL databases compressed into a .tar.gz.&lt;br /&gt;
&lt;br /&gt;
For both of the above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install mutt&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;yum install mutt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 755 /sent ; chmod 755 /root/sent&lt;br /&gt;
vim /etc/passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the root user&#039;s home directory to / instead of /root&lt;br /&gt;
&lt;br /&gt;
crontab -e&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;*  * * * 0 :&amp;gt; /root/sent&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A solution may be needed for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;postdrop: warning: uid=0: File too large&lt;br /&gt;
sendmail: fatal: root(0): message file too big&lt;br /&gt;
Error sending message, child exited 75 (Deferred.).&lt;br /&gt;
Could not send the message.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== disablemail.sh - [http://serverkb.co.uk/tools/disablemail.sh Disable mail for multiple domains in Plesk] ==&lt;br /&gt;
&lt;br /&gt;
== disklimit.sh - [http://serverkb.co.uk/tools/disklimit.sh Disk Limit Monitor] ==&lt;br /&gt;
&lt;br /&gt;
This simply notifies you via email when your disk space reaches 90%. To run and install it do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/disklimit.sh ; chmod +x disklimit.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace the ADMIN email address with yours by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim disklimit.sh&lt;br /&gt;
crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In here add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;45 * * * * /root/disklimit.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== domaintoip.sh - [http://serverkb.co.uk/tools/domaintoip.sh Domain to IP conversion] ==&lt;br /&gt;
&lt;br /&gt;
This finds the IP addresses for all domains in /var/www/vhosts (this path can be edited) and outputs the results to screen and a file.&lt;br /&gt;
&lt;br /&gt;
== doswatchauto.sh - http://serverkb.co.uk/tools/doswatchauto.sh ==&lt;br /&gt;
&lt;br /&gt;
This tool is used to monitor an IP address on your server for traffic directed towards a specific service.&lt;br /&gt;
&lt;br /&gt;
== doswatchmanual.sh - http://serverkb.co.uk/tools/doswatchmanual.sh ==&lt;br /&gt;
&lt;br /&gt;
This tool is used to monitor an IP address on your server for traffic directed towards Apache.&lt;br /&gt;
&lt;br /&gt;
== epel.sh - [http://serverkb.co.uk/tools/epel.sh Enable the EPEL repository] ==&lt;br /&gt;
&lt;br /&gt;
This will take into account if the Operating System is CentOS or Ubuntu.&lt;br /&gt;
&lt;br /&gt;
== extralogging.sh - [http://serverkb.co.uk/tools/extralogging.sh Extra Logging V.1] ==&lt;br /&gt;
&lt;br /&gt;
=== extralogging2.sh - [http://serverkb.co.uk/tools/extralogging2.sh Extra Logging V.1] ===&lt;br /&gt;
&lt;br /&gt;
For Plesk servers.&lt;br /&gt;
&lt;br /&gt;
== findnameserver.sh - [http://serverkb.co.uk/tools/findnameserver.sh Nameserver checker for a list of domains] ==&lt;br /&gt;
&lt;br /&gt;
== findregistrar.sh - [http://serverkb.co.uk/tools/findregistrar.sh Registrar finder on Plesk servers] ==&lt;br /&gt;
&lt;br /&gt;
Once edited with the registrar of your choice this will get the list of your domains and look up the domain registar. If it matches then it will place these in a file in the same directory you are in called our_registrar. Some server configuration has to be done first which can be found here: http://serverkb.co.uk/wiki/Linux#WHOIS_script&lt;br /&gt;
&lt;br /&gt;
== getdnsrec.sh - [http://serverkb.co.uk/tools/getdns.sh Retrieve all DNS from nameservers] ==&lt;br /&gt;
&lt;br /&gt;
== load.sh - [http://serverkb.co.uk/tools/load.sh Load and Domain access checker] ==&lt;br /&gt;
&lt;br /&gt;
Shows the load and any domains that are currently being accessed (live) on a Plesk server.&lt;br /&gt;
&lt;br /&gt;
== Mail Queue Count and Mail Warning (15 + 16) ==&lt;br /&gt;
&lt;br /&gt;
These go together.&lt;br /&gt;
&lt;br /&gt;
[http://serverkb.co.uk/tools/mailqueuecount.sh mailqueuecount.sh] gets a queue status once a day.&amp;lt;br&amp;gt;&lt;br /&gt;
[http://serverkb.co.uk/tools/mailwarning.sh mailwarning.sh] runs every five minutes and will email you if your qmail mail queue is over the limit you set within it.&lt;br /&gt;
&lt;br /&gt;
== mcrypt.sh - [http://serverkb.co.uk/tools/mcrypt.sh Install mcrypt] ==&lt;br /&gt;
&lt;br /&gt;
This will install mcrypt on Ubuntu, CentOS 5 or CentOS 6. It will also automatically enable the EPEL repository if needed.&lt;br /&gt;
&lt;br /&gt;
== memcpu.sh - [http://serverkb.co.uk/tools/memcpu.sh Memory + CPU checker] ==&lt;br /&gt;
&lt;br /&gt;
Shows the RAM and CPU usage in the following format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-------Mon Jun 24 19:48:01 BST 2013--------&lt;br /&gt;
PROCESS          %MEM %CPU&lt;br /&gt;
apache      0.0  0.6&lt;br /&gt;
mysql  0.4  2.0&lt;br /&gt;
java            14.1  6.3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== mysqltuner.pl - [http://serverkb.co.uk/tools/mysqltuner.pl MySQL Tuner] ==&lt;br /&gt;
&lt;br /&gt;
This will only review your MySQL setup/performance, it will not make any changes.&lt;br /&gt;
&lt;br /&gt;
wget http://serverkb.co.uk/tools/mysqltuner.pl ; chmod +x ; perl mysqltuner.pl&lt;br /&gt;
&lt;br /&gt;
== nginxmon.sh - [http://serverkb.co.uk/tools/nginxmon.sh Engine X Monitor]==&lt;br /&gt;
&lt;br /&gt;
This is a script to automatically monitor and check the new web server used by Plesk 11+ on Linux servers. To use it, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/nginxmon.sh ; chmod +x nginxmon.sh&lt;br /&gt;
crontab -e&lt;br /&gt;
&lt;br /&gt;
#In here add:&lt;br /&gt;
&lt;br /&gt;
10 * * * * /root/nginxmon.sh&lt;br /&gt;
&lt;br /&gt;
#Edit the file and replace the admin email address with yours by doing:&lt;br /&gt;
&lt;br /&gt;
vim nginxmon.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== oldextralogging.sh - [http://serverkb.co.uk/tools/oldextralog.sh Old Extra Logging] ==&lt;br /&gt;
&lt;br /&gt;
== phptimezone.sh - [http://serverkb.co.uk/tools/phptimezone.sh PHP Timezone correction] ==&lt;br /&gt;
&lt;br /&gt;
This script corrects the PHP5 timezone setting on Debian/Ubuntu and CentOS servers.&lt;br /&gt;
&lt;br /&gt;
== pleskSSLchecker.sh - [http://serverkb.co.uk/tools/pleskSSLchecker.sh Plesk SSL checker] ==&lt;br /&gt;
&lt;br /&gt;
On a Plesk server this will check all SSLs that are in either of the Plesk Domain or Server repositories.&lt;br /&gt;
&lt;br /&gt;
== slow.sh - [http://serverkb.co.uk/tools/slow.sh Slow Query Log for MySQL] ==&lt;br /&gt;
&lt;br /&gt;
HN&lt;br /&gt;
&amp;lt;!-- usermod -G mysql user&lt;br /&gt;
&lt;br /&gt;
ln -s /var/log/mysql/mysql-slow-query.log /var/www/vhosts/website.co.uk/statistics/logs/mysql-slow-query.log&lt;br /&gt;
&lt;br /&gt;
vim /etc/logrotate.d/mysqlslowquery&lt;br /&gt;
&lt;br /&gt;
/var/log/mysql/mysql-slow-query.log {&lt;br /&gt;
    missingok&lt;br /&gt;
    daily&lt;br /&gt;
    create 0644 mysql mysql&lt;br /&gt;
    rotate 10&lt;br /&gt;
} --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
&lt;br /&gt;
=== [http://serverkb.co.uk/tools/software/red5-1.0.0-RC1.tar.gz Red5 Media Server tar.gz] ===&lt;br /&gt;
&lt;br /&gt;
See the following link for what Red5 is/does: http://www.red5.org/ &lt;br /&gt;
&amp;lt;!-- == [http://serverkb.co.uk/tools/servicestarter.sh Plesk Monitor/Starter] ==&lt;br /&gt;
&lt;br /&gt;
This is a work in progress and is meant to start a specific service, in this case, Plesk. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== snow.sh - [http://serverkb.co.uk/tools/snow.sh Snowfall Script] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/snow.sh&lt;br /&gt;
chmod +x snow.sh&lt;br /&gt;
./snow.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This puts snowfall on your screen! :) To quit, do:&lt;br /&gt;
&lt;br /&gt;
CTRL + C&amp;lt;br&amp;gt;&lt;br /&gt;
CTRL + L&lt;br /&gt;
&lt;br /&gt;
== updatedb.sh - [http://serverkb.co.uk/tools/updatedb.sh UpdateDB] ==&lt;br /&gt;
&lt;br /&gt;
This was just a test. You can just add `updatedb` &lt;br /&gt;
&lt;br /&gt;
This updates the linux index of a server if it does not already so any knew files can be found using the command locate &amp;lt;filename&amp;gt;. To use it you need to do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/updatedbscript.sh ; chmod +x updatedbscript.sh&lt;br /&gt;
crontab -e&lt;br /&gt;
&lt;br /&gt;
#In here add:&lt;br /&gt;
&lt;br /&gt;
5 * * * * /path/to/updatedbscript.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== eXample .htaccess and .htpasswd file ==&lt;br /&gt;
&lt;br /&gt;
Place the below .htaccess file in your document root with 644 permissions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Options +Indexes&lt;br /&gt;
AuthName &amp;quot;Private zone&amp;quot;&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthUserFile /change/this/to/full/file/path/to/.htpasswd&lt;br /&gt;
require valid-user&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Encrypt your password by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;openssl passwd -1&lt;br /&gt;
Password: *enter your password*&lt;br /&gt;
Verifying - Password: *enter your password again*&lt;br /&gt;
&amp;lt;Password will appear here&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the encrypted password above.&lt;br /&gt;
&lt;br /&gt;
Place the below .htpasswd file anywhere in the file system:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;user:EncryptedPassword&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test by going to domain.co.uk/folder&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Remove spaces between file names&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://www.unix.com/shell-programming-scripting/105840-remove-spaces-between-file-names.html Guide 1]&lt;br /&gt;
&lt;br /&gt;
Do not use for-loops to process lists of unknown length, like a directory listing. If the list grows too long it will exceed your maximum line length (see syslimits.h) and your code will break. Using a while-loop removes this risk.&lt;br /&gt;
&lt;br /&gt;
[http://design.liberta.co.za/articles/how-to-remove-spaces-from-filenames-in-linuxunix Guide 2]&lt;br /&gt;
&lt;br /&gt;
=== Realtime monitor of Apache accesslog ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim realtime.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
ACCESSLOG=&amp;quot;/var/log/apache2/access_log&amp;quot;&lt;br /&gt;
DATE=`date +%d\/%b\/%Y`&lt;br /&gt;
TOTAL=`netstat -pant | grep :80 | wc -l`&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;There are a total of $TOTAL port 80 connections.&amp;quot;&lt;br /&gt;
echo -ne &amp;quot;The &amp;quot; ; uptime | awk &#039;{print $8,$9,$10,$11,$12}&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
tail -10 $ACCESSLOG | grep $DATE&amp;quot; | awk &#039;{ x = $2 &amp;quot; &amp;quot; $4 &amp;quot; &amp;quot; $7 ; printf &amp;quot;%-15s %-20s \n&amp;quot;, $1, x, $7}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run this with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 2 ./realtime.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively you can use [http://dumpsterventures.com/jason/httpry httpry]. This may be best run in a screen session so you can enter in and out of it. To use it do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget dldmz.eu/s/httpry&lt;br /&gt;
chmod +x httpry&lt;br /&gt;
./httpry&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then go to your websites. You can output the contents to a file by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./httpry -o filename&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Debian&amp;diff=1127</id>
		<title>Debian</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Debian&amp;diff=1127"/>
		<updated>2019-06-05T16:24:40Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* ReadyNAS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Broken package ==&lt;br /&gt;
&lt;br /&gt;
initscripts : Breaks: nfs-common (&amp;lt; 1:1.2.5-3) but 1:1.2.2-4squeeze2 is to be installed&lt;br /&gt;
&lt;br /&gt;
If you&#039;re on Debian 6 (squeeze) do:&lt;br /&gt;
&lt;br /&gt;
vim /etc/apt/sources.list&lt;br /&gt;
&lt;br /&gt;
Make sure there are no lines like the one below:&lt;br /&gt;
&lt;br /&gt;
deb http://ftp.uk.debian.org/debian sid main&lt;br /&gt;
&lt;br /&gt;
== Check OS version ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cron log ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to send mail to Gmail ==&lt;br /&gt;
&lt;br /&gt;
If you are on Debian 7 as of 16/09/2013 I would advise doing the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://ftp.uk.debian.org/debian wheezy main contrib&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then follow this guide: http://www.cyberciti.biz/tips/linux-use-gmail-as-a-smarthost.html&lt;br /&gt;
&lt;br /&gt;
Afterwards comment out the new /etc/apt/sources.list line and do apt-get update again.&lt;br /&gt;
&lt;br /&gt;
== monit ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install monit&lt;br /&gt;
vim /etc/default/monit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set startup=0 to startup=1&lt;br /&gt;
&lt;br /&gt;
The config file is /etc/monit/monitrc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;set httpd port 2812&lt;br /&gt;
    use address 12.34.56.789  # only accept connection from localhost&lt;br /&gt;
    allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server and&lt;br /&gt;
    allow admin:password         # require user &#039;admin&#039; with password &#039;password&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://www.digitalocean.com/community/articles/how-to-install-and-configure-monit&amp;lt;br&amp;gt;&lt;br /&gt;
http://viktorpetersson.com/2010/07/09/setting-up-monit-to-monitor-apache-and-postgresql-on-ubuntu&lt;br /&gt;
&lt;br /&gt;
== motd ==&lt;br /&gt;
&lt;br /&gt;
http://wiki.debian.org/motd&lt;br /&gt;
&lt;br /&gt;
== mutt ==&lt;br /&gt;
&lt;br /&gt;
http://solver.io/wp/2012/10/06/e-could-not-perform-immediate-configuration-on-exim4-daemon-light-please-see-man-5-apt-conf-under-aptimmediate-configure-for-details-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=1672227&amp;lt;br&amp;gt;&lt;br /&gt;
http://techteam.wordpress.com/2009/05/13/how-to-attach-large-files-to-command-line-email/&lt;br /&gt;
&lt;br /&gt;
If you use mutt to send emails via scripts and get this message because the attachment is too large:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;postdrop: warning: uid=0: File too large&lt;br /&gt;
sendmail: fatal: root(0): message file too big&lt;br /&gt;
Error sending message, child exited 75 (Deferred.).&lt;br /&gt;
Could not send the message.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
DO NOT install exim (&#039;&#039;&#039;especially if you have Proxmox installed&#039;&#039;&#039;) to try and solve the issue as it will do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install exim4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reading package lists... Done&lt;br /&gt;
Building dependency tree&lt;br /&gt;
Reading state information... Done&lt;br /&gt;
The following extra packages will be installed:&lt;br /&gt;
  exim4-base exim4-config exim4-daemon-light&lt;br /&gt;
Suggested packages:&lt;br /&gt;
  eximon4 exim4-doc-html exim4-doc-info spf-tools-perl swaks&lt;br /&gt;
The following packages will be REMOVED:&lt;br /&gt;
  postfix&lt;br /&gt;
The following NEW packages will be installed:&lt;br /&gt;
  exim4 exim4-base exim4-config exim4-daemon-light&lt;br /&gt;
0 upgraded, 4 newly installed, 1 to remove and 31 not upgraded.&lt;br /&gt;
Need to get 2,080 kB of archives.&lt;br /&gt;
After this operation, 807 kB of additional disk space will be used.&lt;br /&gt;
Do you want to continue [Y/n]? Y&lt;br /&gt;
Get:1 http://ftp.uk.debian.org/debian/ squeeze/main exim4-base amd64 4.72-6+squeeze3 [1,016 kB]&lt;br /&gt;
Get:2 http://ftp.uk.debian.org/debian/ squeeze/main exim4-daemon-light amd64 4.72-6+squeeze3 [594 kB]&lt;br /&gt;
Get:3 http://ftp.uk.debian.org/debian/ squeeze/main exim4-config all 4.72-6+squeeze3 [462 kB]&lt;br /&gt;
Get:4 http://ftp.uk.debian.org/debian/ squeeze/main exim4 all 4.72-6+squeeze3 [7,812 B]&lt;br /&gt;
Fetched 2,080 kB in 0s (7,680 kB/s)&lt;br /&gt;
E: Could not perform immediate configuration on &#039;exim4-daemon-light&#039;. Please see man 5 apt.conf under APT::Immediate-Configure for details. (2)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install exim4-base exim4-config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reading package lists... Done&amp;lt;br&amp;gt;&lt;br /&gt;
Building dependency tree&amp;lt;br&amp;gt;&lt;br /&gt;
Reading state information... Done&amp;lt;br&amp;gt;&lt;br /&gt;
The following package was automatically installed and is no longer required:&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;pve-kernel-2.6.32-19-pve&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Use &#039;apt-get autoremove&#039; to remove them.&amp;lt;br&amp;gt;&lt;br /&gt;
The following extra packages will be installed:&amp;lt;br&amp;gt;&lt;br /&gt;
pve-kernel-2.6.32-19-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Suggested packages:&amp;lt;br&amp;gt;&lt;br /&gt;
eximon4 exim4-doc-html exim4-doc-info spf-tools-perl swaks&amp;lt;br&amp;gt;&lt;br /&gt;
The following packages will be REMOVED:&amp;lt;br&amp;gt;&lt;br /&gt;
bsd-mailx postfix proxmox-ve-2.6.32 pve-manager&amp;lt;br&amp;gt;&lt;br /&gt;
The following NEW packages will be installed:&amp;lt;br&amp;gt;&lt;br /&gt;
exim4-base exim4-config pve-kernel-2.6.32-19-pve&amp;lt;br&amp;gt;&lt;br /&gt;
0 upgraded, 3 newly installed, 4 to remove and 30 not upgraded.&amp;lt;br&amp;gt;&lt;br /&gt;
Need to get 31.9 MB/33.4 MB of archives.&amp;lt;br&amp;gt;&lt;br /&gt;
After this operation, 553 kB disk space will be freed.&amp;lt;br&amp;gt;&lt;br /&gt;
Do you want to continue [Y/n]? Y&amp;lt;br&amp;gt;&lt;br /&gt;
Get:1 http://download.proxmox.com/debian/ squeeze/pve pve-kernel-2.6.32-19-pve amd64 2.6.32-96 [31.9 MB]&amp;lt;br&amp;gt;&lt;br /&gt;
Fetched 31.9 MB in 3s (8,937 kB/s)&amp;lt;br&amp;gt;&lt;br /&gt;
Preconfiguring packages ...&amp;lt;br&amp;gt;&lt;br /&gt;
(Reading database ... 56486 files and directories currently installed.)&amp;lt;br&amp;gt;&lt;br /&gt;
Removing bsd-mailx ...&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Removing proxmox-ve-2.6.32&#039;&#039;&#039; ...&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Removing pve-manager&#039;&#039;&#039; ...&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Removing postfix&#039;&#039;&#039; ...&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Stopping Postfix Mail Transport Agent: postfix.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Processing triggers for man-db ...&amp;lt;br&amp;gt;&lt;br /&gt;
Selecting previously deselected package exim4-config.&amp;lt;br&amp;gt;&lt;br /&gt;
(Reading database ... 55756 files and directories currently installed.)&amp;lt;br&amp;gt;&lt;br /&gt;
Unpacking exim4-config (from .../exim4-config_4.72-6+squeeze3_all.deb) ...&amp;lt;br&amp;gt;&lt;br /&gt;
Selecting previously deselected package exim4-base.&amp;lt;br&amp;gt;&lt;br /&gt;
Unpacking exim4-base (from .../exim4-base_4.72-6+squeeze3_amd64.deb) ...&amp;lt;br&amp;gt;&lt;br /&gt;
Selecting previously deselected package pve-kernel-2.6.32-19-pve.&amp;lt;br&amp;gt;&lt;br /&gt;
Unpacking pve-kernel-2.6.32-19-pve (from .../pve-kernel-2.6.32-19-pve_2.6.32-96_amd64.deb) ...&amp;lt;br&amp;gt;&lt;br /&gt;
Processing triggers for man-db ...&amp;lt;br&amp;gt;&lt;br /&gt;
Setting up exim4-config (4.72-6+squeeze3) ...&amp;lt;br&amp;gt;&lt;br /&gt;
grep: /etc/inetd.conf: No such file or directory&amp;lt;br&amp;gt;&lt;br /&gt;
Adding system-user for exim (v4)&amp;lt;br&amp;gt;&lt;br /&gt;
Setting up exim4-base (4.72-6+squeeze3) ...&amp;lt;br&amp;gt;&lt;br /&gt;
insserv: warning: script &#039;K01jira&#039; missing LSB tags and overrides&amp;lt;br&amp;gt;&lt;br /&gt;
insserv: warning: script &#039;jira&#039; missing LSB tags and overrides&amp;lt;br&amp;gt;&lt;br /&gt;
Setting up pve-kernel-2.6.32-19-pve (2.6.32-96) ...&amp;lt;br&amp;gt;&lt;br /&gt;
update-initramfs: Generating /boot/initrd.img-2.6.32-19-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Generating grub.cfg ...&amp;lt;br&amp;gt;&lt;br /&gt;
Found linux image: /boot/vmlinuz-2.6.32-19-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Found initrd image: /boot/initrd.img-2.6.32-19-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Found linux image: /boot/vmlinuz-2.6.32-18-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Found initrd image: /boot/initrd.img-2.6.32-18-pve&amp;lt;br&amp;gt;&lt;br /&gt;
Found memtest86+ image: /memtest86+.bin&amp;lt;br&amp;gt;&lt;br /&gt;
Found memtest86+ multiboot image: /memtest86+_multiboot.bin&amp;lt;br&amp;gt;&lt;br /&gt;
done&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install exim4-daemon-light&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reading package lists... Done&lt;br /&gt;
Building dependency tree&lt;br /&gt;
Reading state information... Done&lt;br /&gt;
The following package was automatically installed and is no longer required:&lt;br /&gt;
  pve-kernel-2.6.32-19-pve&lt;br /&gt;
Use &#039;apt-get autoremove&#039; to remove them.&lt;br /&gt;
The following NEW packages will be installed:&lt;br /&gt;
  exim4-daemon-light&lt;br /&gt;
0 upgraded, 1 newly installed, 0 to remove and 30 not upgraded.&lt;br /&gt;
Need to get 0 B/594 kB of archives.&lt;br /&gt;
After this operation, 1,135 kB of additional disk space will be used.&lt;br /&gt;
Preconfiguring packages ...&lt;br /&gt;
Selecting previously deselected package exim4-daemon-light.&lt;br /&gt;
(Reading database ... 58349 files and directories currently installed.)&lt;br /&gt;
Unpacking exim4-daemon-light (from .../exim4-daemon-light_4.72-6+squeeze3_amd64.deb) ...&lt;br /&gt;
Processing triggers for man-db ...&lt;br /&gt;
Setting up exim4-daemon-light (4.72-6+squeeze3) ...&lt;br /&gt;
Starting MTA: exim4.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you start getting the following message:&lt;br /&gt;
&lt;br /&gt;
mailx Can&#039;t send mail: sendmail process failed with error code 67&lt;br /&gt;
&lt;br /&gt;
And you can&#039;t start Apache, you need to re-install pve-manager.&lt;br /&gt;
&lt;br /&gt;
=== error code 67 ===&lt;br /&gt;
&lt;br /&gt;
If you get this error message when sending mail to a domain with mail externally but it is on the server:&lt;br /&gt;
&lt;br /&gt;
Can&#039;t send mail: sendmail process failed with error code 67&lt;br /&gt;
&lt;br /&gt;
Add the domain to this file and restart sendmail:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/mail/relay-domains&lt;br /&gt;
/etc/init.d/sendmail restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
It is commonly easier to use this to dump and restore MySQL, instead of using mysqldump on the new server via .sql files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename &amp;gt; dbdump.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --silent --local --password=EnterPasswordHere DatabaseName &amp;lt; dbdump.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ReadyNAS ==&lt;br /&gt;
&lt;br /&gt;
===  Deleting large file/s fails and crashes NAS ===&lt;br /&gt;
&lt;br /&gt;
https://community.netgear.com/t5/Using-your-ReadyNAS-in-Business/Deleting-large-file-fails-and-crashes-NAS/m-p/1562763?collapse_discussion=true&amp;amp;search_type=thread&lt;br /&gt;
&lt;br /&gt;
Use truncate&lt;br /&gt;
&lt;br /&gt;
=== Install mplayer on Debian Wheezy ===&lt;br /&gt;
&lt;br /&gt;
Add the following lines to your /etc/apt/sources.list file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Debian Multimedia Repository&lt;br /&gt;
deb http://www.deb-multimedia.org wheezy main non-free&lt;br /&gt;
deb ftp://ftp.deb-multimedia.org wheezy main non-free&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install deb-multimedia-keyring&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get install libimage-exiftool-perl ffmpeg&lt;br /&gt;
apt-get install mplayer mencoder&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then comment out the following lines to your /etc/apt/sources.list file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Debian Multimedia Repository&lt;br /&gt;
#deb http://www.deb-multimedia.org wheezy main non-free&lt;br /&gt;
#deb ftp://ftp.deb-multimedia.org wheezy main non-free&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And run apt-get update again.&lt;br /&gt;
&lt;br /&gt;
This can be needed to also get mencoder working as well.&lt;br /&gt;
&lt;br /&gt;
mediainfo and dcraw should install normally without the above packages.&lt;br /&gt;
&lt;br /&gt;
vlc and vlc-nox will ask to remove some of the packages that were installed above.&lt;br /&gt;
&lt;br /&gt;
=== ReadyCloud page not working for ReadyNAS on Static IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;netstat -na |grep LISTEN |grep &#039;:80\|:443&#039;&lt;br /&gt;
cat /etc/apache2/ports.conf&lt;br /&gt;
ps aux |grep apache&lt;br /&gt;
ls -l /frontview/dashboard&lt;br /&gt;
cat nonadmin_redirect.html&lt;br /&gt;
free -h&lt;br /&gt;
cat /proc/meminfo&lt;br /&gt;
locate error.log&lt;br /&gt;
tail -f /var/log/apache2/error.log&lt;br /&gt;
tail -f /var/log/frontview/error.log&lt;br /&gt;
date&lt;br /&gt;
tail -f /var/log/frontview/http-error.log&lt;br /&gt;
hostname&lt;br /&gt;
top&lt;br /&gt;
systemctl status readynasd&lt;br /&gt;
service ctscand stop&lt;br /&gt;
ps -ef | grep ctsc&lt;br /&gt;
systemctl status apache2&lt;br /&gt;
systemctl restart apache2&lt;br /&gt;
systemctl status apache2&lt;br /&gt;
ps -ef | grep readynasd&lt;br /&gt;
systemctl status readynasd&lt;br /&gt;
cat /etc/default/services | grep &amp;quot;FRONTVIEWLOCALE&amp;quot;&lt;br /&gt;
btrfs fi show&lt;br /&gt;
btrfs fi df /data&lt;br /&gt;
df -h&lt;br /&gt;
df -i&lt;br /&gt;
cat /var/log/frontview/initrd.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
apt-get update fails due to static IP + DNS&lt;br /&gt;
&lt;br /&gt;
== Set date/time ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure tzdata&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/Tz_database&lt;br /&gt;
&lt;br /&gt;
Or you can just install NTP (Network Time Protocol) using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install ntp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Speed up SSH login ==&lt;br /&gt;
&lt;br /&gt;
By default for some reason in Debian 6 (Squeeze) /etc/ssh/sshd_config does not have UseDNS=no within it. Add it into the file and restart SSH and this will greatly improve SSH login as a sudo user or root. GSSAPIAuthentication=no may also help.&lt;br /&gt;
&lt;br /&gt;
== Transmission ==&lt;br /&gt;
&lt;br /&gt;
Config File configuration: https://trac.transmissionbt.com/wiki/EditConfigFiles&lt;br /&gt;
&lt;br /&gt;
Pre-installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install vim ncdu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The easiest way to get this working is by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add in this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://ftp.uk.debian.org/debian sid main&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do apt-get update , then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-cache show transmission-cli | grep Version&lt;br /&gt;
apt-cache show transmission-common | grep Version&lt;br /&gt;
apt-cache show transmission-daemon | grep Version&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install transmission-cli transmission-common transmission-daemon&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to edit the files without it overwriting /etc/transmission-daemon/settings.json&lt;br /&gt;
&lt;br /&gt;
Stop the service, edit the file, backup the file and then start the service.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/transmission-daemon stop&lt;br /&gt;
vim /etc/transmission-daemon/settings.json&lt;br /&gt;
cp /etc/transmission-daemon/settings.json /root/settings.json.backup&lt;br /&gt;
/etc/init.d/transmission-daemon start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check /etc/transmission-daemon/settings.json is the same file you edited and that it is owned by debian-transmission:debian-transmission&lt;br /&gt;
&lt;br /&gt;
== User has the wrong group ==&lt;br /&gt;
&lt;br /&gt;
For example you want the files of the User tester to have the following User:Group setting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tester:tester&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However the system is creating files as tester:anotherGroupOrUser&lt;br /&gt;
To resolve this log in as root and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod -g tester tester&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will set the tester User&#039;s primary group as tester.&lt;br /&gt;
&lt;br /&gt;
== Wordpress ==&lt;br /&gt;
&lt;br /&gt;
If you are using a Vanilla build of a Unix OS you will need to do this so themes and plugins can install:&lt;br /&gt;
&lt;br /&gt;
cd /var/www/vhosts/&amp;lt;br&amp;gt;&lt;br /&gt;
chown www-data:www-data yourdomain.co.uk/* -R&lt;br /&gt;
&lt;br /&gt;
=== Stop prompting for FTP credentials ===&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;gt;&amp;gt; /var/www/vhosts/yourdomain.co.uk/wp-config.php&amp;lt;br&amp;gt;&lt;br /&gt;
echo &amp;quot;define(&#039;FS_METHOD&#039;, &#039;direct&#039;);&amp;quot; &amp;gt;&amp;gt; /var/www/vhosts/yourdomain.co.uk/wp-config.php&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Ubuntu&amp;diff=1126</id>
		<title>Ubuntu</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Ubuntu&amp;diff=1126"/>
		<updated>2019-05-28T14:45:37Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* List all installed packages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;dpkg -l | grep service will show the enabled modules for that service. -s | packagename shows the version available. 64 bit on Debian is called amd64, not x86_64&lt;br /&gt;
&lt;br /&gt;
== 32bit on 64bit ==&lt;br /&gt;
&lt;br /&gt;
To use 32bit applications on Ubuntu 10.04 64bit you will need the following package: [http://packages.ubuntu.com/lucid/ia32-libs ia32 libs]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.debian-administration.org/articles/534 Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://help.ubuntu.com/community/32bit_and_64bit Guide 2]&lt;br /&gt;
&lt;br /&gt;
== [http://maddhat.com/apt-get-upgrade-confusion apt-get upgrade option] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Running &lt;br /&gt;
&lt;br /&gt;
apt-get install update-manager-core&lt;br /&gt;
do-release-upgrade&lt;br /&gt;
&lt;br /&gt;
Will attempt to upgrade Ubuntu from 8.04 to 10.04 which will break the server.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://www.google.co.uk/#hl=en&amp;amp;sclient=psy-ab&amp;amp;q=ubuntu+none:0%3A+open%3A+%2Fetc%2Fnamed.conf%3A+permission+denied&amp;amp;oq=ubuntu+none:0%3A+open%3A+%2Fetc%2Fnamed.conf%3A+permission+denied&amp;amp;aq=f&amp;amp;aqi=g4&amp;amp;aql=&amp;amp;gs_sm=3&amp;amp;gs_upl=13786l13786l1l14193l1l1l0l0l0l0l0l0ll0l0&amp;amp;gs_l=serp.3..0l4.13786l13786l1l14193l1l1l0l0l0l0l0l0ll0l0.llsin.&amp;amp;pbx=1&amp;amp;fp=1&amp;amp;bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&amp;amp;cad=b bind9 fails to start] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ubuntu none:0: open: /etc/named.conf: permission denied&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below fix is not related to the above error in the box.&lt;br /&gt;
&lt;br /&gt;
This can be caused because the Operating System is Ubuntu 12 (as of 28/01/13), and there is a bug with Plesk version 11 servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/apparmor.d/disable&lt;br /&gt;
ls -lah&lt;br /&gt;
ln -s ../usr.sbin.named .&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart apparmor by doing one of the below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apparmor restart&lt;br /&gt;
service apparmor reload&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or it could be [http://serverfault.com/questions/412012/ubuntu-bind9-apparmor-read-permission-denied-chroot-jail this]. Then restart bind:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/bind9 restart&lt;br /&gt;
&lt;br /&gt;
Alternatively, you need to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apparmor teardown&lt;br /&gt;
update-rc.d -f apparmor remove&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Custom Software ==&lt;br /&gt;
&lt;br /&gt;
=== [http://1000umbrellas.com/2010/04/30/how-to-install-dropbox-on-a-headless-ubuntu-10-04-server Dropbox via CLI] ===&lt;br /&gt;
=== [http://ubuntuforums.org/showpost.php?p=9868359&amp;amp;postcount=1289/ ffmpeg and x264 on 10.04] ===&lt;br /&gt;
=== [http://latunyj.no-ip.org/2011/09/installing-geoip-database-in-ubuntu-10-04/ GeoIP] ===&lt;br /&gt;
&lt;br /&gt;
=== [http://koorenneef.nl/content/run-your-own-online-radio-station-icecast2-and-ezstream-howto/ IceCast] ===&lt;br /&gt;
&lt;br /&gt;
Follow the above guide and then before you get to starting ezstream section do the following:&lt;br /&gt;
&lt;br /&gt;
FTP your .mp3 music files to /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice as either files or folders. Folders will work as when you index the files it picks them up anyway.&lt;br /&gt;
&lt;br /&gt;
cp /usr/share/doc/ezstream/examples/ezstream_mp3.xml /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/&lt;br /&gt;
&lt;br /&gt;
vim /var/www/vhosts/thesixts.com/httpdocs/mu/ezstream_mp3.xml&lt;br /&gt;
&lt;br /&gt;
Ensure these are set correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;url&amp;gt;http://DomainNameOrServerIP:8000/mu&amp;lt;/url&amp;gt;&lt;br /&gt;
&amp;lt;sourcepassword&amp;gt;SameAsWhatIsIn/etc/icecast2/icecast.xml&amp;lt;/sourcepassword&amp;gt;&lt;br /&gt;
&amp;lt;filename&amp;gt;/var/www/vhosts/thesixts.com/httpdocs/mu/playlist-pickaname.txt&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;stream_once&amp;gt;0&amp;lt;/stream_once&amp;gt;&lt;br /&gt;
&amp;lt;svrinfopublic&amp;gt;0&amp;lt;/svrinfopublic&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
find /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/ -name *mp3 -type f &amp;gt; /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/playlist-pickaname.txt&lt;br /&gt;
&lt;br /&gt;
ezstream -c /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/ezstream_mp3.xml&lt;br /&gt;
&amp;lt;!-- https://intranet.webfusion.com/Installing_Nagios_(Ubuntu) --&amp;gt;&lt;br /&gt;
=== Nagios ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install build-essential&lt;br /&gt;
apt-get install libgd2-xpm-dev&lt;br /&gt;
cd /etc ; mkdir nagios1&lt;br /&gt;
wget http://serverkb.co.uk/tools/nagios-3.2.3.tar.gz&lt;br /&gt;
cd nagios1&lt;br /&gt;
useradd -m nagios1&lt;br /&gt;
passwd nagios1&lt;br /&gt;
groupadd nag1cmd&lt;br /&gt;
usermod -a -G nag1cmd nagios1&lt;br /&gt;
usermod -a -G nag1cmd www-data&lt;br /&gt;
tar -zxvf nagios-3.2.3.tar.gz&lt;br /&gt;
mv nagios-3.2.3/* . ; rm nagios-3.2.3 -R&lt;br /&gt;
./configure --with-command-group=nag1cmd&lt;br /&gt;
make all&lt;br /&gt;
make install&lt;br /&gt;
make install-init&lt;br /&gt;
make install-config&lt;br /&gt;
make install-commandmode&lt;br /&gt;
make install-webconf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Currently up to this step documented.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.zimbio.com/Ubuntu+Linux/articles/JggbIZlG1Iq/Install+osTicket+free+open+source+help+desk/ OS ticket] ===&lt;br /&gt;
&lt;br /&gt;
=== Plex ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://plex.r.worldssl.net/PlexMediaServer/0.9.7.7.339-5ec3b53/plexmediaserver_0.9.7.7.339-5ec3b53_amd64.deb&lt;br /&gt;
apt-get -f install avahi-daemon avahi-utils ffmpeg&lt;br /&gt;
mv plexmediaserver_0.9.7.7.339-5ec3b53_amd64.deb plex.0.9.7.7.339.deb ; dpkg -i plex.0.9.7.7.339.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install plexmediaserver&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This works on Debian too (only with the below fix):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/sources.list.d/plexmediaserver.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://shell.ninthgate.se/packages/debian squeeze main&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install plexmediaserver&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To log into Plex nowadays, you have to setup X11 forwarding to authenticate on a headless server. To do this:&lt;br /&gt;
&lt;br /&gt;
* Install XLaunch on your PC and run it&lt;br /&gt;
* Then select Multiple Windows, Display Number 0 (or 1 above the previous number) &amp;gt; Next &amp;gt; Start no client &amp;gt; Next &amp;gt; Next &amp;gt; Finish&lt;br /&gt;
* Install and run PuTTy&lt;br /&gt;
* Select the &amp;quot;Saved Sessions&amp;quot; you use to connect to your server, click Load&lt;br /&gt;
* Click Connection &amp;gt; SSH &amp;gt; X11 - tick &amp;quot;Enable X11 Forwarding&amp;quot;&lt;br /&gt;
* Set &amp;quot;X display location&amp;quot; to :0.0&lt;br /&gt;
* Click &amp;quot;Session&amp;quot; and click Default Settings or your session under &amp;quot;Saved Session&amp;quot;, then click Save&lt;br /&gt;
* Log into your server with a new session&lt;br /&gt;
* Run: echo $DISPLAY . This should return localhost:10.0&lt;br /&gt;
* Run iceweasel from within your server on CLI and go to this address: http://localhost:324000/web . That should connect you locally to your Plex Media Server and you should be able to configure the rest from the web interface.&lt;br /&gt;
&lt;br /&gt;
You need to ensure you run iceweasel from the same user you logged in as/installed iceweasel with, as it creates /home/user/.Xauthority&lt;br /&gt;
&lt;br /&gt;
Note: File naming on Unix for TV shows should be in the format Episode 01, Episode 02 etc. so that Episode 10+ does not come first.&lt;br /&gt;
&amp;lt;!-- You need to set the Web URL to be http://127.0.0.1:port/web to be able to remotely manage the settings externally.&lt;br /&gt;
&lt;br /&gt;
To change the port, read [http://wiki.plexapp.com/index.php/MyPlex#Manually_Configure_the_Router this]. On Unix, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j REDIRECT --to-port 32400&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you mess up just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -F -t nat&lt;br /&gt;
iptables -F&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Need to figure out how to do iptables -A INPUT -p tcp --dport 32400 -j DROP . These do not work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j REDIRECT --to-ports 32400&lt;br /&gt;
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j DNAT --to 127.0.0.1:32400&amp;lt;/pre&amp;gt; --&amp;gt;&lt;br /&gt;
Once installed to access the panel, go to http://ipaddress:32400/web&lt;br /&gt;
&lt;br /&gt;
If the settings menu disappears, do:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/plexmediaserver restart&lt;br /&gt;
&lt;br /&gt;
==== [http://wiki.plexapp.com/index.php/PlexNine_Tips_and_Tricks#Plex_Log_Files Log Files] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$PLEX_HOME/Library/Application Support/Plex Media Server/Logs&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs&lt;br /&gt;
tail -f Plex\ Media\ Server.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.red5.org Red5] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Additional guides:&lt;br /&gt;
&lt;br /&gt;
http://nooblikeaboss.wordpress.com/2011/11/01/installing-red5-on-ubuntu-10-04-lts/&lt;br /&gt;
http://bryogenic.com/red5-1-0-rc-in-ubuntu-10-04-on-rackspace-cloud/&lt;br /&gt;
http://www.videochat-scripts.com/install-red5-0-9-on-linux-ubuntu/ --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;add-apt-repository &amp;quot;deb http://archive.canonical.com/ lucid partner&amp;quot;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get install subversion&lt;br /&gt;
apt-get install ant&lt;br /&gt;
apt-get install python-software-properties&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
apt-get install sun-java6-jdk&lt;br /&gt;
apt-get install sun-java6-jre&lt;br /&gt;
wget http://trac.red5.org/downloads/1_0/red5-1.0.0-RC1.tar.gz&lt;br /&gt;
tar xvfz red5-1.0.0-RC1.tar.gz&lt;br /&gt;
mv red5-1.0.0 red5&lt;br /&gt;
mv red5 /usr/local/&lt;br /&gt;
adduser –system –group –home /usr/local/red5 red5&lt;br /&gt;
chown -R red5.red5 /usr/local/red5&lt;br /&gt;
touch /etc/init.d/red5&lt;br /&gt;
vim /etc/init.d/red5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Paste this script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#! /bin/sh&lt;br /&gt;
#&lt;br /&gt;
# red5 red5 initscript&lt;br /&gt;
#&lt;br /&gt;
# Author: Simon Eisenmann.&lt;br /&gt;
#&lt;br /&gt;
set -e&lt;br /&gt;
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin&lt;br /&gt;
DESC=&amp;quot;Red5 flash streaming server&amp;quot;&lt;br /&gt;
NAME=red5&lt;br /&gt;
RED5_HOME=/usr/local/red5&lt;br /&gt;
DAEMON=$RED5_HOME/$NAME.sh&lt;br /&gt;
PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
SCRIPTNAME=/etc/init.d/$NAME&lt;br /&gt;
RED5_USER=red5&lt;br /&gt;
&lt;br /&gt;
# Gracefully exit if the package has been removed.&lt;br /&gt;
test -x $DAEMON || exit 0&lt;br /&gt;
&lt;br /&gt;
# Read config file if it is present.&lt;br /&gt;
if [ -r /etc/default/$NAME ]&lt;br /&gt;
then&lt;br /&gt;
  . /etc/default/$NAME&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
# Function that starts the daemon/service.&lt;br /&gt;
#&lt;br /&gt;
d_start() {&lt;br /&gt;
	start-stop-daemon --start -c $RED5_USER --pidfile $PIDFILE \&lt;br /&gt;
	--chdir $RED5_HOME --background --make-pidfile \&lt;br /&gt;
	--exec $DAEMON&lt;br /&gt;
}&lt;br /&gt;
#&lt;br /&gt;
# Function that stops the daemon/service.&lt;br /&gt;
#&lt;br /&gt;
d_stop() {&lt;br /&gt;
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \&lt;br /&gt;
	--name java&lt;br /&gt;
	rm -f $PIDFILE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
	echo -n &amp;quot;Starting $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_start&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  stop)&lt;br /&gt;
	echo -n &amp;quot;Stopping $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_stop&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  restart|force-reload)&lt;br /&gt;
	echo -n &amp;quot;Restarting $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_stop&lt;br /&gt;
	sleep 1&lt;br /&gt;
	d_start&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  *)&lt;br /&gt;
	echo &amp;quot;Usage: $SCRIPTNAME {start|stop|restart|force-reload}&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
	exit 1&lt;br /&gt;
	;;&lt;br /&gt;
&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
exit 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x /etc/init.d/red5&lt;br /&gt;
update-rc.d red5 defaults&lt;br /&gt;
/etc/init.d/red5 start&lt;br /&gt;
netstat -ant (Check for: “tcp6 0 0 :::5080 :::* Listen”)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to http://DomainOrIP:5080 and you should see the red5 landing page there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Install Xuggle&#039;&#039;&#039; next&lt;br /&gt;
&lt;br /&gt;
http://www.emunewz.net/forum/showthread.php?tid=2448&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Install Xuggler&#039;&#039;&#039;. Go to http://www.xuggle.com/xuggler/downloads/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/local&lt;br /&gt;
wget http://com.xuggle.s3.amazonaws.com/xuggler/xuggler-3.1.FINAL/xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&lt;br /&gt;
 &lt;br /&gt;
chmod a+x xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&lt;br /&gt;
./xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Put Xuggler into PATH&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/profile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the following at the bottom of the file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;export XUGGLE_HOME=/usr/local/xuggler&lt;br /&gt;
export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH&lt;br /&gt;
export PATH=$XUGGLE_HOME/bin:$PATH&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.red5tutorials.net/index.php/An_idiot&#039;s_guide_to_RMI/JMX_remote_connections_-_without_SSL_/_authentication Red5 Tutorials Website]&lt;br /&gt;
&lt;br /&gt;
== Cyber Citi Guides ==&lt;br /&gt;
[http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/ Monitoring Tools]&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/linux-security.html/ Security Tips]&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html Linux Debian cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Dynamic MMap ran out of room ==&lt;br /&gt;
&lt;br /&gt;
Upon apt-get update&lt;br /&gt;
&lt;br /&gt;
E: Dynamic MMap ran out of room&lt;br /&gt;
E: Error occurred while processing mindi (NewVersion1)&lt;br /&gt;
E: Problem with MergeList /var/lib/apt/lists/mirrors.filename&lt;br /&gt;
E: The package lists or status file could not be parsed or opened.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/apt/lists&lt;br /&gt;
mv mirrors.filename old.mirrors.filename&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the error still persists try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cp lists/* /root/VarLibAptListsBACKUP -R&lt;br /&gt;
rm /var/lib/apt/lists/* -vf&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the error still persists then try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/apt.conf.d/70debconf&lt;br /&gt;
APT::Cache-Limit &amp;quot;118388608&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update -o APT::Cache-Limit=25165824&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Install LAMP ==&lt;br /&gt;
&lt;br /&gt;
apt-get install lamp-server^ phpmyadmin&lt;br /&gt;
&lt;br /&gt;
== Install SSL on Ubuntu 12.04 with Apache 2.2.22 ==&lt;br /&gt;
&lt;br /&gt;
This is for a fresh install, unmodified in any way from apt-get install apache2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2ensite default-ssl&lt;br /&gt;
a2enmod ssl&lt;br /&gt;
service apache2 restart&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then go to https://yourhostname (either your domain or IP address), accept the certificate warning and you should see your website.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/apache2/ssl&lt;br /&gt;
vim /etc/apache2/sites-enabled/default-ssl&lt;br /&gt;
/SSLCertificateFile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press insert and edit the filepath of:&lt;br /&gt;
&lt;br /&gt;
SSLCertificateFile&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCertificateKeyFile&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCACertificateFile&lt;br /&gt;
&lt;br /&gt;
to direct to your files with the Certificate (.crt format), the Private Key (.key format) and the Intermediate Root CA Bundle (.crt format).&lt;br /&gt;
&lt;br /&gt;
Then vim each of the above filepaths and enter the certificate, key and Chain CA in their respective files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 600 /etc/apache2/ssl/SSLCertificateKeyFile&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;[https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigating-the-beast-attack-on-tls mitigate the BEAST attack]&#039;&#039;&#039; and &#039;&#039;&#039;disable SSLv3&#039;&#039;&#039; enter the following into /etc/apache2/sites-enabled/default-ssl&lt;br /&gt;
&lt;br /&gt;
SSLHonorCipherOrder On&amp;lt;br&amp;gt;&lt;br /&gt;
SSLProtocol -all +TLSv1&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCipherSuite ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;disable Apache and OS version&#039;&#039;&#039; put the following in /etc/apache2/sites-enabled/default-ssl &#039;&#039;&#039;outside&#039;&#039;&#039; of the VirtualHost tags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerTokens Prod&lt;br /&gt;
ServerSignature Off&lt;br /&gt;
TraceEnable Off&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tokens is the header&amp;lt;br&amp;gt;&lt;br /&gt;
Signature is the footer&lt;br /&gt;
&lt;br /&gt;
[https://www.ssllabs.com/ssltest/analyze.html?d=bywatercraft.co.uk Example of these in place]&lt;br /&gt;
&lt;br /&gt;
To get 100 on SSL, see HN.&lt;br /&gt;
&amp;lt;!-- Only TLS 1.2&lt;br /&gt;
&lt;br /&gt;
Only these Ciphers allowed (256)&lt;br /&gt;
&lt;br /&gt;
Cipher Suites (SSLv3+ suites in server-preferred order, then SSLv2 suites where used)&lt;br /&gt;
TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA (0x88)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (0x6b)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_DHE_RSA_WITH_AES_256_CBC_SHA (0x39)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_CBC_SHA256 (0x3d)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_GCM_SHA384 (0x9d)	256&lt;br /&gt;
TLS_RSA_WITH_CAMELLIA_256_CBC_SHA (0x84)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_CBC_SHA (0x35)	256&lt;br /&gt;
&lt;br /&gt;
Protocols&lt;br /&gt;
Session tickets	No &lt;br /&gt;
&lt;br /&gt;
https://community.qualys.com/thread/2013&lt;br /&gt;
http://www.apachehaus.com/forum/index.php?topic=628.0&lt;br /&gt;
&lt;br /&gt;
https://isc.sans.edu/diary.html?storyid=11629&lt;br /&gt;
Apache with OpenSSL - 1.0 only &lt;br /&gt;
Apache with GNUTLS - 1.2 is supported.  (note however that GNUTLS does not have the full feature set that OpenSSL does, nor does it have the body of testing, peer review and overall acceptance that OpenSSL has behind it.)&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;allow only TLS v1.2 only&#039;&#039;&#039; do [https://www.nnbfn.net/2011/05/tls-1-2-support-in-apache2 this]:&lt;br /&gt;
&lt;br /&gt;
apt-get install libgnutls28 libgnutls28-dbg libgnutls28-dev libgnutlsxx28--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Launch network manager ==&lt;br /&gt;
&lt;br /&gt;
nm-connection-editor&lt;br /&gt;
&lt;br /&gt;
== List all installed packages ==&lt;br /&gt;
&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
== Log Locations ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;FTP&#039;&#039;&#039;: /usr/local/psa/var/log/xferlog&lt;br /&gt;
&lt;br /&gt;
== Old Version of Plesk and an update fails ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when upgrading Plesk using the updates section in plesk:&lt;br /&gt;
&lt;br /&gt;
Installation could not be started: Unable to install packages because of package dependency problems. Not all packages were installed. ERROR: An error occurred on attempt to install packages. Attention! Your software might be inoperable. Please, contact product technical support.&lt;br /&gt;
&lt;br /&gt;
Check what Ubuntu OS you are running. To do this via command line run cat /etc/issue. &lt;br /&gt;
&lt;br /&gt;
=== Repositories ===&lt;br /&gt;
&lt;br /&gt;
The below repository issue most commonly happens on Ubuntu 6.06 as it is out of support now and the repos have changed. Edit the following file by using &#039;&#039;&#039;vim /etc/apt/sources.list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Comment out the old Ubuntu repository list using # (leave any others such as Plesk) and put in the below.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 6.06&#039;&#039;&#039; (Dapper Drake):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#Old-Release Sources&lt;br /&gt;
deb http://old-releases.ubuntu.com/ubuntu/ dapper  main universe multiverse&lt;br /&gt;
deb-src http://old-releases.ubuntu.com/ubuntu/ dapper  main universe multiverse&lt;br /&gt;
deb http://old-releases.ubuntu.com/ubuntu/ dapper-security main restricted universe multiverse&lt;br /&gt;
deb-src http://old-releases.ubuntu.com/ubuntu/ dapper-security main restricted universe multiverse&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error via [[SSH]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Err karmic/main Packages  404  Not Found&lt;br /&gt;
Err karmic/restricted Packages 404  Not Found&lt;br /&gt;
Err  karmic/universe Packages, 404  Not Found&lt;br /&gt;
Err  karmic-updates/main Packages 404  Not Found&lt;br /&gt;
Err karmic-updates/restricted Packages 404  Not Found&lt;br /&gt;
&lt;br /&gt;
vim /etc/apt/sources.list.d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
karmic.list is Ubuntu 9 which many hosters did not offer (hence no mirrors). If you are using lucid (Ubuntu 10), comment out the lines in this file. Apt should now update with no errors.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 8.04&#039;&#039;&#039; (Hardy Heron):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://archive.ubuntu.com/ubuntu hardy main restricted universe multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse&lt;br /&gt;
# Plesk&lt;br /&gt;
deb http://autoinstall.plesk.com/ubuntu/PSA8 hardy all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 10.04&#039;&#039;&#039; (Lucid Lynx):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb gb.archive.ubuntu.com lucid main restricted universe&lt;br /&gt;
deb gb.archive.ubuntu.com lucid-updates main restricted universe&lt;br /&gt;
deb gb.archive.ubuntu.com lucid-security main restricted universe&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: change mirrors from gb.archive.ubuntu.com to your own/your hosting companies if need be.&lt;br /&gt;
&lt;br /&gt;
Subversion repository guides: [https://help.ubuntu.com/10.04/serverguide/C/subversion.html 1], [http://www.howtogeek.com/howto/ubuntu/install-subversion-with-web-access-on-ubuntu/ 2], [http://geektaco.blogspot.co.uk/2010/05/using-ubuntu-1004-lts-server-for.html 3], [http://www.wikihow.com/Install-a-Subversion-Source-Control-Server-on-Ubuntu-10.04  4], [https://launchpad.net/ubuntu/lucid/+package/subversion 5]&lt;br /&gt;
&lt;br /&gt;
Additional repos:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://archive.ubuntu.com/ubuntu lucid universe&lt;br /&gt;
deb http://archive.canonical.com/ lucid partner&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Then run the following afterwards:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
/opt/psa/admin/bin/autoinstaller&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide more information as to which packages are causing the problem. Also try looking in the following log as this should have the info:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#/tmp/autoinstaller3.log&lt;br /&gt;
&lt;br /&gt;
Depending what is broken you may be able to force the install or configure the packages:&lt;br /&gt;
&lt;br /&gt;
apt-get -f install&lt;br /&gt;
dpkg -a configure-all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If neither of those fix then rebuild the VPS. Also check if there have been any custom upgrades such as PHP as that can break it.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 12.04&#039;&#039;&#039; (Precise Pangolin):&lt;br /&gt;
&lt;br /&gt;
http://ubuntuguide.org/wiki/Ubuntu:Precise#Edit_the_repository_sources_list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ dists/precise/main/binary-i386/&lt;br /&gt;
&lt;br /&gt;
# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ dists/precise/restricted/binary-i386/&lt;br /&gt;
# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ precise main restricted&lt;br /&gt;
&lt;br /&gt;
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to&lt;br /&gt;
# newer versions of the distribution.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise main restricted&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise main restricted&lt;br /&gt;
&lt;br /&gt;
## Major bug fix updates produced after the final release of the&lt;br /&gt;
## distribution.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates main restricted&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates main restricted&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu&lt;br /&gt;
## team. Also, please note that software in universe WILL NOT receive any&lt;br /&gt;
## review or updates from the Ubuntu security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise universe&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise universe&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates universe&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates universe&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu &lt;br /&gt;
## team, and may not be under a free licence. Please satisfy yourself as to &lt;br /&gt;
## your rights to use the software. Also, please note that software in &lt;br /&gt;
## multiverse WILL NOT receive any review or updates from the Ubuntu&lt;br /&gt;
## security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates multiverse&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository may not have been tested as&lt;br /&gt;
## extensively as that contained in the main release, although it includes&lt;br /&gt;
## newer versions of some applications which may provide useful features.&lt;br /&gt;
## Also, please note that software in backports WILL NOT receive any review&lt;br /&gt;
## or updates from the Ubuntu security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse&lt;br /&gt;
&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security main restricted&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security main restricted&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security universe&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security universe&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security multiverse&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security multiverse&lt;br /&gt;
&lt;br /&gt;
## Uncomment the following two lines to add software from Canonical&#039;s&lt;br /&gt;
## &#039;partner&#039; repository.&lt;br /&gt;
## This software is not part of Ubuntu, but is offered by Canonical and the&lt;br /&gt;
## respective vendors as a service to Ubuntu users.&lt;br /&gt;
deb http://archive.canonical.com/ubuntu precise partner&lt;br /&gt;
# deb-src http://archive.canonical.com/ubuntu precise partner&lt;br /&gt;
&lt;br /&gt;
## This software is not part of Ubuntu, but is offered by third-party&lt;br /&gt;
## developers who want to ship their latest software.&lt;br /&gt;
deb http://extras.ubuntu.com/ubuntu precise main&lt;br /&gt;
# deb-src http://extras.ubuntu.com/ubuntu precise main&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Networking#IP_Tables | iptables]] ==&lt;br /&gt;
&lt;br /&gt;
If within Virtuozzo you receive &#039;&#039;&#039;Failed to add the firewall rule to the Input chain&#039;&#039;&#039; when editing the firewall: http://kb.parallels.com/6691&lt;br /&gt;
&lt;br /&gt;
== Set time ==&lt;br /&gt;
&lt;br /&gt;
The easiest way is to pick your timezone by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure tzdata&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.mosbase.com/2010/05/install-latest-version-of-mysql-on.html Upgrade MySQL on Ubuntu 8.04] ==&lt;br /&gt;
&lt;br /&gt;
== [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 Upgrade MySQL on Ubuntu 10.04] ==&lt;br /&gt;
&lt;br /&gt;
== [[General#VNC | VNC]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install vnc4server&lt;br /&gt;
vnc4server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted for a password. This password will be used to log into the vnc session.&lt;br /&gt;
After providing a password, you will get output that looks like:&lt;br /&gt;
New &#039;IP.IP.IP.IP:1 (laptop)&#039; desktop is IP.IP.IP.IP:1&lt;br /&gt;
     &lt;br /&gt;
Take notice of the number after the colon (:), in this case it is &amp;quot;1.&amp;quot; Starting the vnc4server will cause a .vnc directory to be placed in your home directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vnc4server -kill :1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the .vnc/xstartup file for editing.&lt;br /&gt;
     &lt;br /&gt;
&amp;lt;pre&amp;gt;vim ~/.vnc/xstartup&amp;lt;/pre&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
The file will look like:&lt;br /&gt;
      &lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
# Uncomment the following two lines for normal desktop:&lt;br /&gt;
#unset SESSION_MANAGER&lt;br /&gt;
#exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
xsetroot -solid grey&lt;br /&gt;
vncconfig -iconic &amp;amp;&lt;br /&gt;
xterm -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
twm &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Type :wq and hit enter. Uncomment the lines that start with unset and exec. Comment out the lines that start with xsetroot, vncconfig, xterm, and twm.&lt;br /&gt;
&lt;br /&gt;
The final file should look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
unset SESSION_MANAGER&lt;br /&gt;
exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
#xsetroot -solid grey&lt;br /&gt;
#vncconfig -iconic &amp;amp;&lt;br /&gt;
#xterm -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
#twm &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
unset SESSION_MANAGER&lt;br /&gt;
exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
xsetroot -solid grey&lt;br /&gt;
vncconfig -iconic &amp;amp;&lt;br /&gt;
x-terminal-emulator -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
x-window-manager &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the permissions on the /etc/X11/xinit/xinitrc file to make it executable. Run the server, install Ubuntu Desktop.&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 755 /etc/X11/xinit/xinitrc&lt;br /&gt;
vnc4server&lt;br /&gt;
apt-get install ubuntu-desktop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember the number after the colon (:). Log into your remote desktop to check the configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vncviewer IP.IP.IP.IP:1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide the password that you chose.&lt;br /&gt;
&lt;br /&gt;
== warning: setlocale: LC_ALL: cannot change locale ==&lt;br /&gt;
&lt;br /&gt;
If you get this error when logging in, or you get the below when doing locale-gen en_GB:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/bin/bash: warning: setlocale: LC_ALL: cannot change locale ((unset))&lt;br /&gt;
/usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale ((unset))&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You normally need to comment out LC_ALL=&amp;quot;(unset)&amp;quot; in /etc/environment or /root/.profile&lt;br /&gt;
&lt;br /&gt;
== Work Offline in Firefox ==&lt;br /&gt;
&lt;br /&gt;
If the browser in Ubuntu 10.04 is always set to Work Offline, go into about:config and set the following:&lt;br /&gt;
&lt;br /&gt;
browser:offline 		set to 	FALSE&lt;br /&gt;
network.online			set to 	TRUE&lt;br /&gt;
toolkit.networkmanager.disable 	set to 	FALSE&lt;br /&gt;
&lt;br /&gt;
Create New &amp;gt; Boolean&lt;br /&gt;
&lt;br /&gt;
network.manage-offline-status 	set to	FALSE&lt;br /&gt;
&lt;br /&gt;
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/191889&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Ubuntu&amp;diff=1125</id>
		<title>Ubuntu</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Ubuntu&amp;diff=1125"/>
		<updated>2019-05-24T09:58:41Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Log Locations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;dpkg -l | grep service will show the enabled modules for that service. -s | packagename shows the version available. 64 bit on Debian is called amd64, not x86_64&lt;br /&gt;
&lt;br /&gt;
== 32bit on 64bit ==&lt;br /&gt;
&lt;br /&gt;
To use 32bit applications on Ubuntu 10.04 64bit you will need the following package: [http://packages.ubuntu.com/lucid/ia32-libs ia32 libs]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.debian-administration.org/articles/534 Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://help.ubuntu.com/community/32bit_and_64bit Guide 2]&lt;br /&gt;
&lt;br /&gt;
== [http://maddhat.com/apt-get-upgrade-confusion apt-get upgrade option] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Running &lt;br /&gt;
&lt;br /&gt;
apt-get install update-manager-core&lt;br /&gt;
do-release-upgrade&lt;br /&gt;
&lt;br /&gt;
Will attempt to upgrade Ubuntu from 8.04 to 10.04 which will break the server.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://www.google.co.uk/#hl=en&amp;amp;sclient=psy-ab&amp;amp;q=ubuntu+none:0%3A+open%3A+%2Fetc%2Fnamed.conf%3A+permission+denied&amp;amp;oq=ubuntu+none:0%3A+open%3A+%2Fetc%2Fnamed.conf%3A+permission+denied&amp;amp;aq=f&amp;amp;aqi=g4&amp;amp;aql=&amp;amp;gs_sm=3&amp;amp;gs_upl=13786l13786l1l14193l1l1l0l0l0l0l0l0ll0l0&amp;amp;gs_l=serp.3..0l4.13786l13786l1l14193l1l1l0l0l0l0l0l0ll0l0.llsin.&amp;amp;pbx=1&amp;amp;fp=1&amp;amp;bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&amp;amp;cad=b bind9 fails to start] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ubuntu none:0: open: /etc/named.conf: permission denied&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The below fix is not related to the above error in the box.&lt;br /&gt;
&lt;br /&gt;
This can be caused because the Operating System is Ubuntu 12 (as of 28/01/13), and there is a bug with Plesk version 11 servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/apparmor.d/disable&lt;br /&gt;
ls -lah&lt;br /&gt;
ln -s ../usr.sbin.named .&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart apparmor by doing one of the below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apparmor restart&lt;br /&gt;
service apparmor reload&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or it could be [http://serverfault.com/questions/412012/ubuntu-bind9-apparmor-read-permission-denied-chroot-jail this]. Then restart bind:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/bind9 restart&lt;br /&gt;
&lt;br /&gt;
Alternatively, you need to do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apparmor teardown&lt;br /&gt;
update-rc.d -f apparmor remove&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Custom Software ==&lt;br /&gt;
&lt;br /&gt;
=== [http://1000umbrellas.com/2010/04/30/how-to-install-dropbox-on-a-headless-ubuntu-10-04-server Dropbox via CLI] ===&lt;br /&gt;
=== [http://ubuntuforums.org/showpost.php?p=9868359&amp;amp;postcount=1289/ ffmpeg and x264 on 10.04] ===&lt;br /&gt;
=== [http://latunyj.no-ip.org/2011/09/installing-geoip-database-in-ubuntu-10-04/ GeoIP] ===&lt;br /&gt;
&lt;br /&gt;
=== [http://koorenneef.nl/content/run-your-own-online-radio-station-icecast2-and-ezstream-howto/ IceCast] ===&lt;br /&gt;
&lt;br /&gt;
Follow the above guide and then before you get to starting ezstream section do the following:&lt;br /&gt;
&lt;br /&gt;
FTP your .mp3 music files to /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice as either files or folders. Folders will work as when you index the files it picks them up anyway.&lt;br /&gt;
&lt;br /&gt;
cp /usr/share/doc/ezstream/examples/ezstream_mp3.xml /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/&lt;br /&gt;
&lt;br /&gt;
vim /var/www/vhosts/thesixts.com/httpdocs/mu/ezstream_mp3.xml&lt;br /&gt;
&lt;br /&gt;
Ensure these are set correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;url&amp;gt;http://DomainNameOrServerIP:8000/mu&amp;lt;/url&amp;gt;&lt;br /&gt;
&amp;lt;sourcepassword&amp;gt;SameAsWhatIsIn/etc/icecast2/icecast.xml&amp;lt;/sourcepassword&amp;gt;&lt;br /&gt;
&amp;lt;filename&amp;gt;/var/www/vhosts/thesixts.com/httpdocs/mu/playlist-pickaname.txt&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;stream_once&amp;gt;0&amp;lt;/stream_once&amp;gt;&lt;br /&gt;
&amp;lt;svrinfopublic&amp;gt;0&amp;lt;/svrinfopublic&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
find /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/ -name *mp3 -type f &amp;gt; /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/playlist-pickaname.txt&lt;br /&gt;
&lt;br /&gt;
ezstream -c /var/www/vhosts/yourdomain.com/httpdocs/FolderOfYourChoice/ezstream_mp3.xml&lt;br /&gt;
&amp;lt;!-- https://intranet.webfusion.com/Installing_Nagios_(Ubuntu) --&amp;gt;&lt;br /&gt;
=== Nagios ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install build-essential&lt;br /&gt;
apt-get install libgd2-xpm-dev&lt;br /&gt;
cd /etc ; mkdir nagios1&lt;br /&gt;
wget http://serverkb.co.uk/tools/nagios-3.2.3.tar.gz&lt;br /&gt;
cd nagios1&lt;br /&gt;
useradd -m nagios1&lt;br /&gt;
passwd nagios1&lt;br /&gt;
groupadd nag1cmd&lt;br /&gt;
usermod -a -G nag1cmd nagios1&lt;br /&gt;
usermod -a -G nag1cmd www-data&lt;br /&gt;
tar -zxvf nagios-3.2.3.tar.gz&lt;br /&gt;
mv nagios-3.2.3/* . ; rm nagios-3.2.3 -R&lt;br /&gt;
./configure --with-command-group=nag1cmd&lt;br /&gt;
make all&lt;br /&gt;
make install&lt;br /&gt;
make install-init&lt;br /&gt;
make install-config&lt;br /&gt;
make install-commandmode&lt;br /&gt;
make install-webconf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Currently up to this step documented.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.zimbio.com/Ubuntu+Linux/articles/JggbIZlG1Iq/Install+osTicket+free+open+source+help+desk/ OS ticket] ===&lt;br /&gt;
&lt;br /&gt;
=== Plex ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://plex.r.worldssl.net/PlexMediaServer/0.9.7.7.339-5ec3b53/plexmediaserver_0.9.7.7.339-5ec3b53_amd64.deb&lt;br /&gt;
apt-get -f install avahi-daemon avahi-utils ffmpeg&lt;br /&gt;
mv plexmediaserver_0.9.7.7.339-5ec3b53_amd64.deb plex.0.9.7.7.339.deb ; dpkg -i plex.0.9.7.7.339.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install plexmediaserver&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This works on Debian too (only with the below fix):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/sources.list.d/plexmediaserver.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://shell.ninthgate.se/packages/debian squeeze main&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
apt-get install plexmediaserver&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To log into Plex nowadays, you have to setup X11 forwarding to authenticate on a headless server. To do this:&lt;br /&gt;
&lt;br /&gt;
* Install XLaunch on your PC and run it&lt;br /&gt;
* Then select Multiple Windows, Display Number 0 (or 1 above the previous number) &amp;gt; Next &amp;gt; Start no client &amp;gt; Next &amp;gt; Next &amp;gt; Finish&lt;br /&gt;
* Install and run PuTTy&lt;br /&gt;
* Select the &amp;quot;Saved Sessions&amp;quot; you use to connect to your server, click Load&lt;br /&gt;
* Click Connection &amp;gt; SSH &amp;gt; X11 - tick &amp;quot;Enable X11 Forwarding&amp;quot;&lt;br /&gt;
* Set &amp;quot;X display location&amp;quot; to :0.0&lt;br /&gt;
* Click &amp;quot;Session&amp;quot; and click Default Settings or your session under &amp;quot;Saved Session&amp;quot;, then click Save&lt;br /&gt;
* Log into your server with a new session&lt;br /&gt;
* Run: echo $DISPLAY . This should return localhost:10.0&lt;br /&gt;
* Run iceweasel from within your server on CLI and go to this address: http://localhost:324000/web . That should connect you locally to your Plex Media Server and you should be able to configure the rest from the web interface.&lt;br /&gt;
&lt;br /&gt;
You need to ensure you run iceweasel from the same user you logged in as/installed iceweasel with, as it creates /home/user/.Xauthority&lt;br /&gt;
&lt;br /&gt;
Note: File naming on Unix for TV shows should be in the format Episode 01, Episode 02 etc. so that Episode 10+ does not come first.&lt;br /&gt;
&amp;lt;!-- You need to set the Web URL to be http://127.0.0.1:port/web to be able to remotely manage the settings externally.&lt;br /&gt;
&lt;br /&gt;
To change the port, read [http://wiki.plexapp.com/index.php/MyPlex#Manually_Configure_the_Router this]. On Unix, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j REDIRECT --to-port 32400&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you mess up just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -F -t nat&lt;br /&gt;
iptables -F&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Need to figure out how to do iptables -A INPUT -p tcp --dport 32400 -j DROP . These do not work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j REDIRECT --to-ports 32400&lt;br /&gt;
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport &amp;lt;PortYouWant&amp;gt; -j DNAT --to 127.0.0.1:32400&amp;lt;/pre&amp;gt; --&amp;gt;&lt;br /&gt;
Once installed to access the panel, go to http://ipaddress:32400/web&lt;br /&gt;
&lt;br /&gt;
If the settings menu disappears, do:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/plexmediaserver restart&lt;br /&gt;
&lt;br /&gt;
==== [http://wiki.plexapp.com/index.php/PlexNine_Tips_and_Tricks#Plex_Log_Files Log Files] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$PLEX_HOME/Library/Application Support/Plex Media Server/Logs&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs&lt;br /&gt;
tail -f Plex\ Media\ Server.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.red5.org Red5] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Additional guides:&lt;br /&gt;
&lt;br /&gt;
http://nooblikeaboss.wordpress.com/2011/11/01/installing-red5-on-ubuntu-10-04-lts/&lt;br /&gt;
http://bryogenic.com/red5-1-0-rc-in-ubuntu-10-04-on-rackspace-cloud/&lt;br /&gt;
http://www.videochat-scripts.com/install-red5-0-9-on-linux-ubuntu/ --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;add-apt-repository &amp;quot;deb http://archive.canonical.com/ lucid partner&amp;quot;&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get install subversion&lt;br /&gt;
apt-get install ant&lt;br /&gt;
apt-get install python-software-properties&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
apt-get install sun-java6-jdk&lt;br /&gt;
apt-get install sun-java6-jre&lt;br /&gt;
wget http://trac.red5.org/downloads/1_0/red5-1.0.0-RC1.tar.gz&lt;br /&gt;
tar xvfz red5-1.0.0-RC1.tar.gz&lt;br /&gt;
mv red5-1.0.0 red5&lt;br /&gt;
mv red5 /usr/local/&lt;br /&gt;
adduser –system –group –home /usr/local/red5 red5&lt;br /&gt;
chown -R red5.red5 /usr/local/red5&lt;br /&gt;
touch /etc/init.d/red5&lt;br /&gt;
vim /etc/init.d/red5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Paste this script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#! /bin/sh&lt;br /&gt;
#&lt;br /&gt;
# red5 red5 initscript&lt;br /&gt;
#&lt;br /&gt;
# Author: Simon Eisenmann.&lt;br /&gt;
#&lt;br /&gt;
set -e&lt;br /&gt;
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin&lt;br /&gt;
DESC=&amp;quot;Red5 flash streaming server&amp;quot;&lt;br /&gt;
NAME=red5&lt;br /&gt;
RED5_HOME=/usr/local/red5&lt;br /&gt;
DAEMON=$RED5_HOME/$NAME.sh&lt;br /&gt;
PIDFILE=/var/run/$NAME.pid&lt;br /&gt;
SCRIPTNAME=/etc/init.d/$NAME&lt;br /&gt;
RED5_USER=red5&lt;br /&gt;
&lt;br /&gt;
# Gracefully exit if the package has been removed.&lt;br /&gt;
test -x $DAEMON || exit 0&lt;br /&gt;
&lt;br /&gt;
# Read config file if it is present.&lt;br /&gt;
if [ -r /etc/default/$NAME ]&lt;br /&gt;
then&lt;br /&gt;
  . /etc/default/$NAME&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
# Function that starts the daemon/service.&lt;br /&gt;
#&lt;br /&gt;
d_start() {&lt;br /&gt;
	start-stop-daemon --start -c $RED5_USER --pidfile $PIDFILE \&lt;br /&gt;
	--chdir $RED5_HOME --background --make-pidfile \&lt;br /&gt;
	--exec $DAEMON&lt;br /&gt;
}&lt;br /&gt;
#&lt;br /&gt;
# Function that stops the daemon/service.&lt;br /&gt;
#&lt;br /&gt;
d_stop() {&lt;br /&gt;
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \&lt;br /&gt;
	--name java&lt;br /&gt;
	rm -f $PIDFILE&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;$1&amp;quot; in&lt;br /&gt;
  start)&lt;br /&gt;
	echo -n &amp;quot;Starting $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_start&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  stop)&lt;br /&gt;
	echo -n &amp;quot;Stopping $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_stop&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  restart|force-reload)&lt;br /&gt;
	echo -n &amp;quot;Restarting $DESC: $NAME&amp;quot;&lt;br /&gt;
	d_stop&lt;br /&gt;
	sleep 1&lt;br /&gt;
	d_start&lt;br /&gt;
	echo &amp;quot;.&amp;quot;&lt;br /&gt;
	;;&lt;br /&gt;
  *)&lt;br /&gt;
	echo &amp;quot;Usage: $SCRIPTNAME {start|stop|restart|force-reload}&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
	exit 1&lt;br /&gt;
	;;&lt;br /&gt;
&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
exit 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod +x /etc/init.d/red5&lt;br /&gt;
update-rc.d red5 defaults&lt;br /&gt;
/etc/init.d/red5 start&lt;br /&gt;
netstat -ant (Check for: “tcp6 0 0 :::5080 :::* Listen”)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to http://DomainOrIP:5080 and you should see the red5 landing page there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Install Xuggle&#039;&#039;&#039; next&lt;br /&gt;
&lt;br /&gt;
http://www.emunewz.net/forum/showthread.php?tid=2448&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Install Xuggler&#039;&#039;&#039;. Go to http://www.xuggle.com/xuggler/downloads/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/local&lt;br /&gt;
wget http://com.xuggle.s3.amazonaws.com/xuggler/xuggler-3.1.FINAL/xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&lt;br /&gt;
 &lt;br /&gt;
chmod a+x xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&lt;br /&gt;
./xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Put Xuggler into PATH&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/profile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the following at the bottom of the file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;export XUGGLE_HOME=/usr/local/xuggler&lt;br /&gt;
export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH&lt;br /&gt;
export PATH=$XUGGLE_HOME/bin:$PATH&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.red5tutorials.net/index.php/An_idiot&#039;s_guide_to_RMI/JMX_remote_connections_-_without_SSL_/_authentication Red5 Tutorials Website]&lt;br /&gt;
&lt;br /&gt;
== Cyber Citi Guides ==&lt;br /&gt;
[http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html/ Monitoring Tools]&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/linux-security.html/ Security Tips]&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html Linux Debian cheat sheet]&lt;br /&gt;
&lt;br /&gt;
== Dynamic MMap ran out of room ==&lt;br /&gt;
&lt;br /&gt;
Upon apt-get update&lt;br /&gt;
&lt;br /&gt;
E: Dynamic MMap ran out of room&lt;br /&gt;
E: Error occurred while processing mindi (NewVersion1)&lt;br /&gt;
E: Problem with MergeList /var/lib/apt/lists/mirrors.filename&lt;br /&gt;
E: The package lists or status file could not be parsed or opened.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/apt/lists&lt;br /&gt;
mv mirrors.filename old.mirrors.filename&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the error still persists try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cp lists/* /root/VarLibAptListsBACKUP -R&lt;br /&gt;
rm /var/lib/apt/lists/* -vf&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the error still persists then try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/apt/apt.conf.d/70debconf&lt;br /&gt;
APT::Cache-Limit &amp;quot;118388608&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update -o APT::Cache-Limit=25165824&lt;br /&gt;
apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Install LAMP ==&lt;br /&gt;
&lt;br /&gt;
apt-get install lamp-server^ phpmyadmin&lt;br /&gt;
&lt;br /&gt;
== Install SSL on Ubuntu 12.04 with Apache 2.2.22 ==&lt;br /&gt;
&lt;br /&gt;
This is for a fresh install, unmodified in any way from apt-get install apache2.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;a2ensite default-ssl&lt;br /&gt;
a2enmod ssl&lt;br /&gt;
service apache2 restart&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then go to https://yourhostname (either your domain or IP address), accept the certificate warning and you should see your website.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/apache2/ssl&lt;br /&gt;
vim /etc/apache2/sites-enabled/default-ssl&lt;br /&gt;
/SSLCertificateFile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press insert and edit the filepath of:&lt;br /&gt;
&lt;br /&gt;
SSLCertificateFile&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCertificateKeyFile&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCACertificateFile&lt;br /&gt;
&lt;br /&gt;
to direct to your files with the Certificate (.crt format), the Private Key (.key format) and the Intermediate Root CA Bundle (.crt format).&lt;br /&gt;
&lt;br /&gt;
Then vim each of the above filepaths and enter the certificate, key and Chain CA in their respective files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 600 /etc/apache2/ssl/SSLCertificateKeyFile&lt;br /&gt;
/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;[https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigating-the-beast-attack-on-tls mitigate the BEAST attack]&#039;&#039;&#039; and &#039;&#039;&#039;disable SSLv3&#039;&#039;&#039; enter the following into /etc/apache2/sites-enabled/default-ssl&lt;br /&gt;
&lt;br /&gt;
SSLHonorCipherOrder On&amp;lt;br&amp;gt;&lt;br /&gt;
SSLProtocol -all +TLSv1&amp;lt;br&amp;gt;&lt;br /&gt;
SSLCipherSuite ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;disable Apache and OS version&#039;&#039;&#039; put the following in /etc/apache2/sites-enabled/default-ssl &#039;&#039;&#039;outside&#039;&#039;&#039; of the VirtualHost tags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerTokens Prod&lt;br /&gt;
ServerSignature Off&lt;br /&gt;
TraceEnable Off&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/apache2 restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tokens is the header&amp;lt;br&amp;gt;&lt;br /&gt;
Signature is the footer&lt;br /&gt;
&lt;br /&gt;
[https://www.ssllabs.com/ssltest/analyze.html?d=bywatercraft.co.uk Example of these in place]&lt;br /&gt;
&lt;br /&gt;
To get 100 on SSL, see HN.&lt;br /&gt;
&amp;lt;!-- Only TLS 1.2&lt;br /&gt;
&lt;br /&gt;
Only these Ciphers allowed (256)&lt;br /&gt;
&lt;br /&gt;
Cipher Suites (SSLv3+ suites in server-preferred order, then SSLv2 suites where used)&lt;br /&gt;
TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA (0x88)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (0x6b)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_DHE_RSA_WITH_AES_256_CBC_SHA (0x39)   DH 4096 bits (p: 512, g: 1, Ys: 512)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_CBC_SHA256 (0x3d)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_GCM_SHA384 (0x9d)	256&lt;br /&gt;
TLS_RSA_WITH_CAMELLIA_256_CBC_SHA (0x84)	256&lt;br /&gt;
TLS_RSA_WITH_AES_256_CBC_SHA (0x35)	256&lt;br /&gt;
&lt;br /&gt;
Protocols&lt;br /&gt;
Session tickets	No &lt;br /&gt;
&lt;br /&gt;
https://community.qualys.com/thread/2013&lt;br /&gt;
http://www.apachehaus.com/forum/index.php?topic=628.0&lt;br /&gt;
&lt;br /&gt;
https://isc.sans.edu/diary.html?storyid=11629&lt;br /&gt;
Apache with OpenSSL - 1.0 only &lt;br /&gt;
Apache with GNUTLS - 1.2 is supported.  (note however that GNUTLS does not have the full feature set that OpenSSL does, nor does it have the body of testing, peer review and overall acceptance that OpenSSL has behind it.)&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;allow only TLS v1.2 only&#039;&#039;&#039; do [https://www.nnbfn.net/2011/05/tls-1-2-support-in-apache2 this]:&lt;br /&gt;
&lt;br /&gt;
apt-get install libgnutls28 libgnutls28-dbg libgnutls28-dev libgnutlsxx28--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== List all installed packages ==&lt;br /&gt;
&lt;br /&gt;
apt list --installed&lt;br /&gt;
&lt;br /&gt;
== Log Locations ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;FTP&#039;&#039;&#039;: /usr/local/psa/var/log/xferlog&lt;br /&gt;
&lt;br /&gt;
== Old Version of Plesk and an update fails ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when upgrading Plesk using the updates section in plesk:&lt;br /&gt;
&lt;br /&gt;
Installation could not be started: Unable to install packages because of package dependency problems. Not all packages were installed. ERROR: An error occurred on attempt to install packages. Attention! Your software might be inoperable. Please, contact product technical support.&lt;br /&gt;
&lt;br /&gt;
Check what Ubuntu OS you are running. To do this via command line run cat /etc/issue. &lt;br /&gt;
&lt;br /&gt;
=== Repositories ===&lt;br /&gt;
&lt;br /&gt;
The below repository issue most commonly happens on Ubuntu 6.06 as it is out of support now and the repos have changed. Edit the following file by using &#039;&#039;&#039;vim /etc/apt/sources.list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Comment out the old Ubuntu repository list using # (leave any others such as Plesk) and put in the below.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 6.06&#039;&#039;&#039; (Dapper Drake):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#Old-Release Sources&lt;br /&gt;
deb http://old-releases.ubuntu.com/ubuntu/ dapper  main universe multiverse&lt;br /&gt;
deb-src http://old-releases.ubuntu.com/ubuntu/ dapper  main universe multiverse&lt;br /&gt;
deb http://old-releases.ubuntu.com/ubuntu/ dapper-security main restricted universe multiverse&lt;br /&gt;
deb-src http://old-releases.ubuntu.com/ubuntu/ dapper-security main restricted universe multiverse&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error via [[SSH]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Err karmic/main Packages  404  Not Found&lt;br /&gt;
Err karmic/restricted Packages 404  Not Found&lt;br /&gt;
Err  karmic/universe Packages, 404  Not Found&lt;br /&gt;
Err  karmic-updates/main Packages 404  Not Found&lt;br /&gt;
Err karmic-updates/restricted Packages 404  Not Found&lt;br /&gt;
&lt;br /&gt;
vim /etc/apt/sources.list.d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
karmic.list is Ubuntu 9 which many hosters did not offer (hence no mirrors). If you are using lucid (Ubuntu 10), comment out the lines in this file. Apt should now update with no errors.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 8.04&#039;&#039;&#039; (Hardy Heron):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://archive.ubuntu.com/ubuntu hardy main restricted universe multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse&lt;br /&gt;
# Plesk&lt;br /&gt;
deb http://autoinstall.plesk.com/ubuntu/PSA8 hardy all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 10.04&#039;&#039;&#039; (Lucid Lynx):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb gb.archive.ubuntu.com lucid main restricted universe&lt;br /&gt;
deb gb.archive.ubuntu.com lucid-updates main restricted universe&lt;br /&gt;
deb gb.archive.ubuntu.com lucid-security main restricted universe&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: change mirrors from gb.archive.ubuntu.com to your own/your hosting companies if need be.&lt;br /&gt;
&lt;br /&gt;
Subversion repository guides: [https://help.ubuntu.com/10.04/serverguide/C/subversion.html 1], [http://www.howtogeek.com/howto/ubuntu/install-subversion-with-web-access-on-ubuntu/ 2], [http://geektaco.blogspot.co.uk/2010/05/using-ubuntu-1004-lts-server-for.html 3], [http://www.wikihow.com/Install-a-Subversion-Source-Control-Server-on-Ubuntu-10.04  4], [https://launchpad.net/ubuntu/lucid/+package/subversion 5]&lt;br /&gt;
&lt;br /&gt;
Additional repos:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://archive.ubuntu.com/ubuntu lucid universe&lt;br /&gt;
deb http://archive.canonical.com/ lucid partner&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Then run the following afterwards:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get update&lt;br /&gt;
/opt/psa/admin/bin/autoinstaller&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide more information as to which packages are causing the problem. Also try looking in the following log as this should have the info:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#/tmp/autoinstaller3.log&lt;br /&gt;
&lt;br /&gt;
Depending what is broken you may be able to force the install or configure the packages:&lt;br /&gt;
&lt;br /&gt;
apt-get -f install&lt;br /&gt;
dpkg -a configure-all&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If neither of those fix then rebuild the VPS. Also check if there have been any custom upgrades such as PHP as that can break it.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;&#039;Ubuntu 12.04&#039;&#039;&#039; (Precise Pangolin):&lt;br /&gt;
&lt;br /&gt;
http://ubuntuguide.org/wiki/Ubuntu:Precise#Edit_the_repository_sources_list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ dists/precise/main/binary-i386/&lt;br /&gt;
&lt;br /&gt;
# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ dists/precise/restricted/binary-i386/&lt;br /&gt;
# deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Beta amd64 (20120328)]/ precise main restricted&lt;br /&gt;
&lt;br /&gt;
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to&lt;br /&gt;
# newer versions of the distribution.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise main restricted&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise main restricted&lt;br /&gt;
&lt;br /&gt;
## Major bug fix updates produced after the final release of the&lt;br /&gt;
## distribution.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates main restricted&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates main restricted&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu&lt;br /&gt;
## team. Also, please note that software in universe WILL NOT receive any&lt;br /&gt;
## review or updates from the Ubuntu security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise universe&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise universe&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates universe&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates universe&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu &lt;br /&gt;
## team, and may not be under a free licence. Please satisfy yourself as to &lt;br /&gt;
## your rights to use the software. Also, please note that software in &lt;br /&gt;
## multiverse WILL NOT receive any review or updates from the Ubuntu&lt;br /&gt;
## security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise multiverse&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-updates multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-updates multiverse&lt;br /&gt;
&lt;br /&gt;
## N.B. software from this repository may not have been tested as&lt;br /&gt;
## extensively as that contained in the main release, although it includes&lt;br /&gt;
## newer versions of some applications which may provide useful features.&lt;br /&gt;
## Also, please note that software in backports WILL NOT receive any review&lt;br /&gt;
## or updates from the Ubuntu security team.&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse&lt;br /&gt;
# deb-src http://de.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse&lt;br /&gt;
&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security main restricted&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security main restricted&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security universe&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security universe&lt;br /&gt;
deb http://archive.ubuntu.com/ubuntu precise-security multiverse&lt;br /&gt;
# deb-src http://security.ubuntu.com/ubuntu precise-security multiverse&lt;br /&gt;
&lt;br /&gt;
## Uncomment the following two lines to add software from Canonical&#039;s&lt;br /&gt;
## &#039;partner&#039; repository.&lt;br /&gt;
## This software is not part of Ubuntu, but is offered by Canonical and the&lt;br /&gt;
## respective vendors as a service to Ubuntu users.&lt;br /&gt;
deb http://archive.canonical.com/ubuntu precise partner&lt;br /&gt;
# deb-src http://archive.canonical.com/ubuntu precise partner&lt;br /&gt;
&lt;br /&gt;
## This software is not part of Ubuntu, but is offered by third-party&lt;br /&gt;
## developers who want to ship their latest software.&lt;br /&gt;
deb http://extras.ubuntu.com/ubuntu precise main&lt;br /&gt;
# deb-src http://extras.ubuntu.com/ubuntu precise main&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Networking#IP_Tables | iptables]] ==&lt;br /&gt;
&lt;br /&gt;
If within Virtuozzo you receive &#039;&#039;&#039;Failed to add the firewall rule to the Input chain&#039;&#039;&#039; when editing the firewall: http://kb.parallels.com/6691&lt;br /&gt;
&lt;br /&gt;
== Set time ==&lt;br /&gt;
&lt;br /&gt;
The easiest way is to pick your timezone by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure tzdata&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.mosbase.com/2010/05/install-latest-version-of-mysql-on.html Upgrade MySQL on Ubuntu 8.04] ==&lt;br /&gt;
&lt;br /&gt;
== [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 Upgrade MySQL on Ubuntu 10.04] ==&lt;br /&gt;
&lt;br /&gt;
== [[General#VNC | VNC]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install vnc4server&lt;br /&gt;
vnc4server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted for a password. This password will be used to log into the vnc session.&lt;br /&gt;
After providing a password, you will get output that looks like:&lt;br /&gt;
New &#039;IP.IP.IP.IP:1 (laptop)&#039; desktop is IP.IP.IP.IP:1&lt;br /&gt;
     &lt;br /&gt;
Take notice of the number after the colon (:), in this case it is &amp;quot;1.&amp;quot; Starting the vnc4server will cause a .vnc directory to be placed in your home directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vnc4server -kill :1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the .vnc/xstartup file for editing.&lt;br /&gt;
     &lt;br /&gt;
&amp;lt;pre&amp;gt;vim ~/.vnc/xstartup&amp;lt;/pre&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
The file will look like:&lt;br /&gt;
      &lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
# Uncomment the following two lines for normal desktop:&lt;br /&gt;
#unset SESSION_MANAGER&lt;br /&gt;
#exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
xsetroot -solid grey&lt;br /&gt;
vncconfig -iconic &amp;amp;&lt;br /&gt;
xterm -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
twm &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Type :wq and hit enter. Uncomment the lines that start with unset and exec. Comment out the lines that start with xsetroot, vncconfig, xterm, and twm.&lt;br /&gt;
&lt;br /&gt;
The final file should look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
unset SESSION_MANAGER&lt;br /&gt;
exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
#xsetroot -solid grey&lt;br /&gt;
#vncconfig -iconic &amp;amp;&lt;br /&gt;
#xterm -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
#twm &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/sh&lt;br /&gt;
unset SESSION_MANAGER&lt;br /&gt;
exec /etc/X11/xinit/xinitrc&lt;br /&gt;
[ -x /etc/vnc/xstartup ] &amp;amp;&amp;amp; exec /etc/vnc/xstartup&lt;br /&gt;
[ -r $HOME/.Xresources ] &amp;amp;&amp;amp; xrdb $HOME/.Xresources&lt;br /&gt;
xsetroot -solid grey&lt;br /&gt;
vncconfig -iconic &amp;amp;&lt;br /&gt;
x-terminal-emulator -geometry 80x24+10+10 -ls -title &amp;quot;$VNCDESKTOP Desktop&amp;quot; &amp;amp;&lt;br /&gt;
x-window-manager &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the permissions on the /etc/X11/xinit/xinitrc file to make it executable. Run the server, install Ubuntu Desktop.&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod 755 /etc/X11/xinit/xinitrc&lt;br /&gt;
vnc4server&lt;br /&gt;
apt-get install ubuntu-desktop&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember the number after the colon (:). Log into your remote desktop to check the configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vncviewer IP.IP.IP.IP:1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide the password that you chose.&lt;br /&gt;
&lt;br /&gt;
== warning: setlocale: LC_ALL: cannot change locale ==&lt;br /&gt;
&lt;br /&gt;
If you get this error when logging in, or you get the below when doing locale-gen en_GB:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/bin/bash: warning: setlocale: LC_ALL: cannot change locale ((unset))&lt;br /&gt;
/usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale ((unset))&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You normally need to comment out LC_ALL=&amp;quot;(unset)&amp;quot; in /etc/environment or /root/.profile&lt;br /&gt;
&lt;br /&gt;
== Work Offline in Firefox ==&lt;br /&gt;
&lt;br /&gt;
If the browser in Ubuntu 10.04 is always set to Work Offline, go into about:config and set the following:&lt;br /&gt;
&lt;br /&gt;
browser:offline 		set to 	FALSE&lt;br /&gt;
network.online			set to 	TRUE&lt;br /&gt;
toolkit.networkmanager.disable 	set to 	FALSE&lt;br /&gt;
&lt;br /&gt;
Create New &amp;gt; Boolean&lt;br /&gt;
&lt;br /&gt;
network.manage-offline-status 	set to	FALSE&lt;br /&gt;
&lt;br /&gt;
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/191889&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1124</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1124"/>
		<updated>2019-05-23T14:00:55Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* updatedb (locate command) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1123</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1123"/>
		<updated>2019-05-23T13:56:30Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* PID */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;quot;c&amp;quot; key to show the file path a PID is being called from.&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1122</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1122"/>
		<updated>2019-05-23T13:45:15Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* eval */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this if you want to run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=User:Rootadminacc&amp;diff=1121</id>
		<title>User:Rootadminacc</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=User:Rootadminacc&amp;diff=1121"/>
		<updated>2019-05-22T15:57:08Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Notes to self ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Jira&amp;diff=1120</id>
		<title>Jira</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Jira&amp;diff=1120"/>
		<updated>2019-05-17T09:53:41Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Check version of Jira on Linux/Unix via command line ==&lt;br /&gt;
&lt;br /&gt;
This is specifically for if you are using a MySQL database.&lt;br /&gt;
&lt;br /&gt;
select * from propertystring where id = (select id from propertyentry where property_key = &#039;jira.version&#039;);&lt;br /&gt;
&lt;br /&gt;
== Update Jira ==&lt;br /&gt;
&lt;br /&gt;
Backup the XML database: https://confluence.atlassian.com/adminjiraserver074/backing-up-data-881683990.html&lt;br /&gt;
&lt;br /&gt;
Backup the dbconfig.xml file&lt;br /&gt;
&lt;br /&gt;
Backup the jira/data directory&lt;br /&gt;
&lt;br /&gt;
Then update either manually or with the installer:&lt;br /&gt;
&lt;br /&gt;
https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-manually-881683261.html&lt;br /&gt;
&lt;br /&gt;
https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-using-the-installer-881683273.html&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Jira&amp;diff=1119</id>
		<title>Jira</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Jira&amp;diff=1119"/>
		<updated>2019-05-17T09:22:22Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Update Jira */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Check version of Jira on Linux/Unix via command line ==&lt;br /&gt;
&lt;br /&gt;
This is specifically for if you are using a MySQL database.&lt;br /&gt;
&lt;br /&gt;
select * from propertystring where id = (select id from propertyentry where property_key = &#039;jira.version&#039;);&lt;br /&gt;
&lt;br /&gt;
== Update Jira ==&lt;br /&gt;
&lt;br /&gt;
Backup the XML database: https://confluence.atlassian.com/adminjiraserver074/backing-up-data-881683990.html&lt;br /&gt;
&lt;br /&gt;
Backup the dbconfig.xml file&lt;br /&gt;
&lt;br /&gt;
Backup the jira/data directory&lt;br /&gt;
&lt;br /&gt;
Then update either manually or with the installer:&lt;br /&gt;
&lt;br /&gt;
https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-manually-881683261.html&lt;br /&gt;
https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-using-the-installer-881683273.html&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Jira&amp;diff=1118</id>
		<title>Jira</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Jira&amp;diff=1118"/>
		<updated>2019-05-17T09:22:03Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Check version of Jira on Linux/Unix via command line ==&lt;br /&gt;
&lt;br /&gt;
This is specifically for if you are using a MySQL database.&lt;br /&gt;
&lt;br /&gt;
select * from propertystring where id = (select id from propertyentry where property_key = &#039;jira.version&#039;);&lt;br /&gt;
&lt;br /&gt;
== Update Jira ==&lt;br /&gt;
&lt;br /&gt;
Backup the XML database: https://confluence.atlassian.com/adminjiraserver074/backing-up-data-881683990.html&lt;br /&gt;
&lt;br /&gt;
Backup the dbconfig.xml file&lt;br /&gt;
&lt;br /&gt;
Backup the jira/data directory&lt;br /&gt;
&lt;br /&gt;
Then: https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-manually-881683261.html&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Jira&amp;diff=1117</id>
		<title>Jira</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Jira&amp;diff=1117"/>
		<updated>2019-05-17T08:59:41Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Check version of Jira on Linux/Unix via command line ==&lt;br /&gt;
&lt;br /&gt;
This is specifically for if you are using a MySQL database.&lt;br /&gt;
&lt;br /&gt;
select * from propertystring where id = (select id from propertyentry where property_key = &#039;jira.version&#039;);&lt;br /&gt;
&lt;br /&gt;
== Update Jira ==&lt;br /&gt;
&lt;br /&gt;
Backup the XML database: https://confluence.atlassian.com/adminjiraserver074/backing-up-data-881683990.html&lt;br /&gt;
&lt;br /&gt;
Backup the dbconfig.xml file&lt;br /&gt;
&lt;br /&gt;
Backup the jira/data directory&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
https://confluence.atlassian.com/adminjiraserver074/upgrading-jira-applications-manually-881683261.html&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1116</id>
		<title>MySQL</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1116"/>
		<updated>2019-05-17T08:57:44Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* MySQLdump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note: MySQL on Fedora and CentOS can be called mysqld&lt;br /&gt;
&lt;br /&gt;
== Backup a database ==&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/MySQL#MySQLdump&lt;br /&gt;
&lt;br /&gt;
== Before making changes... ==&lt;br /&gt;
&lt;br /&gt;
Use the commands BEGIN, COMMIT and ROLLBACK&lt;br /&gt;
&lt;br /&gt;
If your format is InnoDB, the majority of MySQL data is stored in the ibdata file.&lt;br /&gt;
&lt;br /&gt;
== Change character encoding  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use mysql &lt;br /&gt;
#or the database you want so for example; use moodle&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | character_set_database | latin1 |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alter database DatabaseName character set UTF8;&lt;br /&gt;
Query OK, 1 row affected (0.00 sec)&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | character_set_database | utf8 |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Exit MySQL and restart to be safe.&lt;br /&gt;
&lt;br /&gt;
=== Check database size ===&lt;br /&gt;
&lt;br /&gt;
http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://rackerhacker.com/2007/04/27/plesk-sql-statements Check email passwords] ==&lt;br /&gt;
&lt;br /&gt;
== Check MySQL users ==&lt;br /&gt;
&lt;br /&gt;
Short versions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select User from mysql.user;&lt;br /&gt;
select User,Host from mysql.user;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Long version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from mysql.user\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pantz.org/software/mysql/mysqlcommands.html Common Commands] ==&lt;br /&gt;
&lt;br /&gt;
Log into MySQL, use database and then check MySQL process list which display the database being accessed, the command and the time in minutes it has been running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show processlist;&lt;br /&gt;
show full processlist;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check all database/tables for corruption using one of these commands outside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For DH server use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
mysqlcheck: Got error: 1045: Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO) when trying to connect . Use this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uadmin -p`cat /etc/psa/.psa.shadow` -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Skip grant tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
mysqld_safe --skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Table names in MySQL are case sensitive.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;locate my.cnf&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For importing large database files, I would recommend using a software like HeidiSQL to import your Databases, as PhpMyAdmin is often problematic when attempting to upload databases of a larger size.  &lt;br /&gt;
&lt;br /&gt;
http://www.heidisql.com/&lt;br /&gt;
&lt;br /&gt;
The below command will &#039;&#039;&#039;show you how a database table was created&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
show create table tables_name\G&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Show all where the start of the entry begins with a&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from table where name like &#039;a%&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.w3schools.com/sql/sql_distinct.asp This] is used to return only different values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT DISTINCT column/row from table;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [http://www.w3schools.com/sql/sql_orderby.asp ORDER BY] keyword is used to &#039;&#039;&#039;sort the result-set&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT column_name&lt;br /&gt;
FROM table_name&lt;br /&gt;
ORDER BY column_name ASC|DESC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
e.g. select * from domains ORDER BY &amp;quot;name&amp;quot; DESC;&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;return the number of records in a table&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
select count(*) from table;&lt;br /&gt;
&lt;br /&gt;
=== [http://support.modwest.com/content/6/60/en/how-do-i-connect-to-my-mysql-database.html#monitor Connect to MySQL database] ===&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -d database -p&amp;lt;br&amp;gt; &lt;br /&gt;
mysql -h 127.0.0.1 -u username -d database -p&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -Ddatabase -p&lt;br /&gt;
&lt;br /&gt;
== Connect to MySQL remotely ==&lt;br /&gt;
&lt;br /&gt;
To allow external access to MySQL &#039;&#039;&#039;comment out&#039;&#039;&#039; the following line in my.cnf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;bind-address           = 127.0.0.1&lt;br /&gt;
#bind-address           = 127.0.0.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restart MySQL.&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html Enable remote connection]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely Connect remotely]&lt;br /&gt;
&lt;br /&gt;
To connect from a Linux box to another you can try:&lt;br /&gt;
&lt;br /&gt;
mysql -h IPaddress -uusername -p -D database&lt;br /&gt;
&lt;br /&gt;
== Convert all MySQL tables and fields to UTF8 ==&lt;br /&gt;
&lt;br /&gt;
mysql --database=dbname -B -N -e &amp;quot;SHOW TABLES&amp;quot;  | awk &#039;{print &amp;quot;ALTER TABLE&amp;quot;, $1, &amp;quot;CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;&amp;quot;}&#039; | mysql --database=dbname &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This loops through all tables and changes their collations to UTF8. You should backup beforehand though in case some data is lost in the process. Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
UTF-8 UTF utf-8 utf&lt;br /&gt;
&lt;br /&gt;
== Create table with text ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName ( ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName (&lt;br /&gt;
ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Deleting large amount of data ==&lt;br /&gt;
&lt;br /&gt;
You may get:&lt;br /&gt;
&lt;br /&gt;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction&lt;br /&gt;
&lt;br /&gt;
You can see more details of the event by issuing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SHOW ENGINE INNODB STATUS\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show variables like &#039;innodb_lock_wait_timeout&#039;;&lt;br /&gt;
set innodb_lock_wait_timeout=100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also set it to a higher value in /etc/my.cnf permanently with this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[mysqld]&lt;br /&gt;
innodb_lock_wait_timeout=120&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and then restart mysql. If you cannot restart mysql at this time, run this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET GLOBAL innodb_lock_wait_timeout = 120;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of locked tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show open tables where in_use&amp;gt;0;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of the current processes, one of them might be locking your table(s):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; show processlist;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then kill one of these processes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;kill put_process_id_here;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delete user ==&lt;br /&gt;
&lt;br /&gt;
drop user@localhost;&lt;br /&gt;
&lt;br /&gt;
== [http://www.microsoft.com/en-us/download/details.aspx?id=7593 Download SQL Server Management Studio] ==&lt;br /&gt;
&lt;br /&gt;
== Drop database, table or row/column ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database DatabaseName;&lt;br /&gt;
drop table TableName;&lt;br /&gt;
&lt;br /&gt;
#Delete a row(s) from a table&lt;br /&gt;
DELETE from TableName where FieldName] = &#039;value&#039;;&lt;br /&gt;
&lt;br /&gt;
#Delete a column&lt;br /&gt;
alter table TableName drop column ColumnName;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump a single table ==&lt;br /&gt;
&lt;br /&gt;
mysqldump -pPASSWORD DatabaseName TableName &amp;gt; table.sql&lt;br /&gt;
&lt;br /&gt;
To dump in XML format, use --xml after mysqldump&lt;br /&gt;
&lt;br /&gt;
== Dump a database ==&lt;br /&gt;
&lt;br /&gt;
If you have a backup of the MySQL database in a .sql file, delete the database first within mysql:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database NameOfDatabaseToBeDeleted;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then dump the .sql file into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uroot -p &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump database/s &amp;amp; copy database/s from one Plesk server to another ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linux&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
On the old server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&lt;br /&gt;
scp &amp;lt;database&amp;gt;.sql root@VPS_IP:&lt;br /&gt;
yes&lt;br /&gt;
*Paste the password in*&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the new server; check the mysql databases to ensure it isn&#039;t already there, go into Plesk and create it with the same name and then after the command below create a database user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;lt; /root/&amp;lt;database&amp;gt;.sql #or just /&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- [http://www.snowfrog.net/2005/11/16/backup-multiple-databases-into-separate-files/ Backup multiple DBs into separate files] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://serverkb.co.uk/tools/dbdump.sh Backup script] ===&lt;br /&gt;
&lt;br /&gt;
Made by [[User:Trilium]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- #!/bin/bash &lt;br /&gt;
######################################################## &lt;br /&gt;
# Database backup script &lt;br /&gt;
######################################################## &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
CHROOTMYSQLPASS=**** &lt;br /&gt;
MYSQLBACKUPDIR=/root/database_backup &lt;br /&gt;
EXCLUDE=&amp;quot;mysql psa information_schema horde atmail admin&amp;quot; &lt;br /&gt;
&lt;br /&gt;
#Edit this. grep -v phpmyadmin and exclude it&lt;br /&gt;
 &lt;br /&gt;
if [ -d $MYSQLBACKUPDIR ] &lt;br /&gt;
then &lt;br /&gt;
echo &amp;quot;$MYSQLBACKUPDIR exists&amp;quot; &lt;br /&gt;
else &lt;br /&gt;
mkdir -p $MYSQLBACKUPDIR &lt;br /&gt;
fi &lt;br /&gt;
 &lt;br /&gt;
DBNAMES=&amp;quot;$(mysql -h server0 -u root -p$CHROOTMYSQLPASS -Bse &#039;show databases&#039;)&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $EXCLUDE &lt;br /&gt;
do &lt;br /&gt;
DBNAMES=`echo $DBNAMES | sed &amp;quot;s/\b$DATABASE\b//g&amp;quot;` &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $DBNAMES &lt;br /&gt;
do &lt;br /&gt;
echo &amp;quot;Backing up $DATABASE&amp;quot; &lt;br /&gt;
FILENAME=&amp;quot;$MYSQLBACKUPDIR/$DATABASE.sql&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
mysqldump --lock-tables=false -h server0 -u root -p$CHROOTMYSQLPASS $DATABASE &amp;gt; $FILENAME &lt;br /&gt;
 &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
tar -czvf database_backup.tar.gz $MYSQLBACKUPDIR/*.sql &lt;br /&gt;
 &lt;br /&gt;
echo Backup complete to database_backup.tar.gz  --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enable Slow Query Logging ==&lt;br /&gt;
&lt;br /&gt;
Only valid for Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
chmod +x slow.sh&lt;br /&gt;
./snow.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entering MySQL and selecting a database/table ==&lt;br /&gt;
&lt;br /&gt;
On a Plesk server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
show databases;&lt;br /&gt;
use database (e.g. psa)&lt;br /&gt;
show tables;&lt;br /&gt;
select * from domains; or \G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&lt;br /&gt;
mysql -uadmin -p&#039;$AES...==&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd %plesk_dir%\mysql\bin&lt;br /&gt;
mysql -uadmin -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below goes into the Plesk database MySQL area:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p -P8306&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may need to reset the admin password via Plesk. Get the PW by doing this in Run:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;%plesk_bin%\plesksrvclient&amp;quot; -get&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 4.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 5.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C:\Program Files (x86)\Parallels\Plesk\MySQL\Data\my is the my.cnf equivalent.&lt;br /&gt;
&lt;br /&gt;
== ERROR 1175 ==&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
You will need to do desc TableName; to see which Field uses a Key. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from zone_records;&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
| zone                       | type   | record | prefix       | ttl   | data                        |&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;domain.co.uk&amp;quot; where record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; desc zone_records;&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| Field  | Type                                            | Null | Key | Default  | Extra |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| zone   | varchar(255)                                    | NO   | MUL |          |       |&lt;br /&gt;
| type   | enum(&#039;username&#039;,&#039;domain&#039;,&#039;component&#039;,&#039;default&#039;) | NO   |     | username |       |&lt;br /&gt;
| record | enum(&#039;A&#039;,&#039;MX&#039;,&#039;CNAME&#039;,&#039;PTR&#039;,&#039;TXT&#039;)              | YES  |     | NULL     |       |&lt;br /&gt;
| prefix | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
| ttl    | int(10) unsigned                                | YES  |     | NULL     |       |&lt;br /&gt;
| data   | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;dev.domain.co.uk&amp;quot; where zone=&amp;quot;domain.co.uk&amp;quot; and record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Flat Files ==&lt;br /&gt;
&lt;br /&gt;
These are the .mdf and .ldf files.&lt;br /&gt;
&lt;br /&gt;
== Got a packet bigger than &#039;max_allowed_packet&#039; bytes ==&lt;br /&gt;
&lt;br /&gt;
In my.cnf add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;max_allowed_packet = 10M&lt;br /&gt;
#or 100M&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import sqlite to MySQL ==&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql Stack Overflow Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4140210/shell-file-to-import-sqlite-into-mysql Stack Overflow Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.google.co.uk/search?hl=en&amp;amp;safe=off&amp;amp;site=&amp;amp;source=hp&amp;amp;q=import+sqlite+to+mysql&amp;amp;oq=import+sqlite+&amp;amp;aq=5&amp;amp;aqi=g10&amp;amp;aql=&amp;amp;gs_nf=1&amp;amp;gs_l=hp.3.5.0l10.647.6084.0.8595.14.14.0.4.4.0.148.866.8j2.10.0.0kqDvPY0M4E Google search]&lt;br /&gt;
&lt;br /&gt;
[http://www.php.net/manual/en/mysqli.installation.php mysqli]&lt;br /&gt;
&lt;br /&gt;
== Plesk database location ==&lt;br /&gt;
&lt;br /&gt;
on Windows is C:\Program Files (x86)\Parallels\Plesk\Databases\MySQL\data normally.&lt;br /&gt;
&lt;br /&gt;
== [http://www.theadminzone.com/forums/showthread.php?p=564138 Optimizing MySQL database] ==&lt;br /&gt;
&lt;br /&gt;
Utilise functions such as Query Caching to serve results of previous repeated queries to reduce load.&lt;br /&gt;
&lt;br /&gt;
Some of the main cause of databases degradation usually relates to overly complex queries and large log tables, for information on how to improve this performance on Magento please see [http://www.quentinnel.com/2009/10/01/magento-and-log-cleaning this] and [http://www.magentocommerce.com/boards/viewthread/36225 this].&lt;br /&gt;
&lt;br /&gt;
== Manually create database and user (Unix) ==&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database NewDatabase;&lt;br /&gt;
show databases;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to dump a database.sql file onto the new database you have just created, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p NewDatabase &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the new user that will be assigned to the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;YourUsername&#039;@&#039;localhost&#039; identified by &#039;plaintextpassword&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then to assign a user to the database, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use NewDatabase&lt;br /&gt;
grant usage on NewDatabase.* to YourUsername@localhost identified by &#039;plaintextpassword&#039;;&lt;br /&gt;
grant all privileges on `NewDatabase`.* to &#039;YourUsername&#039;@&#039;localhost&#039;;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then test the connection works to the database with that username and password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -h localhost -u YourUser -DNewDatabase -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Monitor queries ==&lt;br /&gt;
&lt;br /&gt;
watch -n 1 mysqladmin --user=&amp;lt;user&amp;gt; --password=&amp;lt;password&amp;gt; processlist&lt;br /&gt;
&lt;br /&gt;
== MySQLdump ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -u username -p database_to_backup &amp;gt; backup_name.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump: Couldn&#039;t execute &#039;SHOW VARIABLES LIKE &#039;gtid\_mode&#039;&#039;: Table &#039;performance_schema.session_variables&#039; doesn&#039;t exist (1146)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql_upgrade -u root -p --force&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restart mysql:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service mysql restart&lt;br /&gt;
service mysqld restart&lt;br /&gt;
systemctl restart mysql&lt;br /&gt;
systemctl restart mysqld&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this doesn&#039;t work you may need this fix: http://www.lampdocs.com/couldnt-execute-show-variables-like-gtid_mode-table-performance_schema-session_variables-doesnt-exist-1146-how-to-fix/&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD server ===&lt;br /&gt;
&lt;br /&gt;
You may need to chroot into the appropriate environment. The mysqldump location will either be /mysql/bin/mysqldump or /usr/fs//mysql/bin/mysqldump&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p&amp;lt;password&amp;gt; &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://stackoverflow.com/questions/13996606/add-database-name-to-sql-file-when-exporting-using-mysqldump-via-linux Multiple exports to .sql files] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
dbs=&#039;firstdb seconddb thirddb&#039;&lt;br /&gt;
&lt;br /&gt;
echo -n &#039;Enter database password: &#039;&lt;br /&gt;
read pw&lt;br /&gt;
&lt;br /&gt;
for db in $dbs&lt;br /&gt;
do&lt;br /&gt;
    mysqldump -u user -h localhost -p$pw $db &amp;gt; $db_1_$(date +%d%m%y).sql&lt;br /&gt;
done&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plesk server === &lt;br /&gt;
&lt;br /&gt;
Unix: &amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
Windows: &amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL errors/issues ==&lt;br /&gt;
&lt;br /&gt;
=== Database already exists importing via PHP My Admin ===&lt;br /&gt;
&lt;br /&gt;
Go to Tools &amp;amp; Settings &amp;gt; Applications &amp;amp; Databases - Database Servers &amp;gt; Webadmin &amp;gt; Import the Database here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`&lt;br /&gt;
show databases;&lt;br /&gt;
quit&lt;br /&gt;
mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;gt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure there are no databases in Plesk under domain in Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases. Remove any if they exist. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;lt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go back into Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases &amp;gt; Database &amp;gt; Add a Database user &amp;gt; Access Webadmin/PHP My Admin&lt;br /&gt;
&lt;br /&gt;
=== Can&#039;t connect to local MySQL server through socket ===&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_connect() [function.mysql-connect]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 10&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_select_db() [function.mysql-select-db]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 11&lt;br /&gt;
&lt;br /&gt;
ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2)&lt;br /&gt;
&lt;br /&gt;
Restart MySQL (via chroot environment if needed).&lt;br /&gt;
&lt;br /&gt;
Check the error log and if need be increase the innodb buffer pool size from it&#039;s default 2M. Also ensure the file /var/run/mysqld/mysqld.sock has mysql:mysql and socket permissions (use mkfifo).&lt;br /&gt;
&lt;br /&gt;
http://forums.mysql.com/read.php?22,423592,423592#msg-423592&lt;br /&gt;
&lt;br /&gt;
=== Memory allocation error in Plesk ===&lt;br /&gt;
&lt;br /&gt;
[MySQL][ODBC 3.51 Driver][mysqld-5.0.95-0ubuntu1]Memory allocation error &lt;br /&gt;
File 	aps_php.php&amp;lt;br&amp;gt;&lt;br /&gt;
Line 	7476&amp;lt;br&amp;gt;&lt;br /&gt;
Type 	Exception&lt;br /&gt;
&lt;br /&gt;
[http://forum.parallels.com/pda/index.php/t-258020.html How to fix on Ubuntu 10.04] + http://kb.parallels.com/113620&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;pre&amp;gt;mkdir deb&lt;br /&gt;
cd deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev*&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
cd deb&lt;br /&gt;
ls&lt;br /&gt;
rm index.html; ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.95-0ubuntu1_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
ls&lt;br /&gt;
rm *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.51a-3ubuntu5_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15off_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQLSTATE[HY000]: General error: 1030 Got error 122 from storage engine ===&lt;br /&gt;
&lt;br /&gt;
Disk space is full normally. Run df -h to find out.&lt;br /&gt;
&lt;br /&gt;
=== Big BLOB or TEXT rows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;InnoDB: ERROR: the age of the last checkpoint is 9433569,&lt;br /&gt;
InnoDB: largest such row.&lt;br /&gt;
InnoDB: combined size of log files at least 10 times bigger than the&lt;br /&gt;
InnoDB: If you are using big BLOB or TEXT rows, you must set the&lt;br /&gt;
InnoDB: which exceeds the log group capacity 9433498.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error message can mean that you&#039;re trying to insert too much data into InnoDB too quickly, and the InnoDB log is filling up before the data can be flushed into the main data files.&lt;br /&gt;
&lt;br /&gt;
To solve it, you need to stop MySQL cleanly (very important), delete the existing InnoDB log files (probably lb_logfile* in your MySQL data directory, unless you&#039;ve moved them), then adjust theinnodb_log_file_size to suit your needs, and then start MySQL again.&lt;br /&gt;
&lt;br /&gt;
Also see the &amp;lt;pre&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;/pre&amp;gt; box in [[Plesk_Fatal_Exception#Can.27t_connect_to_MySQL_Database | this link]].&lt;br /&gt;
&lt;br /&gt;
== PHP Connector guides ==&lt;br /&gt;
&lt;br /&gt;
http://www.phpfreaks.com/forums/index.php?topic=232018.0&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.dreamincode.net/forums/topic/80945-php-mysql-connector&amp;lt;br&amp;gt;&lt;br /&gt;
http://tycoontalk.freelancer.com/php-forum/19135-php-mysql-connection-problems.html&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would advise reading the following guide in regards to the Windows sections: http://www.ora600.be/node/3511&lt;br /&gt;
&lt;br /&gt;
This refers to the error &amp;quot;Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP&amp;quot; and can happen due to the PHP installation not having the MySQL compiled within it.&lt;br /&gt;
&lt;br /&gt;
== PHP My Admin ==&lt;br /&gt;
&lt;br /&gt;
=== 1077 Error ===&lt;br /&gt;
&lt;br /&gt;
When you upload a file into phpMyAdmin and it shows a 1077 error, you are likely uploading the wrong file type. It needs to be as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;File may be compressed (gzip, zip) or uncompressed.&lt;br /&gt;
A compressed file&#039;s name must end in .[format].[compression]. Example: .sql.zip&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you right click the .sql file and zip it and then try it should work as long as it is below 2GB.&lt;br /&gt;
&lt;br /&gt;
=== Export issue ===&lt;br /&gt;
&lt;br /&gt;
The error normally shown is &amp;quot;can’t find the file at https://xx.xx.xx.xx:8443/domains/databases/phpMyAdmin/export.php&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /usr/local/psa/admin/conf/php.ini&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing&#039;&#039;&#039; memory_limit&#039;&#039;&#039;. Increase this to &#039;&#039;&#039;512M&#039;&#039;&#039; or &#039;&#039;&#039;1024M&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/sw-cp-server restart&lt;br /&gt;
/etc/init.d/psa stopall&lt;br /&gt;
/etc/init.d/psa startall&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Repair database/s ==&lt;br /&gt;
&lt;br /&gt;
To repair one database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair DatabaseName -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or to repair all databases:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair --all-databases -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reset root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
Quick way if you already know the password, outside of MySQL do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqladmin -u root -p&#039;OldPassword&#039; password NewPassword&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET PASSWORD FOR &#039;root&#039;@&#039;localhost&#039;=PASSWORD(&#039;MyNewPass&#039;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t know the current password:&lt;br /&gt;
&lt;br /&gt;
=== [http://kwatog.com/blog/reset-mysql-root-password-in-centos CentOS] ===&lt;br /&gt;
&lt;br /&gt;
The same steps basically.&lt;br /&gt;
&lt;br /&gt;
=== Debian ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
/usr/bin/mysqld_safe --skip-grant-tables &amp;amp;&lt;br /&gt;
[1] 32305&lt;br /&gt;
130401 22:43:57 mysqld_safe Logging to syslog.&lt;br /&gt;
130401 22:43:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whilst this is at a blank line, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --user=root mysql&lt;br /&gt;
update user set Password=PASSWORD(&#039;new-password-here&#039;) WHERE User=&#039;root&#039;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then stop and start the server:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql restart&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysqld stop&lt;br /&gt;
mysqld_safe –skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or &lt;br /&gt;
&lt;br /&gt;
mysqld_safe -–skip-grant-tables &amp;amp; (two hyphens)&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use mysql;&lt;br /&gt;
update user set password=PASSWORD(“yourpassword”) where User=’root’;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;update user set password=PASSWORD(“yourpassword”) where User=’admin’&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should now be able to log in as root/admin using the “yourpassword” that you entered.&lt;br /&gt;
&lt;br /&gt;
[http://www.achawkins.com/tech/regain-lost-root-mysql-access-permissions-when-connecting-from-localhost Regain lost root MySQL access permissions connecting from localhost]&lt;br /&gt;
&lt;br /&gt;
Alternatively do this (on a Plesk server only):&lt;br /&gt;
&lt;br /&gt;
Get the password via the command below, and keep for later*. If it is Plesk 11 you need to copy from the &#039;&#039;&#039;$ up to but not including&#039;&#039;&#039; the word &#039;&#039;&#039;root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter this into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;skip-grant-tables&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file. Then restart MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&lt;br /&gt;
mysql&lt;br /&gt;
use mysql&lt;br /&gt;
update user set password=PASSWORD (&amp;quot;*&amp;quot;) where user=&amp;quot;admin&amp;quot;;&lt;br /&gt;
flush privileges&lt;br /&gt;
exit&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove skip-grant-tables from /etc/mysql/my.cnf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run a command externally/outside of MySQL ==&lt;br /&gt;
&lt;br /&gt;
mysql -p`cat PasswordFile` -D DatabaseName -e &amp;quot;select * from dbname;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Set root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
You obviously must know it already:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
update user set password=PASSWORD(&amp;quot;yourpassword&amp;quot;) where User=&amp;quot;root&amp;quot;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then attempt to access MySQL:&lt;br /&gt;
&lt;br /&gt;
mysql -p&amp;lt;br&amp;gt;&lt;br /&gt;
yourpassword&lt;br /&gt;
&lt;br /&gt;
== Show users permissions ==&lt;br /&gt;
&lt;br /&gt;
show grants;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
SHOW GRANTS FOR &#039;root&#039;@&#039;localhost&#039;;&lt;br /&gt;
&lt;br /&gt;
=== All users ===&lt;br /&gt;
&lt;br /&gt;
SELECT User FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT * FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT CONCAT(&#039;SHOW GRANTS FOR &#039;&#039;&#039;,user,&#039;&#039;&#039;@&#039;&#039;&#039;,host,&#039;&#039;&#039;;&#039;) FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
http://dbadiaries.com/no-mysql-show-users-how-to-list-mysql-user-accounts-and-their-privileges&lt;br /&gt;
&lt;br /&gt;
== Show over 1000 rows ==&lt;br /&gt;
&lt;br /&gt;
use database&lt;br /&gt;
select * from table where type=&amp;quot;HeaderValue&amp;quot; LIMIT 0,99999;&lt;br /&gt;
&lt;br /&gt;
== Show tables column headers ==&lt;br /&gt;
&lt;br /&gt;
show columns from table;&lt;br /&gt;
&lt;br /&gt;
== Uninstall MySQL completely (Unix) ==&lt;br /&gt;
&lt;br /&gt;
If for example you have installed mysql-server, then uninstalled, then installed it again but it is not prompting you for the root password like before, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get purge mysql-server mysql-common mysql-client&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Unknown table engine &#039;InnoDB&#039; ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;MySQL query failed: Unknown table engine &#039;InnoDB&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Look inside the /etc/mysql/my.cnf file and ensure you don&#039;t have skip-innodb in there. If so, comment out and restart MySQL.&lt;br /&gt;
&lt;br /&gt;
== [http://www.mosbase.com/2010/05/install-latest-version-of-mysql-on.html Upgrade on Ubuntu 8.04] ==&lt;br /&gt;
&lt;br /&gt;
== [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 Upgrade on Ubuntu 10.04] ==&lt;br /&gt;
&lt;br /&gt;
Alternate guides: [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 1], [http://www.php-trivandrum.org/general-articles/how-i-got-mysql-55-running-on-ubuntu-10-server 2], [http://akbarahmed.com/2012/04/08/install-mysql-5-5-on-ubuntu-10-04-lts-running-in-the-rackspace-cloud-2 3]&lt;br /&gt;
&lt;br /&gt;
=== MySQL 5.5. error ===&lt;br /&gt;
&lt;br /&gt;
If you get the below error when stopping MySQL after upgrading MySQL from 5.1 to 5.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
* MySQL server PID file could not be found!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | grep mysql&lt;br /&gt;
#this will then show the below output&lt;br /&gt;
mysql    11683  0.0  3.5 410276 71276 ?        Sl   06:48   0:00 mysqld --skip-grant-tables --user=mysql&lt;br /&gt;
&lt;br /&gt;
#kill the process id&lt;br /&gt;
kill 11683&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
/etc/init.d/mysql stop&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
&lt;br /&gt;
ps aux | grep mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
root      5291  0.1  0.0   4088   668 pts/1    S    09:51   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/serverhostname.pid&amp;lt;br&amp;gt;&lt;br /&gt;
mysql     5615  1.1  4.2 621124 84776 pts/1    Sl   09:51   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log&amp;lt;br&amp;gt;&lt;br /&gt;
--pid-file=/usr/local/mysql/data/serverhostname.pid --socket=/var/run/mysqld/mysqld.sock --port=3306&amp;lt;br&amp;gt;&lt;br /&gt;
root      5670  0.0  0.0   6156   696 pts/1    S+   09:51   0:00 grep mysql&lt;br /&gt;
&lt;br /&gt;
== Version 5.5 on CentOS 6 with Plesk ==&lt;br /&gt;
&lt;br /&gt;
This is really only possible on CentOS 5, as of 08/03/2013&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm&lt;br /&gt;
rpm -Uvh remi-release-6*.rpm&lt;br /&gt;
vim /etc/yum.repos.d/remi.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the top &amp;lt;nowiki&amp;gt;[remi]&amp;lt;/nowiki&amp;gt; to enabled=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;yum list mysql-server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://dba.stackexchange.com/questions/16316/why-can-i-only-install-mysql-5-1-on-cent-os-6-2 A script to get the latest MySQL 5.5 for RHEL6]&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use the Atomic repo, however you &#039;&#039;&#039;must&#039;&#039;&#039; disable it afterwards, otherwise it may remove Plesk when it auto-updates.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1115</id>
		<title>MySQL</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1115"/>
		<updated>2019-05-17T08:57:07Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* MySQLdump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note: MySQL on Fedora and CentOS can be called mysqld&lt;br /&gt;
&lt;br /&gt;
== Backup a database ==&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/MySQL#MySQLdump&lt;br /&gt;
&lt;br /&gt;
== Before making changes... ==&lt;br /&gt;
&lt;br /&gt;
Use the commands BEGIN, COMMIT and ROLLBACK&lt;br /&gt;
&lt;br /&gt;
If your format is InnoDB, the majority of MySQL data is stored in the ibdata file.&lt;br /&gt;
&lt;br /&gt;
== Change character encoding  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use mysql &lt;br /&gt;
#or the database you want so for example; use moodle&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | character_set_database | latin1 |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alter database DatabaseName character set UTF8;&lt;br /&gt;
Query OK, 1 row affected (0.00 sec)&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | character_set_database | utf8 |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Exit MySQL and restart to be safe.&lt;br /&gt;
&lt;br /&gt;
=== Check database size ===&lt;br /&gt;
&lt;br /&gt;
http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://rackerhacker.com/2007/04/27/plesk-sql-statements Check email passwords] ==&lt;br /&gt;
&lt;br /&gt;
== Check MySQL users ==&lt;br /&gt;
&lt;br /&gt;
Short versions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select User from mysql.user;&lt;br /&gt;
select User,Host from mysql.user;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Long version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from mysql.user\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pantz.org/software/mysql/mysqlcommands.html Common Commands] ==&lt;br /&gt;
&lt;br /&gt;
Log into MySQL, use database and then check MySQL process list which display the database being accessed, the command and the time in minutes it has been running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show processlist;&lt;br /&gt;
show full processlist;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check all database/tables for corruption using one of these commands outside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For DH server use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
mysqlcheck: Got error: 1045: Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO) when trying to connect . Use this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uadmin -p`cat /etc/psa/.psa.shadow` -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Skip grant tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
mysqld_safe --skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Table names in MySQL are case sensitive.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;locate my.cnf&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For importing large database files, I would recommend using a software like HeidiSQL to import your Databases, as PhpMyAdmin is often problematic when attempting to upload databases of a larger size.  &lt;br /&gt;
&lt;br /&gt;
http://www.heidisql.com/&lt;br /&gt;
&lt;br /&gt;
The below command will &#039;&#039;&#039;show you how a database table was created&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
show create table tables_name\G&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Show all where the start of the entry begins with a&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from table where name like &#039;a%&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.w3schools.com/sql/sql_distinct.asp This] is used to return only different values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT DISTINCT column/row from table;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [http://www.w3schools.com/sql/sql_orderby.asp ORDER BY] keyword is used to &#039;&#039;&#039;sort the result-set&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT column_name&lt;br /&gt;
FROM table_name&lt;br /&gt;
ORDER BY column_name ASC|DESC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
e.g. select * from domains ORDER BY &amp;quot;name&amp;quot; DESC;&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;return the number of records in a table&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
select count(*) from table;&lt;br /&gt;
&lt;br /&gt;
=== [http://support.modwest.com/content/6/60/en/how-do-i-connect-to-my-mysql-database.html#monitor Connect to MySQL database] ===&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -d database -p&amp;lt;br&amp;gt; &lt;br /&gt;
mysql -h 127.0.0.1 -u username -d database -p&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -Ddatabase -p&lt;br /&gt;
&lt;br /&gt;
== Connect to MySQL remotely ==&lt;br /&gt;
&lt;br /&gt;
To allow external access to MySQL &#039;&#039;&#039;comment out&#039;&#039;&#039; the following line in my.cnf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;bind-address           = 127.0.0.1&lt;br /&gt;
#bind-address           = 127.0.0.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restart MySQL.&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html Enable remote connection]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely Connect remotely]&lt;br /&gt;
&lt;br /&gt;
To connect from a Linux box to another you can try:&lt;br /&gt;
&lt;br /&gt;
mysql -h IPaddress -uusername -p -D database&lt;br /&gt;
&lt;br /&gt;
== Convert all MySQL tables and fields to UTF8 ==&lt;br /&gt;
&lt;br /&gt;
mysql --database=dbname -B -N -e &amp;quot;SHOW TABLES&amp;quot;  | awk &#039;{print &amp;quot;ALTER TABLE&amp;quot;, $1, &amp;quot;CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;&amp;quot;}&#039; | mysql --database=dbname &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This loops through all tables and changes their collations to UTF8. You should backup beforehand though in case some data is lost in the process. Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
UTF-8 UTF utf-8 utf&lt;br /&gt;
&lt;br /&gt;
== Create table with text ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName ( ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName (&lt;br /&gt;
ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Deleting large amount of data ==&lt;br /&gt;
&lt;br /&gt;
You may get:&lt;br /&gt;
&lt;br /&gt;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction&lt;br /&gt;
&lt;br /&gt;
You can see more details of the event by issuing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SHOW ENGINE INNODB STATUS\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show variables like &#039;innodb_lock_wait_timeout&#039;;&lt;br /&gt;
set innodb_lock_wait_timeout=100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also set it to a higher value in /etc/my.cnf permanently with this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[mysqld]&lt;br /&gt;
innodb_lock_wait_timeout=120&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and then restart mysql. If you cannot restart mysql at this time, run this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET GLOBAL innodb_lock_wait_timeout = 120;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of locked tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show open tables where in_use&amp;gt;0;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of the current processes, one of them might be locking your table(s):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; show processlist;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then kill one of these processes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;kill put_process_id_here;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delete user ==&lt;br /&gt;
&lt;br /&gt;
drop user@localhost;&lt;br /&gt;
&lt;br /&gt;
== [http://www.microsoft.com/en-us/download/details.aspx?id=7593 Download SQL Server Management Studio] ==&lt;br /&gt;
&lt;br /&gt;
== Drop database, table or row/column ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database DatabaseName;&lt;br /&gt;
drop table TableName;&lt;br /&gt;
&lt;br /&gt;
#Delete a row(s) from a table&lt;br /&gt;
DELETE from TableName where FieldName] = &#039;value&#039;;&lt;br /&gt;
&lt;br /&gt;
#Delete a column&lt;br /&gt;
alter table TableName drop column ColumnName;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump a single table ==&lt;br /&gt;
&lt;br /&gt;
mysqldump -pPASSWORD DatabaseName TableName &amp;gt; table.sql&lt;br /&gt;
&lt;br /&gt;
To dump in XML format, use --xml after mysqldump&lt;br /&gt;
&lt;br /&gt;
== Dump a database ==&lt;br /&gt;
&lt;br /&gt;
If you have a backup of the MySQL database in a .sql file, delete the database first within mysql:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database NameOfDatabaseToBeDeleted;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then dump the .sql file into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uroot -p &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump database/s &amp;amp; copy database/s from one Plesk server to another ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linux&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
On the old server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&lt;br /&gt;
scp &amp;lt;database&amp;gt;.sql root@VPS_IP:&lt;br /&gt;
yes&lt;br /&gt;
*Paste the password in*&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the new server; check the mysql databases to ensure it isn&#039;t already there, go into Plesk and create it with the same name and then after the command below create a database user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;lt; /root/&amp;lt;database&amp;gt;.sql #or just /&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- [http://www.snowfrog.net/2005/11/16/backup-multiple-databases-into-separate-files/ Backup multiple DBs into separate files] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://serverkb.co.uk/tools/dbdump.sh Backup script] ===&lt;br /&gt;
&lt;br /&gt;
Made by [[User:Trilium]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- #!/bin/bash &lt;br /&gt;
######################################################## &lt;br /&gt;
# Database backup script &lt;br /&gt;
######################################################## &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
CHROOTMYSQLPASS=**** &lt;br /&gt;
MYSQLBACKUPDIR=/root/database_backup &lt;br /&gt;
EXCLUDE=&amp;quot;mysql psa information_schema horde atmail admin&amp;quot; &lt;br /&gt;
&lt;br /&gt;
#Edit this. grep -v phpmyadmin and exclude it&lt;br /&gt;
 &lt;br /&gt;
if [ -d $MYSQLBACKUPDIR ] &lt;br /&gt;
then &lt;br /&gt;
echo &amp;quot;$MYSQLBACKUPDIR exists&amp;quot; &lt;br /&gt;
else &lt;br /&gt;
mkdir -p $MYSQLBACKUPDIR &lt;br /&gt;
fi &lt;br /&gt;
 &lt;br /&gt;
DBNAMES=&amp;quot;$(mysql -h server0 -u root -p$CHROOTMYSQLPASS -Bse &#039;show databases&#039;)&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $EXCLUDE &lt;br /&gt;
do &lt;br /&gt;
DBNAMES=`echo $DBNAMES | sed &amp;quot;s/\b$DATABASE\b//g&amp;quot;` &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $DBNAMES &lt;br /&gt;
do &lt;br /&gt;
echo &amp;quot;Backing up $DATABASE&amp;quot; &lt;br /&gt;
FILENAME=&amp;quot;$MYSQLBACKUPDIR/$DATABASE.sql&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
mysqldump --lock-tables=false -h server0 -u root -p$CHROOTMYSQLPASS $DATABASE &amp;gt; $FILENAME &lt;br /&gt;
 &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
tar -czvf database_backup.tar.gz $MYSQLBACKUPDIR/*.sql &lt;br /&gt;
 &lt;br /&gt;
echo Backup complete to database_backup.tar.gz  --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enable Slow Query Logging ==&lt;br /&gt;
&lt;br /&gt;
Only valid for Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
chmod +x slow.sh&lt;br /&gt;
./snow.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entering MySQL and selecting a database/table ==&lt;br /&gt;
&lt;br /&gt;
On a Plesk server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
show databases;&lt;br /&gt;
use database (e.g. psa)&lt;br /&gt;
show tables;&lt;br /&gt;
select * from domains; or \G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&lt;br /&gt;
mysql -uadmin -p&#039;$AES...==&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd %plesk_dir%\mysql\bin&lt;br /&gt;
mysql -uadmin -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below goes into the Plesk database MySQL area:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p -P8306&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may need to reset the admin password via Plesk. Get the PW by doing this in Run:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;%plesk_bin%\plesksrvclient&amp;quot; -get&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 4.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 5.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C:\Program Files (x86)\Parallels\Plesk\MySQL\Data\my is the my.cnf equivalent.&lt;br /&gt;
&lt;br /&gt;
== ERROR 1175 ==&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
You will need to do desc TableName; to see which Field uses a Key. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from zone_records;&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
| zone                       | type   | record | prefix       | ttl   | data                        |&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;domain.co.uk&amp;quot; where record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; desc zone_records;&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| Field  | Type                                            | Null | Key | Default  | Extra |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| zone   | varchar(255)                                    | NO   | MUL |          |       |&lt;br /&gt;
| type   | enum(&#039;username&#039;,&#039;domain&#039;,&#039;component&#039;,&#039;default&#039;) | NO   |     | username |       |&lt;br /&gt;
| record | enum(&#039;A&#039;,&#039;MX&#039;,&#039;CNAME&#039;,&#039;PTR&#039;,&#039;TXT&#039;)              | YES  |     | NULL     |       |&lt;br /&gt;
| prefix | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
| ttl    | int(10) unsigned                                | YES  |     | NULL     |       |&lt;br /&gt;
| data   | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;dev.domain.co.uk&amp;quot; where zone=&amp;quot;domain.co.uk&amp;quot; and record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Flat Files ==&lt;br /&gt;
&lt;br /&gt;
These are the .mdf and .ldf files.&lt;br /&gt;
&lt;br /&gt;
== Got a packet bigger than &#039;max_allowed_packet&#039; bytes ==&lt;br /&gt;
&lt;br /&gt;
In my.cnf add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;max_allowed_packet = 10M&lt;br /&gt;
#or 100M&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import sqlite to MySQL ==&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql Stack Overflow Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4140210/shell-file-to-import-sqlite-into-mysql Stack Overflow Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.google.co.uk/search?hl=en&amp;amp;safe=off&amp;amp;site=&amp;amp;source=hp&amp;amp;q=import+sqlite+to+mysql&amp;amp;oq=import+sqlite+&amp;amp;aq=5&amp;amp;aqi=g10&amp;amp;aql=&amp;amp;gs_nf=1&amp;amp;gs_l=hp.3.5.0l10.647.6084.0.8595.14.14.0.4.4.0.148.866.8j2.10.0.0kqDvPY0M4E Google search]&lt;br /&gt;
&lt;br /&gt;
[http://www.php.net/manual/en/mysqli.installation.php mysqli]&lt;br /&gt;
&lt;br /&gt;
== Plesk database location ==&lt;br /&gt;
&lt;br /&gt;
on Windows is C:\Program Files (x86)\Parallels\Plesk\Databases\MySQL\data normally.&lt;br /&gt;
&lt;br /&gt;
== [http://www.theadminzone.com/forums/showthread.php?p=564138 Optimizing MySQL database] ==&lt;br /&gt;
&lt;br /&gt;
Utilise functions such as Query Caching to serve results of previous repeated queries to reduce load.&lt;br /&gt;
&lt;br /&gt;
Some of the main cause of databases degradation usually relates to overly complex queries and large log tables, for information on how to improve this performance on Magento please see [http://www.quentinnel.com/2009/10/01/magento-and-log-cleaning this] and [http://www.magentocommerce.com/boards/viewthread/36225 this].&lt;br /&gt;
&lt;br /&gt;
== Manually create database and user (Unix) ==&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database NewDatabase;&lt;br /&gt;
show databases;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to dump a database.sql file onto the new database you have just created, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p NewDatabase &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the new user that will be assigned to the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;YourUsername&#039;@&#039;localhost&#039; identified by &#039;plaintextpassword&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then to assign a user to the database, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use NewDatabase&lt;br /&gt;
grant usage on NewDatabase.* to YourUsername@localhost identified by &#039;plaintextpassword&#039;;&lt;br /&gt;
grant all privileges on `NewDatabase`.* to &#039;YourUsername&#039;@&#039;localhost&#039;;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then test the connection works to the database with that username and password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -h localhost -u YourUser -DNewDatabase -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Monitor queries ==&lt;br /&gt;
&lt;br /&gt;
watch -n 1 mysqladmin --user=&amp;lt;user&amp;gt; --password=&amp;lt;password&amp;gt; processlist&lt;br /&gt;
&lt;br /&gt;
== MySQLdump ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -u username -p database_to_backup &amp;gt; backup_name.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump: Couldn&#039;t execute &#039;SHOW VARIABLES LIKE &#039;gtid\_mode&#039;&#039;: Table &#039;performance_schema.session_variables&#039; doesn&#039;t exist (1146)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql_upgrade -u root -p --force&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restart mysql:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service mysql restart&lt;br /&gt;
service mysqld restart&lt;br /&gt;
systemctl restart mysql&lt;br /&gt;
systemctl restart mysqld&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD server ===&lt;br /&gt;
&lt;br /&gt;
You may need to chroot into the appropriate environment. The mysqldump location will either be /mysql/bin/mysqldump or /usr/fs//mysql/bin/mysqldump&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p&amp;lt;password&amp;gt; &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://stackoverflow.com/questions/13996606/add-database-name-to-sql-file-when-exporting-using-mysqldump-via-linux Multiple exports to .sql files] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
dbs=&#039;firstdb seconddb thirddb&#039;&lt;br /&gt;
&lt;br /&gt;
echo -n &#039;Enter database password: &#039;&lt;br /&gt;
read pw&lt;br /&gt;
&lt;br /&gt;
for db in $dbs&lt;br /&gt;
do&lt;br /&gt;
    mysqldump -u user -h localhost -p$pw $db &amp;gt; $db_1_$(date +%d%m%y).sql&lt;br /&gt;
done&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plesk server === &lt;br /&gt;
&lt;br /&gt;
Unix: &amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
Windows: &amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL errors/issues ==&lt;br /&gt;
&lt;br /&gt;
=== Database already exists importing via PHP My Admin ===&lt;br /&gt;
&lt;br /&gt;
Go to Tools &amp;amp; Settings &amp;gt; Applications &amp;amp; Databases - Database Servers &amp;gt; Webadmin &amp;gt; Import the Database here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`&lt;br /&gt;
show databases;&lt;br /&gt;
quit&lt;br /&gt;
mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;gt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure there are no databases in Plesk under domain in Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases. Remove any if they exist. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;lt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go back into Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases &amp;gt; Database &amp;gt; Add a Database user &amp;gt; Access Webadmin/PHP My Admin&lt;br /&gt;
&lt;br /&gt;
=== Can&#039;t connect to local MySQL server through socket ===&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_connect() [function.mysql-connect]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 10&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_select_db() [function.mysql-select-db]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 11&lt;br /&gt;
&lt;br /&gt;
ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2)&lt;br /&gt;
&lt;br /&gt;
Restart MySQL (via chroot environment if needed).&lt;br /&gt;
&lt;br /&gt;
Check the error log and if need be increase the innodb buffer pool size from it&#039;s default 2M. Also ensure the file /var/run/mysqld/mysqld.sock has mysql:mysql and socket permissions (use mkfifo).&lt;br /&gt;
&lt;br /&gt;
http://forums.mysql.com/read.php?22,423592,423592#msg-423592&lt;br /&gt;
&lt;br /&gt;
=== Memory allocation error in Plesk ===&lt;br /&gt;
&lt;br /&gt;
[MySQL][ODBC 3.51 Driver][mysqld-5.0.95-0ubuntu1]Memory allocation error &lt;br /&gt;
File 	aps_php.php&amp;lt;br&amp;gt;&lt;br /&gt;
Line 	7476&amp;lt;br&amp;gt;&lt;br /&gt;
Type 	Exception&lt;br /&gt;
&lt;br /&gt;
[http://forum.parallels.com/pda/index.php/t-258020.html How to fix on Ubuntu 10.04] + http://kb.parallels.com/113620&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;pre&amp;gt;mkdir deb&lt;br /&gt;
cd deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev*&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
cd deb&lt;br /&gt;
ls&lt;br /&gt;
rm index.html; ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.95-0ubuntu1_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
ls&lt;br /&gt;
rm *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.51a-3ubuntu5_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15off_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQLSTATE[HY000]: General error: 1030 Got error 122 from storage engine ===&lt;br /&gt;
&lt;br /&gt;
Disk space is full normally. Run df -h to find out.&lt;br /&gt;
&lt;br /&gt;
=== Big BLOB or TEXT rows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;InnoDB: ERROR: the age of the last checkpoint is 9433569,&lt;br /&gt;
InnoDB: largest such row.&lt;br /&gt;
InnoDB: combined size of log files at least 10 times bigger than the&lt;br /&gt;
InnoDB: If you are using big BLOB or TEXT rows, you must set the&lt;br /&gt;
InnoDB: which exceeds the log group capacity 9433498.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error message can mean that you&#039;re trying to insert too much data into InnoDB too quickly, and the InnoDB log is filling up before the data can be flushed into the main data files.&lt;br /&gt;
&lt;br /&gt;
To solve it, you need to stop MySQL cleanly (very important), delete the existing InnoDB log files (probably lb_logfile* in your MySQL data directory, unless you&#039;ve moved them), then adjust theinnodb_log_file_size to suit your needs, and then start MySQL again.&lt;br /&gt;
&lt;br /&gt;
Also see the &amp;lt;pre&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;/pre&amp;gt; box in [[Plesk_Fatal_Exception#Can.27t_connect_to_MySQL_Database | this link]].&lt;br /&gt;
&lt;br /&gt;
== PHP Connector guides ==&lt;br /&gt;
&lt;br /&gt;
http://www.phpfreaks.com/forums/index.php?topic=232018.0&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.dreamincode.net/forums/topic/80945-php-mysql-connector&amp;lt;br&amp;gt;&lt;br /&gt;
http://tycoontalk.freelancer.com/php-forum/19135-php-mysql-connection-problems.html&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would advise reading the following guide in regards to the Windows sections: http://www.ora600.be/node/3511&lt;br /&gt;
&lt;br /&gt;
This refers to the error &amp;quot;Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP&amp;quot; and can happen due to the PHP installation not having the MySQL compiled within it.&lt;br /&gt;
&lt;br /&gt;
== PHP My Admin ==&lt;br /&gt;
&lt;br /&gt;
=== 1077 Error ===&lt;br /&gt;
&lt;br /&gt;
When you upload a file into phpMyAdmin and it shows a 1077 error, you are likely uploading the wrong file type. It needs to be as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;File may be compressed (gzip, zip) or uncompressed.&lt;br /&gt;
A compressed file&#039;s name must end in .[format].[compression]. Example: .sql.zip&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you right click the .sql file and zip it and then try it should work as long as it is below 2GB.&lt;br /&gt;
&lt;br /&gt;
=== Export issue ===&lt;br /&gt;
&lt;br /&gt;
The error normally shown is &amp;quot;can’t find the file at https://xx.xx.xx.xx:8443/domains/databases/phpMyAdmin/export.php&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /usr/local/psa/admin/conf/php.ini&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing&#039;&#039;&#039; memory_limit&#039;&#039;&#039;. Increase this to &#039;&#039;&#039;512M&#039;&#039;&#039; or &#039;&#039;&#039;1024M&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/sw-cp-server restart&lt;br /&gt;
/etc/init.d/psa stopall&lt;br /&gt;
/etc/init.d/psa startall&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Repair database/s ==&lt;br /&gt;
&lt;br /&gt;
To repair one database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair DatabaseName -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or to repair all databases:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair --all-databases -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reset root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
Quick way if you already know the password, outside of MySQL do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqladmin -u root -p&#039;OldPassword&#039; password NewPassword&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET PASSWORD FOR &#039;root&#039;@&#039;localhost&#039;=PASSWORD(&#039;MyNewPass&#039;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t know the current password:&lt;br /&gt;
&lt;br /&gt;
=== [http://kwatog.com/blog/reset-mysql-root-password-in-centos CentOS] ===&lt;br /&gt;
&lt;br /&gt;
The same steps basically.&lt;br /&gt;
&lt;br /&gt;
=== Debian ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
/usr/bin/mysqld_safe --skip-grant-tables &amp;amp;&lt;br /&gt;
[1] 32305&lt;br /&gt;
130401 22:43:57 mysqld_safe Logging to syslog.&lt;br /&gt;
130401 22:43:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whilst this is at a blank line, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --user=root mysql&lt;br /&gt;
update user set Password=PASSWORD(&#039;new-password-here&#039;) WHERE User=&#039;root&#039;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then stop and start the server:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql restart&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysqld stop&lt;br /&gt;
mysqld_safe –skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or &lt;br /&gt;
&lt;br /&gt;
mysqld_safe -–skip-grant-tables &amp;amp; (two hyphens)&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use mysql;&lt;br /&gt;
update user set password=PASSWORD(“yourpassword”) where User=’root’;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;update user set password=PASSWORD(“yourpassword”) where User=’admin’&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should now be able to log in as root/admin using the “yourpassword” that you entered.&lt;br /&gt;
&lt;br /&gt;
[http://www.achawkins.com/tech/regain-lost-root-mysql-access-permissions-when-connecting-from-localhost Regain lost root MySQL access permissions connecting from localhost]&lt;br /&gt;
&lt;br /&gt;
Alternatively do this (on a Plesk server only):&lt;br /&gt;
&lt;br /&gt;
Get the password via the command below, and keep for later*. If it is Plesk 11 you need to copy from the &#039;&#039;&#039;$ up to but not including&#039;&#039;&#039; the word &#039;&#039;&#039;root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter this into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;skip-grant-tables&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file. Then restart MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&lt;br /&gt;
mysql&lt;br /&gt;
use mysql&lt;br /&gt;
update user set password=PASSWORD (&amp;quot;*&amp;quot;) where user=&amp;quot;admin&amp;quot;;&lt;br /&gt;
flush privileges&lt;br /&gt;
exit&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove skip-grant-tables from /etc/mysql/my.cnf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run a command externally/outside of MySQL ==&lt;br /&gt;
&lt;br /&gt;
mysql -p`cat PasswordFile` -D DatabaseName -e &amp;quot;select * from dbname;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Set root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
You obviously must know it already:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
update user set password=PASSWORD(&amp;quot;yourpassword&amp;quot;) where User=&amp;quot;root&amp;quot;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then attempt to access MySQL:&lt;br /&gt;
&lt;br /&gt;
mysql -p&amp;lt;br&amp;gt;&lt;br /&gt;
yourpassword&lt;br /&gt;
&lt;br /&gt;
== Show users permissions ==&lt;br /&gt;
&lt;br /&gt;
show grants;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
SHOW GRANTS FOR &#039;root&#039;@&#039;localhost&#039;;&lt;br /&gt;
&lt;br /&gt;
=== All users ===&lt;br /&gt;
&lt;br /&gt;
SELECT User FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT * FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT CONCAT(&#039;SHOW GRANTS FOR &#039;&#039;&#039;,user,&#039;&#039;&#039;@&#039;&#039;&#039;,host,&#039;&#039;&#039;;&#039;) FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
http://dbadiaries.com/no-mysql-show-users-how-to-list-mysql-user-accounts-and-their-privileges&lt;br /&gt;
&lt;br /&gt;
== Show over 1000 rows ==&lt;br /&gt;
&lt;br /&gt;
use database&lt;br /&gt;
select * from table where type=&amp;quot;HeaderValue&amp;quot; LIMIT 0,99999;&lt;br /&gt;
&lt;br /&gt;
== Show tables column headers ==&lt;br /&gt;
&lt;br /&gt;
show columns from table;&lt;br /&gt;
&lt;br /&gt;
== Uninstall MySQL completely (Unix) ==&lt;br /&gt;
&lt;br /&gt;
If for example you have installed mysql-server, then uninstalled, then installed it again but it is not prompting you for the root password like before, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get purge mysql-server mysql-common mysql-client&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Unknown table engine &#039;InnoDB&#039; ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;MySQL query failed: Unknown table engine &#039;InnoDB&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Look inside the /etc/mysql/my.cnf file and ensure you don&#039;t have skip-innodb in there. If so, comment out and restart MySQL.&lt;br /&gt;
&lt;br /&gt;
== [http://www.mosbase.com/2010/05/install-latest-version-of-mysql-on.html Upgrade on Ubuntu 8.04] ==&lt;br /&gt;
&lt;br /&gt;
== [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 Upgrade on Ubuntu 10.04] ==&lt;br /&gt;
&lt;br /&gt;
Alternate guides: [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 1], [http://www.php-trivandrum.org/general-articles/how-i-got-mysql-55-running-on-ubuntu-10-server 2], [http://akbarahmed.com/2012/04/08/install-mysql-5-5-on-ubuntu-10-04-lts-running-in-the-rackspace-cloud-2 3]&lt;br /&gt;
&lt;br /&gt;
=== MySQL 5.5. error ===&lt;br /&gt;
&lt;br /&gt;
If you get the below error when stopping MySQL after upgrading MySQL from 5.1 to 5.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
* MySQL server PID file could not be found!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | grep mysql&lt;br /&gt;
#this will then show the below output&lt;br /&gt;
mysql    11683  0.0  3.5 410276 71276 ?        Sl   06:48   0:00 mysqld --skip-grant-tables --user=mysql&lt;br /&gt;
&lt;br /&gt;
#kill the process id&lt;br /&gt;
kill 11683&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
/etc/init.d/mysql stop&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
&lt;br /&gt;
ps aux | grep mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
root      5291  0.1  0.0   4088   668 pts/1    S    09:51   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/serverhostname.pid&amp;lt;br&amp;gt;&lt;br /&gt;
mysql     5615  1.1  4.2 621124 84776 pts/1    Sl   09:51   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log&amp;lt;br&amp;gt;&lt;br /&gt;
--pid-file=/usr/local/mysql/data/serverhostname.pid --socket=/var/run/mysqld/mysqld.sock --port=3306&amp;lt;br&amp;gt;&lt;br /&gt;
root      5670  0.0  0.0   6156   696 pts/1    S+   09:51   0:00 grep mysql&lt;br /&gt;
&lt;br /&gt;
== Version 5.5 on CentOS 6 with Plesk ==&lt;br /&gt;
&lt;br /&gt;
This is really only possible on CentOS 5, as of 08/03/2013&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm&lt;br /&gt;
rpm -Uvh remi-release-6*.rpm&lt;br /&gt;
vim /etc/yum.repos.d/remi.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the top &amp;lt;nowiki&amp;gt;[remi]&amp;lt;/nowiki&amp;gt; to enabled=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;yum list mysql-server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://dba.stackexchange.com/questions/16316/why-can-i-only-install-mysql-5-1-on-cent-os-6-2 A script to get the latest MySQL 5.5 for RHEL6]&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use the Atomic repo, however you &#039;&#039;&#039;must&#039;&#039;&#039; disable it afterwards, otherwise it may remove Plesk when it auto-updates.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1114</id>
		<title>MySQL</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=MySQL&amp;diff=1114"/>
		<updated>2019-05-17T08:55:07Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* MySQLdump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note: MySQL on Fedora and CentOS can be called mysqld&lt;br /&gt;
&lt;br /&gt;
== Backup a database ==&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/MySQL#MySQLdump&lt;br /&gt;
&lt;br /&gt;
== Before making changes... ==&lt;br /&gt;
&lt;br /&gt;
Use the commands BEGIN, COMMIT and ROLLBACK&lt;br /&gt;
&lt;br /&gt;
If your format is InnoDB, the majority of MySQL data is stored in the ibdata file.&lt;br /&gt;
&lt;br /&gt;
== Change character encoding  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use mysql &lt;br /&gt;
#or the database you want so for example; use moodle&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 | character_set_database | latin1 |&lt;br /&gt;
 +------------------------+--------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alter database DatabaseName character set UTF8;&lt;br /&gt;
Query OK, 1 row affected (0.00 sec)&lt;br /&gt;
show variables like &amp;quot;character_set_database&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | Variable_name          | Value |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 | character_set_database | utf8 |&lt;br /&gt;
 +------------------------+-------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Exit MySQL and restart to be safe.&lt;br /&gt;
&lt;br /&gt;
=== Check database size ===&lt;br /&gt;
&lt;br /&gt;
http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://rackerhacker.com/2007/04/27/plesk-sql-statements Check email passwords] ==&lt;br /&gt;
&lt;br /&gt;
== Check MySQL users ==&lt;br /&gt;
&lt;br /&gt;
Short versions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select User from mysql.user;&lt;br /&gt;
select User,Host from mysql.user;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Long version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from mysql.user\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pantz.org/software/mysql/mysqlcommands.html Common Commands] ==&lt;br /&gt;
&lt;br /&gt;
Log into MySQL, use database and then check MySQL process list which display the database being accessed, the command and the time in minutes it has been running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show processlist;&lt;br /&gt;
show full processlist;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check all database/tables for corruption using one of these commands outside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For DH server use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -A -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
mysqlcheck: Got error: 1045: Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO) when trying to connect . Use this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uadmin -p`cat /etc/psa/.psa.shadow` -A&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Skip grant tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
mysqld_safe --skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Table names in MySQL are case sensitive.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;locate my.cnf&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For importing large database files, I would recommend using a software like HeidiSQL to import your Databases, as PhpMyAdmin is often problematic when attempting to upload databases of a larger size.  &lt;br /&gt;
&lt;br /&gt;
http://www.heidisql.com/&lt;br /&gt;
&lt;br /&gt;
The below command will &#039;&#039;&#039;show you how a database table was created&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
show create table tables_name\G&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Show all where the start of the entry begins with a&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from table where name like &#039;a%&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.w3schools.com/sql/sql_distinct.asp This] is used to return only different values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT DISTINCT column/row from table;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [http://www.w3schools.com/sql/sql_orderby.asp ORDER BY] keyword is used to &#039;&#039;&#039;sort the result-set&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SELECT column_name&lt;br /&gt;
FROM table_name&lt;br /&gt;
ORDER BY column_name ASC|DESC&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
e.g. select * from domains ORDER BY &amp;quot;name&amp;quot; DESC;&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;return the number of records in a table&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
select count(*) from table;&lt;br /&gt;
&lt;br /&gt;
=== [http://support.modwest.com/content/6/60/en/how-do-i-connect-to-my-mysql-database.html#monitor Connect to MySQL database] ===&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -d database -p&amp;lt;br&amp;gt; &lt;br /&gt;
mysql -h 127.0.0.1 -u username -d database -p&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or&lt;br /&gt;
&lt;br /&gt;
mysql -h localhost -u username -Ddatabase -p&lt;br /&gt;
&lt;br /&gt;
== Connect to MySQL remotely ==&lt;br /&gt;
&lt;br /&gt;
To allow external access to MySQL &#039;&#039;&#039;comment out&#039;&#039;&#039; the following line in my.cnf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;bind-address           = 127.0.0.1&lt;br /&gt;
#bind-address           = 127.0.0.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then restart MySQL.&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html Enable remote connection]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely Connect remotely]&lt;br /&gt;
&lt;br /&gt;
To connect from a Linux box to another you can try:&lt;br /&gt;
&lt;br /&gt;
mysql -h IPaddress -uusername -p -D database&lt;br /&gt;
&lt;br /&gt;
== Convert all MySQL tables and fields to UTF8 ==&lt;br /&gt;
&lt;br /&gt;
mysql --database=dbname -B -N -e &amp;quot;SHOW TABLES&amp;quot;  | awk &#039;{print &amp;quot;ALTER TABLE&amp;quot;, $1, &amp;quot;CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;&amp;quot;}&#039; | mysql --database=dbname &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This loops through all tables and changes their collations to UTF8. You should backup beforehand though in case some data is lost in the process. Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
UTF-8 UTF utf-8 utf&lt;br /&gt;
&lt;br /&gt;
== Create table with text ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName ( ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create table TableName (&lt;br /&gt;
ColumnName TEXT );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Deleting large amount of data ==&lt;br /&gt;
&lt;br /&gt;
You may get:&lt;br /&gt;
&lt;br /&gt;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction&lt;br /&gt;
&lt;br /&gt;
You can see more details of the event by issuing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SHOW ENGINE INNODB STATUS\G&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show variables like &#039;innodb_lock_wait_timeout&#039;;&lt;br /&gt;
set innodb_lock_wait_timeout=100&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also set it to a higher value in /etc/my.cnf permanently with this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[mysqld]&lt;br /&gt;
innodb_lock_wait_timeout=120&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and then restart mysql. If you cannot restart mysql at this time, run this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET GLOBAL innodb_lock_wait_timeout = 120;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of locked tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;show open tables where in_use&amp;gt;0;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check the list of the current processes, one of them might be locking your table(s):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; show processlist;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then kill one of these processes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;kill put_process_id_here;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delete user ==&lt;br /&gt;
&lt;br /&gt;
drop user@localhost;&lt;br /&gt;
&lt;br /&gt;
== [http://www.microsoft.com/en-us/download/details.aspx?id=7593 Download SQL Server Management Studio] ==&lt;br /&gt;
&lt;br /&gt;
== Drop database, table or row/column ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database DatabaseName;&lt;br /&gt;
drop table TableName;&lt;br /&gt;
&lt;br /&gt;
#Delete a row(s) from a table&lt;br /&gt;
DELETE from TableName where FieldName] = &#039;value&#039;;&lt;br /&gt;
&lt;br /&gt;
#Delete a column&lt;br /&gt;
alter table TableName drop column ColumnName;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump a single table ==&lt;br /&gt;
&lt;br /&gt;
mysqldump -pPASSWORD DatabaseName TableName &amp;gt; table.sql&lt;br /&gt;
&lt;br /&gt;
To dump in XML format, use --xml after mysqldump&lt;br /&gt;
&lt;br /&gt;
== Dump a database ==&lt;br /&gt;
&lt;br /&gt;
If you have a backup of the MySQL database in a .sql file, delete the database first within mysql:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;drop database NameOfDatabaseToBeDeleted;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then dump the .sql file into MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uroot -p &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dump database/s &amp;amp; copy database/s from one Plesk server to another ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linux&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
On the old server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&lt;br /&gt;
scp &amp;lt;database&amp;gt;.sql root@VPS_IP:&lt;br /&gt;
yes&lt;br /&gt;
*Paste the password in*&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the new server; check the mysql databases to ensure it isn&#039;t already there, go into Plesk and create it with the same name and then after the command below create a database user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;lt; /root/&amp;lt;database&amp;gt;.sql #or just /&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- [http://www.snowfrog.net/2005/11/16/backup-multiple-databases-into-separate-files/ Backup multiple DBs into separate files] --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://serverkb.co.uk/tools/dbdump.sh Backup script] ===&lt;br /&gt;
&lt;br /&gt;
Made by [[User:Trilium]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- #!/bin/bash &lt;br /&gt;
######################################################## &lt;br /&gt;
# Database backup script &lt;br /&gt;
######################################################## &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
CHROOTMYSQLPASS=**** &lt;br /&gt;
MYSQLBACKUPDIR=/root/database_backup &lt;br /&gt;
EXCLUDE=&amp;quot;mysql psa information_schema horde atmail admin&amp;quot; &lt;br /&gt;
&lt;br /&gt;
#Edit this. grep -v phpmyadmin and exclude it&lt;br /&gt;
 &lt;br /&gt;
if [ -d $MYSQLBACKUPDIR ] &lt;br /&gt;
then &lt;br /&gt;
echo &amp;quot;$MYSQLBACKUPDIR exists&amp;quot; &lt;br /&gt;
else &lt;br /&gt;
mkdir -p $MYSQLBACKUPDIR &lt;br /&gt;
fi &lt;br /&gt;
 &lt;br /&gt;
DBNAMES=&amp;quot;$(mysql -h server0 -u root -p$CHROOTMYSQLPASS -Bse &#039;show databases&#039;)&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $EXCLUDE &lt;br /&gt;
do &lt;br /&gt;
DBNAMES=`echo $DBNAMES | sed &amp;quot;s/\b$DATABASE\b//g&amp;quot;` &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
for DATABASE in $DBNAMES &lt;br /&gt;
do &lt;br /&gt;
echo &amp;quot;Backing up $DATABASE&amp;quot; &lt;br /&gt;
FILENAME=&amp;quot;$MYSQLBACKUPDIR/$DATABASE.sql&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
mysqldump --lock-tables=false -h server0 -u root -p$CHROOTMYSQLPASS $DATABASE &amp;gt; $FILENAME &lt;br /&gt;
 &lt;br /&gt;
done &lt;br /&gt;
 &lt;br /&gt;
tar -czvf database_backup.tar.gz $MYSQLBACKUPDIR/*.sql &lt;br /&gt;
 &lt;br /&gt;
echo Backup complete to database_backup.tar.gz  --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enable Slow Query Logging ==&lt;br /&gt;
&lt;br /&gt;
Only valid for Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
chmod +x slow.sh&lt;br /&gt;
./snow.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entering MySQL and selecting a database/table ==&lt;br /&gt;
&lt;br /&gt;
On a Plesk server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
show databases;&lt;br /&gt;
use database (e.g. psa)&lt;br /&gt;
show tables;&lt;br /&gt;
select * from domains; or \G&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&lt;br /&gt;
mysql -uadmin -p&#039;$AES...==&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd %plesk_dir%\mysql\bin&lt;br /&gt;
mysql -uadmin -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below goes into the Plesk database MySQL area:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p -P8306&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may need to reset the admin password via Plesk. Get the PW by doing this in Run:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;%plesk_bin%\plesksrvclient&amp;quot; -get&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 4.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd C:\Program Files\MySQL\MySQL Server 5.1\bin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C:\Program Files (x86)\Parallels\Plesk\MySQL\Data\my is the my.cnf equivalent.&lt;br /&gt;
&lt;br /&gt;
== ERROR 1175 ==&lt;br /&gt;
&lt;br /&gt;
If you get the below error:&lt;br /&gt;
&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
You will need to do desc TableName; to see which Field uses a Key. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;select * from zone_records;&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
| zone                       | type   | record | prefix       | ttl   | data                        |&lt;br /&gt;
+----------------------------+--------+--------+--------------+-------+-----------------------------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;domain.co.uk&amp;quot; where record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&lt;br /&gt;
ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; desc zone_records;&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| Field  | Type                                            | Null | Key | Default  | Extra |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
| zone   | varchar(255)                                    | NO   | MUL |          |       |&lt;br /&gt;
| type   | enum(&#039;username&#039;,&#039;domain&#039;,&#039;component&#039;,&#039;default&#039;) | NO   |     | username |       |&lt;br /&gt;
| record | enum(&#039;A&#039;,&#039;MX&#039;,&#039;CNAME&#039;,&#039;PTR&#039;,&#039;TXT&#039;)              | YES  |     | NULL     |       |&lt;br /&gt;
| prefix | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
| ttl    | int(10) unsigned                                | YES  |     | NULL     |       |&lt;br /&gt;
| data   | varchar(255)                                    | NO   |     |          |       |&lt;br /&gt;
+--------+-------------------------------------------------+------+-----+----------+-------+&lt;br /&gt;
&lt;br /&gt;
update zone_records set zone=&amp;quot;dev.domain.co.uk&amp;quot; where zone=&amp;quot;domain.co.uk&amp;quot; and record=&amp;quot;TXT&amp;quot; and prefix=&amp;quot;mail&amp;quot;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Flat Files ==&lt;br /&gt;
&lt;br /&gt;
These are the .mdf and .ldf files.&lt;br /&gt;
&lt;br /&gt;
== Got a packet bigger than &#039;max_allowed_packet&#039; bytes ==&lt;br /&gt;
&lt;br /&gt;
In my.cnf add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;max_allowed_packet = 10M&lt;br /&gt;
#or 100M&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import sqlite to MySQL ==&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql Stack Overflow Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://stackoverflow.com/questions/4140210/shell-file-to-import-sqlite-into-mysql Stack Overflow Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.google.co.uk/search?hl=en&amp;amp;safe=off&amp;amp;site=&amp;amp;source=hp&amp;amp;q=import+sqlite+to+mysql&amp;amp;oq=import+sqlite+&amp;amp;aq=5&amp;amp;aqi=g10&amp;amp;aql=&amp;amp;gs_nf=1&amp;amp;gs_l=hp.3.5.0l10.647.6084.0.8595.14.14.0.4.4.0.148.866.8j2.10.0.0kqDvPY0M4E Google search]&lt;br /&gt;
&lt;br /&gt;
[http://www.php.net/manual/en/mysqli.installation.php mysqli]&lt;br /&gt;
&lt;br /&gt;
== Plesk database location ==&lt;br /&gt;
&lt;br /&gt;
on Windows is C:\Program Files (x86)\Parallels\Plesk\Databases\MySQL\data normally.&lt;br /&gt;
&lt;br /&gt;
== [http://www.theadminzone.com/forums/showthread.php?p=564138 Optimizing MySQL database] ==&lt;br /&gt;
&lt;br /&gt;
Utilise functions such as Query Caching to serve results of previous repeated queries to reduce load.&lt;br /&gt;
&lt;br /&gt;
Some of the main cause of databases degradation usually relates to overly complex queries and large log tables, for information on how to improve this performance on Magento please see [http://www.quentinnel.com/2009/10/01/magento-and-log-cleaning this] and [http://www.magentocommerce.com/boards/viewthread/36225 this].&lt;br /&gt;
&lt;br /&gt;
== Manually create database and user (Unix) ==&lt;br /&gt;
&lt;br /&gt;
Create the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
create database NewDatabase;&lt;br /&gt;
show databases;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to dump a database.sql file onto the new database you have just created, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p NewDatabase &amp;lt; database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the new user that will be assigned to the database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;create user &#039;YourUsername&#039;@&#039;localhost&#039; identified by &#039;plaintextpassword&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then to assign a user to the database, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use NewDatabase&lt;br /&gt;
grant usage on NewDatabase.* to YourUsername@localhost identified by &#039;plaintextpassword&#039;;&lt;br /&gt;
grant all privileges on `NewDatabase`.* to &#039;YourUsername&#039;@&#039;localhost&#039;;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then test the connection works to the database with that username and password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -h localhost -u YourUser -DNewDatabase -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Monitor queries ==&lt;br /&gt;
&lt;br /&gt;
watch -n 1 mysqladmin --user=&amp;lt;user&amp;gt; --password=&amp;lt;password&amp;gt; processlist&lt;br /&gt;
&lt;br /&gt;
== MySQLdump ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -u username -p database_to_backup &amp;gt; backup_name.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump: Couldn&#039;t execute &#039;SHOW VARIABLES LIKE &#039;gtid\_mode&#039;&#039;: Table &#039;performance_schema.session_variables&#039; doesn&#039;t exist (1146)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql_upgrade -u root -p --force&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD server ===&lt;br /&gt;
&lt;br /&gt;
You may need to chroot into the appropriate environment. The mysqldump location will either be /mysql/bin/mysqldump or /usr/fs//mysql/bin/mysqldump&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -p&amp;lt;password&amp;gt; &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://stackoverflow.com/questions/13996606/add-database-name-to-sql-file-when-exporting-using-mysqldump-via-linux Multiple exports to .sql files] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
dbs=&#039;firstdb seconddb thirddb&#039;&lt;br /&gt;
&lt;br /&gt;
echo -n &#039;Enter database password: &#039;&lt;br /&gt;
read pw&lt;br /&gt;
&lt;br /&gt;
for db in $dbs&lt;br /&gt;
do&lt;br /&gt;
    mysqldump -u user -h localhost -p$pw $db &amp;gt; $db_1_$(date +%d%m%y).sql&lt;br /&gt;
done&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plesk server === &lt;br /&gt;
&lt;br /&gt;
Unix: &amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat etc/psa/.psa.shadow` &amp;lt;database&amp;gt; &amp;gt; &amp;lt;database&amp;gt;.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
Windows: &amp;lt;pre&amp;gt;mysqldump.exe -uroot -pPASSWORD DATABASE &amp;gt; outputdirectory\DATABASE.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL errors/issues ==&lt;br /&gt;
&lt;br /&gt;
=== Database already exists importing via PHP My Admin ===&lt;br /&gt;
&lt;br /&gt;
Go to Tools &amp;amp; Settings &amp;gt; Applications &amp;amp; Databases - Database Servers &amp;gt; Webadmin &amp;gt; Import the Database here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`&lt;br /&gt;
show databases;&lt;br /&gt;
quit&lt;br /&gt;
mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;gt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure there are no databases in Plesk under domain in Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases. Remove any if they exist. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` DatabaseName &amp;lt; /filepath/DatabaseName.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go back into Hosting Services - Domains &amp;gt; Control Panel &amp;gt; Websites and Domains &amp;gt; Databases &amp;gt; Database &amp;gt; Add a Database user &amp;gt; Access Webadmin/PHP My Admin&lt;br /&gt;
&lt;br /&gt;
=== Can&#039;t connect to local MySQL server through socket ===&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_connect() [function.mysql-connect]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 10&lt;br /&gt;
&lt;br /&gt;
Warning: mysql_select_db() [function.mysql-select-db]: Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2) in /home/DomainWithoutSuffix/public_html/includes/includes.php on line 11&lt;br /&gt;
&lt;br /&gt;
ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;/var/run/mysqld/mysqld.sock&#039; (2)&lt;br /&gt;
&lt;br /&gt;
Restart MySQL (via chroot environment if needed).&lt;br /&gt;
&lt;br /&gt;
Check the error log and if need be increase the innodb buffer pool size from it&#039;s default 2M. Also ensure the file /var/run/mysqld/mysqld.sock has mysql:mysql and socket permissions (use mkfifo).&lt;br /&gt;
&lt;br /&gt;
http://forums.mysql.com/read.php?22,423592,423592#msg-423592&lt;br /&gt;
&lt;br /&gt;
=== Memory allocation error in Plesk ===&lt;br /&gt;
&lt;br /&gt;
[MySQL][ODBC 3.51 Driver][mysqld-5.0.95-0ubuntu1]Memory allocation error &lt;br /&gt;
File 	aps_php.php&amp;lt;br&amp;gt;&lt;br /&gt;
Line 	7476&amp;lt;br&amp;gt;&lt;br /&gt;
Type 	Exception&lt;br /&gt;
&lt;br /&gt;
[http://forum.parallels.com/pda/index.php/t-258020.html How to fix on Ubuntu 10.04] + http://kb.parallels.com/113620&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&amp;lt;pre&amp;gt;mkdir deb&lt;br /&gt;
cd deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev*&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-)ubuntu1_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
cd deb&lt;br /&gt;
ls&lt;br /&gt;
rm index.html; ls&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.95-0ubuntu1_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.95-0ubuntu1_amd64.deb&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
ls&lt;br /&gt;
rm *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15-dev_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-client-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-common_5.0.51a-3ubuntu5_all.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&lt;br /&gt;
wget http://nl.archive.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/libmysqlclient15off_5.0.51a-3ubuntu5_amd64.deb&lt;br /&gt;
ls&lt;br /&gt;
dpkg -i *.deb&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQLSTATE[HY000]: General error: 1030 Got error 122 from storage engine ===&lt;br /&gt;
&lt;br /&gt;
Disk space is full normally. Run df -h to find out.&lt;br /&gt;
&lt;br /&gt;
=== Big BLOB or TEXT rows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;InnoDB: ERROR: the age of the last checkpoint is 9433569,&lt;br /&gt;
InnoDB: largest such row.&lt;br /&gt;
InnoDB: combined size of log files at least 10 times bigger than the&lt;br /&gt;
InnoDB: If you are using big BLOB or TEXT rows, you must set the&lt;br /&gt;
InnoDB: which exceeds the log group capacity 9433498.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error message can mean that you&#039;re trying to insert too much data into InnoDB too quickly, and the InnoDB log is filling up before the data can be flushed into the main data files.&lt;br /&gt;
&lt;br /&gt;
To solve it, you need to stop MySQL cleanly (very important), delete the existing InnoDB log files (probably lb_logfile* in your MySQL data directory, unless you&#039;ve moved them), then adjust theinnodb_log_file_size to suit your needs, and then start MySQL again.&lt;br /&gt;
&lt;br /&gt;
Also see the &amp;lt;pre&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;/pre&amp;gt; box in [[Plesk_Fatal_Exception#Can.27t_connect_to_MySQL_Database | this link]].&lt;br /&gt;
&lt;br /&gt;
== PHP Connector guides ==&lt;br /&gt;
&lt;br /&gt;
http://www.phpfreaks.com/forums/index.php?topic=232018.0&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.dreamincode.net/forums/topic/80945-php-mysql-connector&amp;lt;br&amp;gt;&lt;br /&gt;
http://tycoontalk.freelancer.com/php-forum/19135-php-mysql-connection-problems.html&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I would advise reading the following guide in regards to the Windows sections: http://www.ora600.be/node/3511&lt;br /&gt;
&lt;br /&gt;
This refers to the error &amp;quot;Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP&amp;quot; and can happen due to the PHP installation not having the MySQL compiled within it.&lt;br /&gt;
&lt;br /&gt;
== PHP My Admin ==&lt;br /&gt;
&lt;br /&gt;
=== 1077 Error ===&lt;br /&gt;
&lt;br /&gt;
When you upload a file into phpMyAdmin and it shows a 1077 error, you are likely uploading the wrong file type. It needs to be as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;File may be compressed (gzip, zip) or uncompressed.&lt;br /&gt;
A compressed file&#039;s name must end in .[format].[compression]. Example: .sql.zip&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you right click the .sql file and zip it and then try it should work as long as it is below 2GB.&lt;br /&gt;
&lt;br /&gt;
=== Export issue ===&lt;br /&gt;
&lt;br /&gt;
The error normally shown is &amp;quot;can’t find the file at https://xx.xx.xx.xx:8443/domains/databases/phpMyAdmin/export.php&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /usr/local/psa/admin/conf/php.ini&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing&#039;&#039;&#039; memory_limit&#039;&#039;&#039;. Increase this to &#039;&#039;&#039;512M&#039;&#039;&#039; or &#039;&#039;&#039;1024M&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/sw-cp-server restart&lt;br /&gt;
/etc/init.d/psa stopall&lt;br /&gt;
/etc/init.d/psa startall&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Repair database/s ==&lt;br /&gt;
&lt;br /&gt;
To repair one database:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair DatabaseName -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or to repair all databases:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqlcheck -uUser --repair --all-databases -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reset root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
Quick way if you already know the password, outside of MySQL do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysqladmin -u root -p&#039;OldPassword&#039; password NewPassword&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;SET PASSWORD FOR &#039;root&#039;@&#039;localhost&#039;=PASSWORD(&#039;MyNewPass&#039;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t know the current password:&lt;br /&gt;
&lt;br /&gt;
=== [http://kwatog.com/blog/reset-mysql-root-password-in-centos CentOS] ===&lt;br /&gt;
&lt;br /&gt;
The same steps basically.&lt;br /&gt;
&lt;br /&gt;
=== Debian ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
/usr/bin/mysqld_safe --skip-grant-tables &amp;amp;&lt;br /&gt;
[1] 32305&lt;br /&gt;
130401 22:43:57 mysqld_safe Logging to syslog.&lt;br /&gt;
130401 22:43:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whilst this is at a blank line, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql --user=root mysql&lt;br /&gt;
update user set Password=PASSWORD(&#039;new-password-here&#039;) WHERE User=&#039;root&#039;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then stop and start the server:&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql restart&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysqld stop&lt;br /&gt;
mysqld_safe –skip-grant-tables &amp;amp;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or &lt;br /&gt;
&lt;br /&gt;
mysqld_safe -–skip-grant-tables &amp;amp; (two hyphens)&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -u admin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;use mysql;&lt;br /&gt;
update user set password=PASSWORD(“yourpassword”) where User=’root’;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;update user set password=PASSWORD(“yourpassword”) where User=’admin’&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should now be able to log in as root/admin using the “yourpassword” that you entered.&lt;br /&gt;
&lt;br /&gt;
[http://www.achawkins.com/tech/regain-lost-root-mysql-access-permissions-when-connecting-from-localhost Regain lost root MySQL access permissions connecting from localhost]&lt;br /&gt;
&lt;br /&gt;
Alternatively do this (on a Plesk server only):&lt;br /&gt;
&lt;br /&gt;
Get the password via the command below, and keep for later*. If it is Plesk 11 you need to copy from the &#039;&#039;&#039;$ up to but not including&#039;&#039;&#039; the word &#039;&#039;&#039;root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat /etc/psa/.psa.shadow&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enter this into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;skip-grant-tables&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit the file. Then restart MySQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&lt;br /&gt;
mysql&lt;br /&gt;
use mysql&lt;br /&gt;
update user set password=PASSWORD (&amp;quot;*&amp;quot;) where user=&amp;quot;admin&amp;quot;;&lt;br /&gt;
flush privileges&lt;br /&gt;
exit&lt;br /&gt;
vim /etc/mysql/my.cnf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove skip-grant-tables from /etc/mysql/my.cnf&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run a command externally/outside of MySQL ==&lt;br /&gt;
&lt;br /&gt;
mysql -p`cat PasswordFile` -D DatabaseName -e &amp;quot;select * from dbname;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Set root password for MySQL ==&lt;br /&gt;
&lt;br /&gt;
You obviously must know it already:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -p&lt;br /&gt;
update user set password=PASSWORD(&amp;quot;yourpassword&amp;quot;) where User=&amp;quot;root&amp;quot;;&lt;br /&gt;
flush privileges;&lt;br /&gt;
quit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then attempt to access MySQL:&lt;br /&gt;
&lt;br /&gt;
mysql -p&amp;lt;br&amp;gt;&lt;br /&gt;
yourpassword&lt;br /&gt;
&lt;br /&gt;
== Show users permissions ==&lt;br /&gt;
&lt;br /&gt;
show grants;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
SHOW GRANTS FOR &#039;root&#039;@&#039;localhost&#039;;&lt;br /&gt;
&lt;br /&gt;
=== All users ===&lt;br /&gt;
&lt;br /&gt;
SELECT User FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT * FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
SELECT CONCAT(&#039;SHOW GRANTS FOR &#039;&#039;&#039;,user,&#039;&#039;&#039;@&#039;&#039;&#039;,host,&#039;&#039;&#039;;&#039;) FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
http://dbadiaries.com/no-mysql-show-users-how-to-list-mysql-user-accounts-and-their-privileges&lt;br /&gt;
&lt;br /&gt;
== Show over 1000 rows ==&lt;br /&gt;
&lt;br /&gt;
use database&lt;br /&gt;
select * from table where type=&amp;quot;HeaderValue&amp;quot; LIMIT 0,99999;&lt;br /&gt;
&lt;br /&gt;
== Show tables column headers ==&lt;br /&gt;
&lt;br /&gt;
show columns from table;&lt;br /&gt;
&lt;br /&gt;
== Uninstall MySQL completely (Unix) ==&lt;br /&gt;
&lt;br /&gt;
If for example you have installed mysql-server, then uninstalled, then installed it again but it is not prompting you for the root password like before, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get purge mysql-server mysql-common mysql-client&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Unknown table engine &#039;InnoDB&#039; ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;MySQL query failed: Unknown table engine &#039;InnoDB&#039;&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Look inside the /etc/mysql/my.cnf file and ensure you don&#039;t have skip-innodb in there. If so, comment out and restart MySQL.&lt;br /&gt;
&lt;br /&gt;
== [http://www.mosbase.com/2010/05/install-latest-version-of-mysql-on.html Upgrade on Ubuntu 8.04] ==&lt;br /&gt;
&lt;br /&gt;
== [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 Upgrade on Ubuntu 10.04] ==&lt;br /&gt;
&lt;br /&gt;
Alternate guides: [http://superuser.com/questions/146337/install-mysql-5-5-on-ubuntu-10-04 1], [http://www.php-trivandrum.org/general-articles/how-i-got-mysql-55-running-on-ubuntu-10-server 2], [http://akbarahmed.com/2012/04/08/install-mysql-5-5-on-ubuntu-10-04-lts-running-in-the-rackspace-cloud-2 3]&lt;br /&gt;
&lt;br /&gt;
=== MySQL 5.5. error ===&lt;br /&gt;
&lt;br /&gt;
If you get the below error when stopping MySQL after upgrading MySQL from 5.1 to 5.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/mysql stop&lt;br /&gt;
* MySQL server PID file could not be found!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | grep mysql&lt;br /&gt;
#this will then show the below output&lt;br /&gt;
mysql    11683  0.0  3.5 410276 71276 ?        Sl   06:48   0:00 mysqld --skip-grant-tables --user=mysql&lt;br /&gt;
&lt;br /&gt;
#kill the process id&lt;br /&gt;
kill 11683&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
/etc/init.d/mysql stop&lt;br /&gt;
/etc/init.d/mysql start&lt;br /&gt;
&lt;br /&gt;
ps aux | grep mysql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
root      5291  0.1  0.0   4088   668 pts/1    S    09:51   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/serverhostname.pid&amp;lt;br&amp;gt;&lt;br /&gt;
mysql     5615  1.1  4.2 621124 84776 pts/1    Sl   09:51   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log&amp;lt;br&amp;gt;&lt;br /&gt;
--pid-file=/usr/local/mysql/data/serverhostname.pid --socket=/var/run/mysqld/mysqld.sock --port=3306&amp;lt;br&amp;gt;&lt;br /&gt;
root      5670  0.0  0.0   6156   696 pts/1    S+   09:51   0:00 grep mysql&lt;br /&gt;
&lt;br /&gt;
== Version 5.5 on CentOS 6 with Plesk ==&lt;br /&gt;
&lt;br /&gt;
This is really only possible on CentOS 5, as of 08/03/2013&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm&lt;br /&gt;
rpm -Uvh remi-release-6*.rpm&lt;br /&gt;
vim /etc/yum.repos.d/remi.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the top &amp;lt;nowiki&amp;gt;[remi]&amp;lt;/nowiki&amp;gt; to enabled=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;yum list mysql-server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://dba.stackexchange.com/questions/16316/why-can-i-only-install-mysql-5-1-on-cent-os-6-2 A script to get the latest MySQL 5.5 for RHEL6]&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use the Atomic repo, however you &#039;&#039;&#039;must&#039;&#039;&#039; disable it afterwards, otherwise it may remove Plesk when it auto-updates.&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1113</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1113"/>
		<updated>2018-11-30T14:44:00Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* 7zip */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1112</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1112"/>
		<updated>2018-11-30T14:43:32Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* 7zip */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because:&lt;br /&gt;
&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar:&lt;br /&gt;
&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
example : 7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1111</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1111"/>
		<updated>2018-11-30T14:42:58Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Gunzip and Zip */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because :&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar :&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
example : 7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1110</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1110"/>
		<updated>2018-11-30T14:42:43Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* Gunzip and Zip */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
=== 7zip ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Byron Galietta &amp;lt;byrontcg@gmail.com&amp;gt;&lt;br /&gt;
Tue, 4 Apr 2017, 18:39&lt;br /&gt;
to me&lt;br /&gt;
&lt;br /&gt;
https://www.howtoforge.com/tutorial/how-to-install-and-use-7zip-file-archiver-on-ubuntu-linux/&lt;br /&gt;
&lt;br /&gt;
DO NOT USE the 7-zip format for backup purpose on Linux/Unix because :&lt;br /&gt;
- 7-zip does not store the owner/group of the file.&lt;br /&gt;
&lt;br /&gt;
On Linux/Unix, in order to backup directories you must use tar :&lt;br /&gt;
- to backup a directory  : tar cf -  directory  |  7za  a  -si  directory.tar.7z&lt;br /&gt;
- to restore your backup : 7za x -so directory.tar.7z | tar xf -&lt;br /&gt;
&lt;br /&gt;
If  you  want  to send files and directories (not the owner of file) to others Unix/MacOS/Windows users, you can use the 7-zip format.&lt;br /&gt;
example : 7za a directory.7z  directory&lt;br /&gt;
&lt;br /&gt;
Do not use &amp;quot;-r&amp;quot; because this flag does not do what you think.&lt;br /&gt;
&lt;br /&gt;
Do not use directory/* because of &amp;quot;.*&amp;quot; files (example  :  &amp;quot;directory/*&amp;quot; does not match &amp;quot;directory/.profile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
https://www.unixtutorial.org/2014/08/7zip-ubuntu/&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1109</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1109"/>
		<updated>2018-09-18T13:56:37Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* tmux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also possible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
	<entry>
		<id>http://serverkb.co.uk/index.php?title=Linux&amp;diff=1108</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://serverkb.co.uk/index.php?title=Linux&amp;diff=1108"/>
		<updated>2018-09-18T12:20:21Z</updated>

		<summary type="html">&lt;p&gt;Rootadminacc: /* tmux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To check your server info, do lscpu &amp;lt;br&amp;gt;&lt;br /&gt;
To run a bash script without executing it, do bash -n scriptname.sh&amp;lt;br&amp;gt;&lt;br /&gt;
To see help commands do command --help or man command. To paste into PuTTY, use SHIFT + INSERT.&amp;lt;br&amp;gt;&lt;br /&gt;
For detailed software and hardware info do apt-get install hardinfo then hardinfo. For CentOS 6 use [http://pkgs.repoforge.org/hardinfo/hardinfo-0.5.1-1.el6.rf.x86_64.rpm this].&amp;lt;br&amp;gt;&lt;br /&gt;
To write to a user in the same SSH server, do w, get their tty  session and then do write user ttySession. If they are root, do  write root Session&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.linuxfocus.org/English/September1999/article103.html Awk introduction], [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html If manual].&lt;br /&gt;
&lt;br /&gt;
== Append date to same line ==&lt;br /&gt;
&lt;br /&gt;
Either of these will work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;| awk &#039;{ print strftime(&amp;quot;%Y-%m-%d %H:%M:%S&amp;quot;), $0; }&#039;&lt;br /&gt;
| ts &#039;%F %T&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To customise date, put a + symbol in front of the flag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%R&lt;br /&gt;
14:32&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get this format of the date/time:&lt;br /&gt;
&lt;br /&gt;
24 May 2013 10:25:33&lt;br /&gt;
&lt;br /&gt;
Use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date +%d\ %B\ %Y\ %H:%M:%S&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== authorized_keys (RSA) ==&lt;br /&gt;
&lt;br /&gt;
This will show you how to SCP, SSH and rSync without prompting for password between two servers.&lt;br /&gt;
&lt;br /&gt;
Whenever you need to use SCP to copy files, it asks for passwords. Same with rSync as it (by default) uses SSH as well. Usually SCP and rSync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn&#039;t. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it...&lt;br /&gt;
&lt;br /&gt;
Lets say you want to copy between two hosts host_src and host_dest. host_src is the host where you would run the SCP, SSH or rSync command, irrespective of the direction of the file copy!&lt;br /&gt;
&lt;br /&gt;
On host_src, run this command as the user that runs SCP/SSH/rSync&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh-keygen -t rsa&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will prompt for a passphrase. Just press the enter key. It&#039;ll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub:&lt;br /&gt;
&lt;br /&gt;
Your public key has been saved in &amp;lt;your_home_dir&amp;gt;/.ssh/id_rsa.pub&lt;br /&gt;
&lt;br /&gt;
Transfer the id_rsa.pub file to host_dest by either FTP, SCP, rSync or any other method.&lt;br /&gt;
&lt;br /&gt;
On host_dest, &#039;&#039;&#039;login as the remote user which you plan to use when you run SCP, SSH or rSync on host_src&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make sure the folder ~/.ssh exists first, if not do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir ~/.ssh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat id_rsa.pub &amp;gt;&amp;gt;~/.ssh/authorized_keys&lt;br /&gt;
chmod 700 ~/.ssh/authorized_keys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why prevent others from reading this file? Probably, the owner of the key has distributed it to a few trusted users and has not placed any additional security measures to check if its really a trusted user.&lt;br /&gt;
&lt;br /&gt;
Note that SSH by default does not allow root to log in. This has to be explicitly enabled on host_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin from no to yes. Don&#039;t forget to restart SSHD so that it reads the modified config file. Do this only if you want to use the root login.&lt;br /&gt;
&lt;br /&gt;
Well, thats it. Now you can run SCP, SSH and rSync on host_src connecting to host_dest and it won&#039;t prompt for the password. Note that this will still prompt for the password if you are running the commands on host_dest connecting to host_src. You can reverse the steps above (generate the public key on host_dest and copy it to host_src) and you have a two way setup ready!&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Colours ===&lt;br /&gt;
&lt;br /&gt;
https://wiki.archlinux.org/index.php/Color_Bash_Prompt&lt;br /&gt;
&lt;br /&gt;
Add these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;source /root/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /root/.vimrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;syntax on&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit your session and re-enter it.&lt;br /&gt;
&lt;br /&gt;
=== Crontab editor ===&lt;br /&gt;
&lt;br /&gt;
Add this line in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;EDITOR=vim; export EDITOR&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Binary/binaries ==&lt;br /&gt;
&lt;br /&gt;
These are normally in the bin or sbin folder for a program.&lt;br /&gt;
&lt;br /&gt;
== Calendar ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install gcal&lt;br /&gt;
gcal -K -q GB_EN December/2012-January/2013 # Holidays for Dec/2012 and Jan/2013 with week numbers&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
== Check Linux version/kernel ==&lt;br /&gt;
&lt;br /&gt;
cat /etc/issue&lt;br /&gt;
&lt;br /&gt;
For Ubuntu do cat /etc/issue or for some CentOS distributions use cat /etc/redhat-release&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uname -a&lt;br /&gt;
uname -r #for just the kernel&lt;br /&gt;
uname -rs #for OS and kernel&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if SELinux is enabled ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install chkconfig&lt;br /&gt;
yum install chkconfig&lt;br /&gt;
&lt;br /&gt;
chkconfig --list&lt;br /&gt;
cat /etc/sysconfig/selinux&lt;br /&gt;
sestatus&lt;br /&gt;
selinuxenabled&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check if Virtualization is available for server ==&lt;br /&gt;
&lt;br /&gt;
CentOS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;egrep &#039;(vmx|svm)&#039; --color=always /proc/cpuinfo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ubuntu:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install cpu-checker&lt;br /&gt;
kvm-ok&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check your PuTTY (TTY) session ==&lt;br /&gt;
&lt;br /&gt;
Type this into command line:&lt;br /&gt;
&lt;br /&gt;
tty&lt;br /&gt;
&lt;br /&gt;
== CLI/bash Commands and scripting ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output Assign variable command output]&lt;br /&gt;
&lt;br /&gt;
* For variables with multiple pipes &amp;quot;|&amp;quot;, use tacs `` instead of quotes &amp;quot;&amp;quot;&lt;br /&gt;
* If you are attempting to use the Unix mail function, you have to specify a body otherwise it will hang.&lt;br /&gt;
* If you have an if statement and its requirements are not met (e.g. greater than) and it then moves onto the next if statement, if it uses a mail function it may send it to the root user&#039;s email or the Admin/Administrator&#039;s email address. To avoid this use &amp;gt; /dev/null . 2&amp;gt;&amp;amp;1 likely won&#039;t work.&lt;br /&gt;
* It seems if you are using the read function, you can only call a variable that is inside of it (subshell), from [http://www.unixguide.net/unix/bash/E4.shtml here].&lt;br /&gt;
* To stop a ping after x amount of responses, do ping -c x or use ping -oc y (where y equals a maximum amount of tries)&lt;br /&gt;
* Use &amp;gt;&amp;gt; to append an output to the end of the file.&lt;br /&gt;
* The use of &amp;amp;&amp;amp; means that you only echo the name of the directory if the directory creation is successful. &lt;br /&gt;
&lt;br /&gt;
- The $() syntax allows you to load anything echoed to STDOUT to be loaded into a variable, and the single quotes ensure that if there are any spaces in the directory name, it still gets loaded into a single variable. To use command substitution, enclose any command that generates output to standard output inside parentheses and precede the opening parenthesis with a dollar sign, $(command). Command substitution is useful when assigning a value to a variable. It is handy for using the output of one command as an argument to another command. [http://mywiki.wooledge.org/BashFAQ/082 Why is $(...) preferred over `...` (backticks)?] . A good use of this is in http://serverkb.co.uk/tools/slow.sh&lt;br /&gt;
&lt;br /&gt;
* To quote double quotes (&amp;quot;) do the following: echo -e &amp;quot;Testing \&amp;quot;quotes\&amp;quot; here&amp;quot; - this will show as Testing &amp;quot;quotes&amp;quot;&lt;br /&gt;
* Quotes prevent wildcard (*) expansion.&lt;br /&gt;
&lt;br /&gt;
=== $? ===&lt;br /&gt;
&lt;br /&gt;
This is the exit status/code of the last executed function/program/command.&lt;br /&gt;
&lt;br /&gt;
=== [http://beyondgrep.com ack] ===&lt;br /&gt;
&lt;br /&gt;
To look into.&lt;br /&gt;
&lt;br /&gt;
=== [http://www.grymoire.com/Unix/Awk.html Awk] ===&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;print out a list of just folders/file&#039;&#039;&#039;s you want, do;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -l filepath | awk &#039;{print $9;}&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This won&#039;t work correctly if there is spaces in the filename. To resolve this, use [[Linux#Find | this]] command whilst in the directory itself.&lt;br /&gt;
&lt;br /&gt;
To do multiple sections of a result, do:&lt;br /&gt;
&lt;br /&gt;
awk &#039;{print $1,$2,$4,$X;}&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use awk in this way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;awk &#039;NR==22&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. To do multiple lines do awk &#039;NR==22,NR==25&#039; . This will output line 22-25.&lt;br /&gt;
&lt;br /&gt;
The command sed &#039;22 ! d&#039; would do the same as the awk &#039;NR==22&#039; example.&lt;br /&gt;
&lt;br /&gt;
To &#039;&#039;&#039;get rid of pipe symbols in a file&#039;&#039;&#039;, do:&lt;br /&gt;
&lt;br /&gt;
awk -F&#039;|&#039; &#039;{print $1,$10}&#039; FileWithPipes &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
Alternatively if you get a list, e.g of domains from MySQL with only one column selected, put them in a file and you can remove the pipes by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat domainlist | awk &#039;{print $2}&#039; &amp;gt; list&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
awk &#039;{ printf &amp;quot;%-20s %-40s\n&amp;quot;, $1, $2}&#039; allows you to &#039;&#039;&#039;[http://stackoverflow.com/questions/6462894/how-can-i-format-the-output-of-a-bash-command-in-neat-columns print information in columns]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Cat ===&lt;br /&gt;
&lt;br /&gt;
Parse JSON file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cat file | python .mjson.tool&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cut ===&lt;br /&gt;
&lt;br /&gt;
This tool can be used in an example where you get an output but want to strip it to exactly what you need e.g.&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Plan : Bronze, Silver, Gold&lt;br /&gt;
Type : IPv4 or IPv6&lt;br /&gt;
URL  : http&lt;br /&gt;
IP   : 0.0.0.0(primary)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
lookupipscript.sh &amp;lt;IPaddress&amp;gt; | sed &#039;row ! d&#039; | awk &#039;{print $column;}&#039;&lt;br /&gt;
&lt;br /&gt;
This would output 0.0.0.0(primary). To get just the IP address and not the &amp;quot;(primary)&amp;quot; section, do:&lt;br /&gt;
&lt;br /&gt;
| cut -c 1-7&lt;br /&gt;
&lt;br /&gt;
Cut counts the first number/letter as 1, not 0.&lt;br /&gt;
&lt;br /&gt;
=== eval ===&lt;br /&gt;
&lt;br /&gt;
Use this of you want run a variable after a pipe and to shorten down your scripts. e.g. in http://serverkb.co.uk/tools/getdns.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ns=&amp;quot;ns.nameserver.co.uk&amp;quot;&lt;br /&gt;
d=&amp;quot;domain.co.uk&amp;quot;&lt;br /&gt;
g=&amp;quot;grep $d | grep -v &#039;DiG\|;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;dig @$ns $d A&amp;quot;&lt;br /&gt;
dig @$ns $d A | eval $g&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is a good replacement instead of $() or `` or running just a variable.&lt;br /&gt;
&lt;br /&gt;
=== [http://unixhelp.ed.ac.uk/CGI/man-cgi?find Find] ===&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories Exclude directories] ====&lt;br /&gt;
&lt;br /&gt;
==== [http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html Guide Part 1] ====&lt;br /&gt;
&lt;br /&gt;
[http://content.hccfl.edu/pollock/unix/findcmd.htm Find Help] (this includes [http://www.unix.com/tips-tutorials/20526-mtime-ctime-atime.html mtime] commands)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -maxdepth 1 -type f -printf &amp;quot;%f\n&amp;quot;  | sed s/,$//&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finds all files that contain &amp;quot;some string&amp;quot;&#039;&#039;&#039;. This command is useful in a directory (e.g. mail), so you would do ls -lah | grep year-mm then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type f -exec grep -l &amp;quot;some string&amp;quot; {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://www.thegeekstuff.com/2011/07/bash-for-loop-examples for loop examples] ===&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
A prime use of functions is in our script to replace the date.timezone settings in php.ini at http://serverkb.co.uk/tools/phptimezone.sh&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
APACHEPHP=&amp;quot;/etc/php5/apache2/php.ini&amp;quot;&lt;br /&gt;
CURRENT=&amp;quot;\n\nThis is the current timezone configuration:&amp;quot;&lt;br /&gt;
DONE=&amp;quot;If the settings were wrong, they are as below now:&amp;quot;&lt;br /&gt;
ETC=&amp;quot;/etc/php.ini&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function UBDEB(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is Debian/Ubuntu, so editing $APACHEPHP&amp;quot; $CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function RHEL(){&lt;br /&gt;
 echo -e &amp;quot;\nThe operating system is likely CentOS, editing $ETC&amp;quot; &amp;quot;$CURRENT&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
  sed -i -e &#039;s/;date.timezone\ =/date.timezone\ =\ \&amp;quot;Europe\/London\&amp;quot;/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_latitude\ =\ 31.7667/date.default_latitude\ =\ 51.500181/g&#039; $1&lt;br /&gt;
  sed -i -e &#039;s/;date.default_longitude\ =\ 35.2333/date.default_longitude\ =\ 0.12619/g&#039; $1&lt;br /&gt;
 echo $DONE&lt;br /&gt;
 grep &amp;quot;date.&amp;quot; $1 | head -7 | grep -v &#039;; http\|Define&#039; ; echo &amp;quot;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Debian&amp;quot; || `cat /etc/issue | sed &#039;1 ! d&#039; | awk &#039;{print $1;}&#039;` == &amp;quot;Ubuntu&amp;quot; ]];&lt;br /&gt;
then&lt;br /&gt;
 UBDEB &amp;quot;$APACHEPHP&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
 RHEL &amp;quot;$ETC&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to Sam Teale for helping me with this.&lt;br /&gt;
&lt;br /&gt;
=== Grep ===&lt;br /&gt;
&lt;br /&gt;
If you are grepping a a .gz or .zip file you generally need to use zgrep.&lt;br /&gt;
&lt;br /&gt;
==== Exclude multiple directories ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;string&#039; -R . -il --exclude=&amp;quot;/proc&amp;quot; --color&lt;br /&gt;
grep -iR &amp;quot;string&amp;quot; * | grep -v &amp;quot;/proc&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Look for IP address ====&lt;br /&gt;
&lt;br /&gt;
do this:&lt;br /&gt;
&lt;br /&gt;
grep -E -o &#039;(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)&#039;&lt;br /&gt;
&lt;br /&gt;
courtesy of [http://stackoverflow.com/questions/427979/how-do-you-extract-ip-addresses-from-files-using-a-regex-in-a-linux-shell/428086#428086 SO]&lt;br /&gt;
&lt;br /&gt;
==== Multiple terms ====&lt;br /&gt;
&lt;br /&gt;
Exclude using -v&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;grep &#039;chroot\|default\|fs\|fs-passwd\|httpsdocs&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is important to remember to not put a \| after the last text term.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This can be used with tail as well.&lt;br /&gt;
&lt;br /&gt;
==== Remove pipe symbols from MySQL ====&lt;br /&gt;
&lt;br /&gt;
mysql -pPASSWORD admin -e&amp;quot;select domain from domains;&amp;quot; grep -v &amp;quot;|&amp;quot; &amp;gt; FileWithoutPipes&lt;br /&gt;
&lt;br /&gt;
==== Switches/flags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-A after&lt;br /&gt;
-B before&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wildcards for filepaths ====&lt;br /&gt;
&lt;br /&gt;
From http://unix.stackexchange.com/questions/203195/wildcards-for-filepaths-arent-working-in-grep :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;* in a regex is not like a filename glob. It means 0 or more of the previous character/pattern. So your examples would be looking for a A then 0 or more B then -DEF&lt;br /&gt;
. in regex means &amp;quot;any character&amp;quot; so you could fix your pattern by using&lt;br /&gt;
grep &#039;AB.*DEF&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Head ===&lt;br /&gt;
&lt;br /&gt;
If for example you do /var/qmail/bin/qmail-qstat and it prints two separate lines, do this to get just the first line:&lt;br /&gt;
&lt;br /&gt;
head -1&lt;br /&gt;
&lt;br /&gt;
=== [http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php If and Else] ===&lt;br /&gt;
&lt;br /&gt;
[http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_02.html Advanced if usage]&lt;br /&gt;
&lt;br /&gt;
Use -f for files, -d for directories&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ -f $VARIABLE ]&lt;br /&gt;
then&lt;br /&gt;
parameters (e.g. echo, mkdir, touch, rm)&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combine if and $? to get to do something with the exit status of the last executed command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [ $? -eq 0 ]; then&lt;br /&gt;
commands&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to prompt for both y and Y for yes input, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ $variable1 = y || $variable2 = Y ]];&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example of the above if x &#039;&#039;&#039;or&#039;&#039;&#039; y is [http://www.unix.com/302444803-post5.html here]. Use || to do if = x or y.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if [[ value = x || y ]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get the following error when executing a bash script outside of it&#039;s directory:&lt;br /&gt;
&lt;br /&gt;
[[: not found&lt;br /&gt;
&lt;br /&gt;
You need to either bash /file/path/to/script or alter the syntax to use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-eq instead of =&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt;(( command )) instead of [[ command ]]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If value equals multiple values ===&lt;br /&gt;
&lt;br /&gt;
Using the syntax above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter a server number (1, 2 or 3): &amp;quot;&lt;br /&gt;
read ServerNo&lt;br /&gt;
&lt;br /&gt;
if [[ ( $ServerNo -eq 1 ) || ( $ServerNo -eq 2 ) || ( $ServerNo -eq 3 ) ]]; then&lt;br /&gt;
  echo &amp;quot;$ServerNo is a valid server, continuing.&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;$ServerNo is not a valid server, exiting.&amp;quot;&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== read ===&lt;br /&gt;
&lt;br /&gt;
One of the simplest uses of this command is to do it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -ne &amp;quot;Enter the filename you want to create: &amp;quot;&lt;br /&gt;
read createdfilename&lt;br /&gt;
touch $createdfilename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sed ===&lt;br /&gt;
&lt;br /&gt;
If you want to &#039;&#039;&#039;get rid of/cut certain/specific lines/rows from STDOUT&#039;&#039;&#039; aka &#039;&#039;&#039;print a specific line&#039;&#039;&#039;, use sed in this way:&lt;br /&gt;
&lt;br /&gt;
sed &#039;22 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
This is for use &#039;&#039;without&#039;&#039; a file. This example will only display the 22nd row from your output.&lt;br /&gt;
&lt;br /&gt;
Notes: Blank lines count as a row. The command awk &#039;NR==22&#039; would do the same.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print individual/separate lines, e.g. 1, 4 and 5:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed -ne &#039;1p;4p;5p&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To print between lines 22 to 39:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;22,39 ! d&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To put a variable inside sed, use quotes instead of apostrophes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &amp;quot;22,$variable ! d&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To delete parenthesis/brackets, use this:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;()&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;)&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;(&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;]&#039;&#039;&#039;]//g&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
sed &#039;s/[&#039;&#039;&#039;[&#039;&#039;&#039;]//g&#039;&lt;br /&gt;
&lt;br /&gt;
==== Replace text in a file ====&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/TextToFindToReplace/TextToReplaceItWith/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
To handle spaces, forward slashes and quotes &amp;quot; &amp;quot;, use back slashes like you do in filenames:&lt;br /&gt;
&lt;br /&gt;
sed -i -e &#039;s/&#039;&#039;&#039;File\&amp;quot;quotes\&amp;quot;WithA\ Space&#039;&#039;&#039;/&#039;&#039;HereIs&#039;&#039;\/&#039;&#039;ABackslash&#039;&#039;/g&#039; filename&lt;br /&gt;
&lt;br /&gt;
=== sleep and usleep ===&lt;br /&gt;
&lt;br /&gt;
Use sleep if you want to &amp;quot;wait&amp;quot; X seconds. usleep is measured in microseconds and cannot do more than 1 second. 100000 (100,000 / 100k) = 0.1 seconds. 1,000,000 = 1 second.&lt;br /&gt;
&lt;br /&gt;
=== Shells and subshells ===&lt;br /&gt;
&lt;br /&gt;
If you want a script to make changes to your current shell, not the subshell a bash script works in, execute the script by doing the following (sometimes you may need to do ./ still):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;. script&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This information was provided by these sources: [http://stackoverflow.com/questions/874452/change-current-directory-from-a-script 1], [http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script 2]&lt;br /&gt;
&lt;br /&gt;
=== tee ===&lt;br /&gt;
&lt;br /&gt;
Tee command is used to store and view (both at the same time) the output of any other command.&lt;br /&gt;
&lt;br /&gt;
Tee command writes to the STDOUT, and to a file at a time.&lt;br /&gt;
&lt;br /&gt;
By default the tee command overwrites the file. You can instruct tee command to append (like &amp;gt;&amp;gt; does) to the file using the option –a as shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls | tee –a outputfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [http://mywiki.wooledge.org/BashFAQ/031 Use [[ instead of [] ===&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
If you store a variable with a command within it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=`command`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you should instead store it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;variablename=$(command)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then call it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;${variablename}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Watch ===&lt;br /&gt;
&lt;br /&gt;
Example/s:&lt;br /&gt;
&lt;br /&gt;
To monitor a file&#039;s size:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;watch -n 1 &#039;ls -lh | grep filename&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xargs ===&lt;br /&gt;
&lt;br /&gt;
This can be incredibly useful if you get &amp;quot;Argument list too long&amp;quot; &lt;br /&gt;
&lt;br /&gt;
cd /to/directory , find . -type f | xargs rm -Rf&lt;br /&gt;
&lt;br /&gt;
If you need to remove a list of files with spaces in them, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah | grep &amp;quot;SpecificString&amp;quot; | awk &#039;{print $9,$10,$11,$etc}&#039; | xargs -I {} rm -v {}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ls -lh to not include hidden files/file starting with a full stop.&lt;br /&gt;
&lt;br /&gt;
For simple removal of normal files do this in a screen session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | awk &#039;{print $9}&#039; | xargs -t rm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise try using find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -exec grep PATTERN {} + | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copying multiple files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lh | grep TEXT | awk &#039;{print $9}&#039; | xargs cp -t /target/path/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compare a remote file with a local file ==&lt;br /&gt;
&lt;br /&gt;
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
=== Compare files in a directory ===&lt;br /&gt;
&lt;br /&gt;
diff -bur folder1/ folder2/&lt;br /&gt;
&lt;br /&gt;
Warning: when doing diff on folders, if the timestamps are different it will think the files are different. If you actually compare the files, they will be the same.&lt;br /&gt;
&lt;br /&gt;
== Console Clock in corner ==&lt;br /&gt;
&lt;br /&gt;
while true; do echo -ne &amp;quot;\e[s\e[0;$((COLUMNS-27))H$(date)\e[u&amp;quot;; sleep 1; done &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning, this auto scrolls your SSH session&#039;&#039;&#039;. To kill it, do:&lt;br /&gt;
&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
&lt;br /&gt;
Then kill the bash session at the time you ran it:&lt;br /&gt;
&lt;br /&gt;
kill &amp;lt;processid&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/SQUIIDUX Squiidux]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- == Create chroot user with SCP access ==&lt;br /&gt;
&lt;br /&gt;
http://www.linuxscrew.com/2012/07/05/linux-restricted-shells-rssh-and-scponly&amp;lt;br&amp;gt;&lt;br /&gt;
http://ubuntuforums.org/showthread.php?t=128206&amp;lt;br&amp;gt;&lt;br /&gt;
http://internetpartner.info/en/ubuntu/87-openssh-sftp-chroot-on-ubuntu.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/9837/do-you-need-a-shell-for-scp&amp;lt;br&amp;gt;&lt;br /&gt;
http://unix.stackexchange.com/questions/48509/configure-scp-access-for-login-without-a-local-account&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install rssh&lt;br /&gt;
cd /usr/src&lt;br /&gt;
wget http://serverkb.co.uk/tools/scponly-20110526.tgz&lt;br /&gt;
tar scponly-20110526.tgz&lt;br /&gt;
cd scponly-20110526&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vim /etc/rssh.conf&lt;br /&gt;
&lt;br /&gt;
Uncomment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;allowscp&lt;br /&gt;
allowsftp&lt;br /&gt;
chrootpath = /path/to/new/home/directory&lt;br /&gt;
user=username:011:000110:/path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/new/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
http://aristomagnus.wordpress.com/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/&lt;br /&gt;
&amp;lt;!-- https://wiki.archlinux.org/index.php/SFTP-chroot&lt;br /&gt;
http://answers.tectia.com/questions/605/how-do-i-chroot-users-on-unix-platforms&lt;br /&gt;
http://administratosphere.wordpress.com/2011/11/04/restricting-users-to-sftp-only-and-to-home-directories-using-a-chroot/&lt;br /&gt;
&amp;lt;pre&amp;gt;adduser username --home /path/to/home/directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;usermod conscp -s /sbin/nologin&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/ssh/sshd_config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Match User username&lt;br /&gt;
        ChrootDirectory /path/to/home/directory&lt;br /&gt;
        ForceCommand internal-sftp&amp;lt;/pre&amp;gt; --&amp;gt; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create symlink ==&lt;br /&gt;
&lt;br /&gt;
https://www.cyberciti.biz/faq/creating-soft-link-or-symbolic-link/&lt;br /&gt;
&lt;br /&gt;
How to chown a symlink: https://superuser.com/questions/68685/chown-is-not-changing-symbolic-link&lt;br /&gt;
&lt;br /&gt;
Old method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ln -s TARGET LINK_NAME&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cronjob/Crontab ==&lt;br /&gt;
&lt;br /&gt;
To check a cronjob has at least attempted to run/execute, check this at the time of execution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tail -f /var/log/syslog | grep CRON&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.openjs.com/scripts/jslibrary/demos/crontab.php Generator]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;crontab -e&lt;br /&gt;
crontab -l&lt;br /&gt;
&lt;br /&gt;
*     *     *   *    *        command to be executed&lt;br /&gt;
-     -     -   -    -&lt;br /&gt;
|     |     |   |    |&lt;br /&gt;
|     |     |   |    +----- day of week (0 - 6) (Sunday = 0 or 7)&lt;br /&gt;
|     |     |   +------- month (1 - 12)&lt;br /&gt;
|     |     +--------- day of        month (1 - 31)&lt;br /&gt;
|     +----------- hour (0 - 23)&lt;br /&gt;
+------------- min (0 - 59)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Guides:&lt;br /&gt;
&lt;br /&gt;
http://www.adminschoice.com/crontab-quick-reference&lt;br /&gt;
&lt;br /&gt;
To do a job every X minutes, do */X * * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every minute in a specific hour, do * X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every X hours, do * */X * * *&lt;br /&gt;
&lt;br /&gt;
To do a job every day at X hour on the hour, do 0 9 * * * for 9am each day.&lt;br /&gt;
&lt;br /&gt;
To do a job every week at 2am on Sunday, do 0 2 * * 0&lt;br /&gt;
&lt;br /&gt;
To monitor active cron jobs, do tail -f /var/log/cron &lt;br /&gt;
&lt;br /&gt;
=== /usr/local/bin/php: No such file or directory ===&lt;br /&gt;
&lt;br /&gt;
Do whereis php&lt;br /&gt;
&lt;br /&gt;
Generally it is actually in /usr/bin/php&lt;br /&gt;
&lt;br /&gt;
== Cron Daemon email ==&lt;br /&gt;
&lt;br /&gt;
If you get the below email:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.daily&lt;br /&gt;
/etc/cron.daily/sysklogd:&lt;br /&gt;
chown: cannot access `/var/log/mail.warn&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/syslog&#039;: No such file or directory&lt;br /&gt;
chown: cannot access `/var/log/mail.info&#039;: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/log&lt;br /&gt;
touch /var/log/mail.warn /var/log/syslog /var/log/mail.info&lt;br /&gt;
/etc/init.d/sysklogd restart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Date ==&lt;br /&gt;
&lt;br /&gt;
=== Spaces ===&lt;br /&gt;
&lt;br /&gt;
To put spaces between variables (e.g +%H%M) use single quotes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;The time is `date &#039;+%R:%S %Y %Z&#039;` on the following Day/Month/Year `date &#039;+%a %b %d&#039;`&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Echo colours ==&lt;br /&gt;
&lt;br /&gt;
[http://misc.flogisoft.com/bash/tip_colors_and_formatting Tips for colours and formatting]&lt;br /&gt;
&lt;br /&gt;
Place 0; for the normal version (e.g. Black is 0;30)&amp;lt;br&amp;gt;&lt;br /&gt;
Place 1; before these to get the light colour version.&lt;br /&gt;
&lt;br /&gt;
Here are the colour codes:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;&amp;quot; class=&amp;quot;collapsible collapsed wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot;|&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Colour&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Foreground&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Black&lt;br /&gt;
|30&lt;br /&gt;
|40&lt;br /&gt;
|-&lt;br /&gt;
|Dark Grey&lt;br /&gt;
|1;30&lt;br /&gt;
|1;40&lt;br /&gt;
|-&lt;br /&gt;
|Red&lt;br /&gt;
|31&lt;br /&gt;
|41&lt;br /&gt;
|-&lt;br /&gt;
|Light Red&lt;br /&gt;
|1;31&lt;br /&gt;
|1;41&lt;br /&gt;
|-&lt;br /&gt;
|Green&lt;br /&gt;
|32&lt;br /&gt;
|42&lt;br /&gt;
|-&lt;br /&gt;
|Light Green&lt;br /&gt;
|1;32&lt;br /&gt;
|1;42&lt;br /&gt;
|-&lt;br /&gt;
|Yellow&lt;br /&gt;
|1;33&lt;br /&gt;
|1;43&lt;br /&gt;
|-&lt;br /&gt;
|Brown&lt;br /&gt;
|0;33&lt;br /&gt;
|0;43&lt;br /&gt;
|-&lt;br /&gt;
|Blue&lt;br /&gt;
|34&lt;br /&gt;
|44&lt;br /&gt;
|-&lt;br /&gt;
|Light Blue&lt;br /&gt;
|1;34&lt;br /&gt;
|1;44&lt;br /&gt;
|-&lt;br /&gt;
|Magenta (Purple)&lt;br /&gt;
|35&lt;br /&gt;
|45&lt;br /&gt;
|-&lt;br /&gt;
|Light Purple&lt;br /&gt;
|1;35&lt;br /&gt;
|1;45&lt;br /&gt;
|-&lt;br /&gt;
|Cyan&lt;br /&gt;
|36&lt;br /&gt;
|46&lt;br /&gt;
|-&lt;br /&gt;
|Light Cyan&lt;br /&gt;
|1;36&lt;br /&gt;
|1;46&lt;br /&gt;
|-&lt;br /&gt;
|White&lt;br /&gt;
|37&lt;br /&gt;
|47&lt;br /&gt;
|-&lt;br /&gt;
|Light Gray&lt;br /&gt;
|0;37&lt;br /&gt;
|0;47&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
wipe=&amp;quot;\033[1m\033[0m&amp;quot;&lt;br /&gt;
&lt;br /&gt;
black=&amp;quot;40m&amp;quot;&lt;br /&gt;
darkggrey=&#039;\E[1;30m&#039;&lt;br /&gt;
red=&#039;\E[31m&#039;&lt;br /&gt;
lightred=&#039;\E[1;31m&#039;&lt;br /&gt;
green=&#039;\E[32m&#039;&lt;br /&gt;
lightgreen=&#039;\E[1;32m&#039;&lt;br /&gt;
yellow=&#039;\E[1;33m&#039;&lt;br /&gt;
brown=&#039;\E[0;33m&#039;&lt;br /&gt;
blue=&#039;\E[34m&#039;&lt;br /&gt;
lightblue=&#039;\E[1;34m&#039;&lt;br /&gt;
purple=&#039;\E[35m&#039;&lt;br /&gt;
lightpurple=&#039;\E[1;35m&#039;&lt;br /&gt;
cyan=&#039;\E[36m&#039;&lt;br /&gt;
lightcyan=&#039;\E[1;36m&#039;&lt;br /&gt;
white=&#039;\E[37m&#039;&lt;br /&gt;
lightgray=&#039;\E[0;37m&#039;&lt;br /&gt;
green=&#039;\E[32m;&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;$green$black&amp;quot;&lt;br /&gt;
echo Hello World&lt;br /&gt;
echo -e &amp;quot;$wipe&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo -e &amp;quot;Output a ${green}coloured${wipe} word.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./colourtest.sh&lt;br /&gt;
&lt;br /&gt;
Hello World&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Hello World text appears green.&lt;br /&gt;
&lt;br /&gt;
== Execute one off command whenever ==&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;ls -l&amp;quot; | at midnight&lt;br /&gt;
&lt;br /&gt;
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/root Root]&lt;br /&gt;
&lt;br /&gt;
== File Locations (index priority) ==&lt;br /&gt;
&lt;br /&gt;
/etc/apache2/mods-enabled/dir.conf (on Ubuntu) or /etc/httpd/conf/httpd.conf (on CentOS, ~line 402) and it should show something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.html.var index.shtml index.cfm index.php index.htm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This shows the default priority in which the index page is picked up and this can be set in the [[.htaccess]] file as well with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;DirectoryIndex index.html index.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are good places to check if you are using all of your [[Resource_Usage|disk space]].&lt;br /&gt;
&lt;br /&gt;
cd /var/log&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/www/vhosts (website and statistics)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/mysql (database) or mysql/mysql&amp;lt;br&amp;gt;&lt;br /&gt;
cd /usr/bin/mysqldump (mysql dump)&amp;lt;br&amp;gt;&lt;br /&gt;
cd var/qmail (mail logs, queue and configuration)&amp;lt;br&amp;gt;&lt;br /&gt;
cd /var/lib/psa/dumps (physical Plesk backups)&amp;lt;br&amp;gt;&lt;br /&gt;
cd opt/psa/tmp/ (Plesk stores temporary files here for backups)&lt;br /&gt;
&lt;br /&gt;
== File Permissions ==&lt;br /&gt;
&lt;br /&gt;
[http://linuxcommand.org/lts0070.php One of the best permissions guide]&lt;br /&gt;
&lt;br /&gt;
The values and their equivalent permissions. R is Read, W is Write and X is Execute. There are three sets on a file or folder (e.g. -rwx-w--w- , -rw-r--r-- , -rwxr-xrwx) so you need to put in a value of three (or four in rare occasions) for a file/folder e.g. 644.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;0  ---&amp;lt;br&amp;gt;&lt;br /&gt;
1  --x&lt;br /&gt;
2  -w-&lt;br /&gt;
3  -wx&lt;br /&gt;
4  r--&lt;br /&gt;
5  r-x&lt;br /&gt;
6  rw-&lt;br /&gt;
7  rwx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The syntax for chmod is (for example) 755 fileorfolder. The -R option can also be used to set the permissions on anything below a folder.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;The syntax for chown is chown user:group fileorfolder . To apply the user:group to anything below a folder you need to use the -R option.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://permissions-calculator.org/ Permissions Calculator]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.tuxfiles.org/linuxhelp/filepermissions.html Help Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.freeos.com/articles/3127?page=3 Help Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Filesystem_permissions#Notation_of_traditional_Unix_permissions Unix Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.faqs.org/docs/linux_intro/sect_03_04.html File protection with chmod]&lt;br /&gt;
&lt;br /&gt;
If you use PHP Support as &#039;&#039;&#039;Apache module, it will use the third value of&#039;&#039;&#039; -rw- r-- &#039;&#039;&#039;r-x&#039;&#039;&#039; to permissions. If it is using &#039;&#039;&#039;Fast CGI it will use the user:group&#039;&#039;&#039; for the first two values &#039;&#039;&#039;-rwx rw-&#039;&#039;&#039; --x&lt;br /&gt;
&lt;br /&gt;
If you are using Plesk a good place to check if you are getting Forbidden errors on your website is /var/www/vhosts/yourdomain.com/httpdocs/statistics/logs/error_log . Access your site and tail -f that file. If you get .htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable name your .htaccess file correctly, set your httpdocs to 757 and see [http://serverfault.com/questions/61726/permission-denied-home-htaccess-pcfg-openfile-unable-to-check-htaccess-file this link].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Special permissions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
There is also a, g &amp;amp; s which are not widely used as it just needs additional representation at the special/setid permission to the group.&lt;br /&gt;
&lt;br /&gt;
To set a file to -rws--x--x for example use &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;4 = setuid - s&lt;br /&gt;
2 = setgid - s&lt;br /&gt;
4 + 2 = S&lt;br /&gt;
1 = Sticky Bit&lt;br /&gt;
4 + 2 + 1 = T&lt;br /&gt;
2511  -r-x--s--x (e.g. /var/qmail/bin/qmail-remote or /var/qmail/bin/qmail-queue)&lt;br /&gt;
4655  -rwSr-xr-x&lt;br /&gt;
4711  -rws--x--x&lt;br /&gt;
4744  -rwsr--r--&lt;br /&gt;
4755  -rwsr-xr-x&lt;br /&gt;
6411  -r-S--s--x.&lt;br /&gt;
6511  -r-s--s--x&lt;br /&gt;
6644  -rwSr-Sr--&lt;br /&gt;
6666  -rwSrwSrw-&lt;br /&gt;
7000  ---S--S--T&lt;br /&gt;
7644  -rwSr-Sr-T&lt;br /&gt;
7711  -rws--s--t&lt;br /&gt;
7744  -rwsr-Sr-T&lt;br /&gt;
7755  -rwsr-sr-t&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://serverfault.com/questions/111350/what-chmod-and-ownergroup-settings-are-best-for-a-web-application Owner and Group advice for websites]&lt;br /&gt;
&lt;br /&gt;
== [http://adminlogs.info/2011/06/02/linux-find-command-tips Find command guide] ==&lt;br /&gt;
&lt;br /&gt;
== [http://serverfault.com/questions/35076/need-to-fix-file-permissions-in-a-users-home-directory Fix file and folder permissions easily] ==&lt;br /&gt;
&lt;br /&gt;
== FreeBSD ==&lt;br /&gt;
&lt;br /&gt;
* mysqldump location: /mysql/bin/mysqldump&lt;br /&gt;
* Remove syntax:&lt;br /&gt;
&lt;br /&gt;
- rm -r folderName&lt;br /&gt;
* Generic tunneling interface starts with gif&lt;br /&gt;
&lt;br /&gt;
=== [http://forums.freebsd.org/showthread.php?t=5852 Check software versions] ===&lt;br /&gt;
&lt;br /&gt;
=== fetch instead of wget ===&lt;br /&gt;
&lt;br /&gt;
To download a file.&lt;br /&gt;
&lt;br /&gt;
=== whereis instead of locate command ===&lt;br /&gt;
&lt;br /&gt;
To find files/folders.&lt;br /&gt;
&lt;br /&gt;
== Full Directory listing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install tree&lt;br /&gt;
yum install tree&lt;br /&gt;
tree &amp;gt; tree.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you feel adventurous do cat tree.txt , it will take a while ;)&lt;br /&gt;
&lt;br /&gt;
=== Find the deepest directory in your server/file structure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find . -type d -printf &#039;%d:%p\n&#039; | sort -n | tail -1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find and remove specific file types from current directory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd into the directory&lt;br /&gt;
find . -type f -name &#039;*.filetype&#039; -exec rm -v {} \;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Line count a file ===&lt;br /&gt;
&lt;br /&gt;
wc -l /file/path&lt;br /&gt;
&lt;br /&gt;
== Generate random number ==&lt;br /&gt;
&lt;br /&gt;
Between 1 and 10:&lt;br /&gt;
&lt;br /&gt;
seq 10| shuf | head -1&lt;br /&gt;
&lt;br /&gt;
== GeoIP - Block countries accessing website ==&lt;br /&gt;
&lt;br /&gt;
Ubuntu: apt-cache search geoip ; apt-get install geoip-database libgeoip-dev libgeoip1 python-geoip geoip-bin libapache2-mod-geoip tclgeoip&amp;lt;br&amp;gt;&lt;br /&gt;
CentOS: yum list |grep -i geo , yum install GeoIP.x86_64&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webhostingtalk.com/showthread.php?t=959646&amp;lt;br&amp;gt;&lt;br /&gt;
http://askmatt.co.uk/blog/2010/05/block-countries-using-apache-mod-geo-ip-list-of-countries-by-fraud-risk&lt;br /&gt;
&lt;br /&gt;
== Gunzip and Zip ==&lt;br /&gt;
&lt;br /&gt;
To gzip a file (.gz) up, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above won&#039;t work for folders.&lt;br /&gt;
&lt;br /&gt;
Or if zip is installed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;zip -r filename.zip filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unzip a .gz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gunzip file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To extract a .tgz file, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar zxvf fileNameHere.tgz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See http://serverkb.co.uk/wiki/Linux#tar_command for further details.&lt;br /&gt;
&lt;br /&gt;
== [http://eng.eelcowesemann.nl/plesk/changing-the-servers-hostname-in-plesk Hostname guide] (rough) ==&lt;br /&gt;
&lt;br /&gt;
If the server runs Plesk and Virtuozzo, the permanent one needs setting on the hardware or in Virtuozzo.&lt;br /&gt;
&lt;br /&gt;
Run dig -x IP.IP.IP.IP from any Linux server and it will show you the PTR/hostname.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Most servers by default come with a non resolving hostname of localhost, localhost.localdomain or something generic.&lt;br /&gt;
&lt;br /&gt;
The hostname should never be left as the default value on a server sending mail, as it is one of three things mail recipient&#039;s mailservers see to determine if mail is spam or not. The other two are reverse DNS and the SMTP banner.&lt;br /&gt;
&lt;br /&gt;
If Plesk throws an error when clicking Websites &amp;amp; Domains tab regarding hostname -f, see [[Plesk_Errors#Domains_area_is_blank | this resolution]].&lt;br /&gt;
&lt;br /&gt;
== How to fix broken packages ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg --configure -a&lt;br /&gt;
apt-get install -f&lt;br /&gt;
#or&lt;br /&gt;
apt-get -f install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the problem still exists, then edit dpkg status file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;gksudo gedit /var/lib/dpkg/status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the package in question, and remove everything that has anything to do with it and save the file.&lt;br /&gt;
&lt;br /&gt;
== How to install .deb files ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i filename.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[.htaccess]] ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Htaccess HyperText access]&lt;br /&gt;
&lt;br /&gt;
== [http://stackoverflow.com/questions/653096/howto-free-inode-usage inode usage] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df --si&lt;br /&gt;
df -ih&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A lot of the time the cause can be /tmp (/var/lib/php/session/ on Plesk) due to sessions. You may want to delete the files in there.&lt;br /&gt;
&lt;br /&gt;
== Investigating high load ==&lt;br /&gt;
&lt;br /&gt;
If you are getting a high load average in top, these are some of the steps you can take to investigate the issue.&lt;br /&gt;
&lt;br /&gt;
Check which process has the most open of itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ps aux | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nk1 | tail -n5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stop that process, then run the above command a second time. Then start it again and run the command a third time.&lt;br /&gt;
&lt;br /&gt;
=== Useful software ===&lt;br /&gt;
&lt;br /&gt;
* top&lt;br /&gt;
* htop&lt;br /&gt;
* iotop&lt;br /&gt;
&lt;br /&gt;
All these will do the job. Firstly check the CPU wait time, this is shown within top in Cpu(s):  8.0%us,  2.8%sy,  0.0%ni, 40.7%id, 48.3%wa&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;%wa in&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this is high, check the Status column (S column in top) to see if any are labelled D. The [http://stackoverflow.com/questions/666783/how-to-find-out-which-process-is-consuming-wait-cpu-i-e-i-o-blocked processes blocked on IO] are the ones marked as D.&lt;br /&gt;
&lt;br /&gt;
=== On a Plesk server ===&lt;br /&gt;
&lt;br /&gt;
Ensure sites are running PHP as Fast CGI Application instead of Apache module so you can see which USER the process is running as. Pressing the letter &amp;quot;c&amp;quot; on your keyboard will show the path and normally the website name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://serverkb.co.uk/tools/memcpu.sh ; chmod +x memcpu.sh ; ./memcpu.sh &amp;gt; usage.log &amp;amp;&lt;br /&gt;
tail -f usage.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alter the PHP Handler on Plesk boxes in the psa database easily by doing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql -uadmin -p`cat /etc/psa/.psa.shadow`;&lt;br /&gt;
use psa&lt;br /&gt;
select * from hosting\G&lt;br /&gt;
select dom_id,www_root,php_handler_type from hosting;&lt;br /&gt;
update hosting set php_handler_type=&amp;quot;module&amp;quot; where dom_id=x;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If sites run PHP as an Apache module scripts will execute as the Apache user www-data, this can make it difficult to see which site they belong to. This also means scripts run with privileges of the Apache user so if an account is compromised an attacker can get access to all other accounts. Also running as Apache module can make the Apache process CPU report look artificially high. Running PHP as Fast-CGI executes scripts as an FTP user associated with each subscription allowing easier identification of problem scripts and limit the damage of rogue scripts.&lt;br /&gt;
&lt;br /&gt;
CPU reports are not an easy way to determine server health. We&#039;d recommend you look at changes and trends rather than the absolute numbers. Most importantly consider your real world performance.&lt;br /&gt;
&lt;br /&gt;
== Linux Container ==&lt;br /&gt;
&lt;br /&gt;
This install below is for an Ubuntu physical server, I may update this in the future for CentOS, Fedora and others.&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/12.04/serverguide/lxc.html&lt;br /&gt;
&lt;br /&gt;
If you need to get file off the container, you can just scp it off. If the recipient server is slow, try moving the file to the host machine by doing:&lt;br /&gt;
&lt;br /&gt;
scp -Psshport file root@hostIPaddress:~&lt;br /&gt;
&lt;br /&gt;
=== Installation of LXC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install lxc&lt;br /&gt;
cat /etc/init/lxc-net.conf | grep USE_LXC_BRIDGE&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If true set to false unless you want the containers to NAT to your servers real IP addresses, and to be accessible externally.&lt;br /&gt;
&lt;br /&gt;
=== Pre-container creation steps ===&lt;br /&gt;
&lt;br /&gt;
To reduce errors pre-container creation do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg-reconfigure locales&lt;br /&gt;
locale-gen en_GB&lt;br /&gt;
update-locale LANG=en_GB.UTF-8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- &amp;lt;pre&amp;gt;vim ~/.profile&lt;br /&gt;
export LC_CTYPE=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/environment&lt;br /&gt;
LC_ALL=&amp;quot;en_GB.utf8&amp;quot;&amp;lt;/pre&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating/deleting containers ===&lt;br /&gt;
&lt;br /&gt;
[http://wiki.openvz.org/Download/template/precreated OpenVZ Template list]&lt;br /&gt;
&lt;br /&gt;
Check the templates below and pick one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/lib/lxc/templates/ ; ls -lah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a container from one of the templates:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-create -t ubuntu -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to install the fedora package, do apt-get install yum&lt;br /&gt;
&lt;br /&gt;
To delete it just do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-destroy -n NameOfTheContainer&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start/stop a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-start -n NameOfTheContainer -d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/lxc stop&lt;br /&gt;
&lt;br /&gt;
=== Access the container ===&lt;br /&gt;
&lt;br /&gt;
The default user is &#039;ubuntu&#039; with the password &#039;ubuntu&#039;, to enter a container, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc-console -n NameOfTheContainer&lt;br /&gt;
sudo -i&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit using Ctrl + a, then press q&lt;br /&gt;
&lt;br /&gt;
To re-enter the container, do lxc-console -n NameOfTheContainer and then press enter (you may have to a few times)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access externally:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.3.61:22&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Make sure you remove this rule afterwards and DO NOT reboot your server.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Configuration settings ===&lt;br /&gt;
&lt;br /&gt;
* By default you can ping a container from the host, and vice versa, and you can ping the outside world from the container.&lt;br /&gt;
* You can set the hostname just like a normal server, if you want to rename the container.&lt;br /&gt;
&lt;br /&gt;
==== Default configuration of system files ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /var/lib/lxc/nameofcontainer/rootfs/etc/sysconfig/network-scripts&lt;br /&gt;
vim ifcfg-eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DEVICE=eth0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
HOSTNAME=phptester&lt;br /&gt;
NM_CONTROLLED=no&lt;br /&gt;
TYPE=Ethernet&lt;br /&gt;
MTU=&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /var/lib/lxc/nameofcontainer/config&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&lt;br /&gt;
lxc.network.hwaddr = MAC Address&lt;br /&gt;
lxc.utsname = MT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/lxc/lxc.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;lxc.network.type=veth&lt;br /&gt;
lxc.network.link=lxcbr0&lt;br /&gt;
lxc.network.flags=up&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add the below to /etc/network/interfaces&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;auto br1&lt;br /&gt;
iface br1 inet dhcp&lt;br /&gt;
    bridge_ports eth0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fedora ====&lt;br /&gt;
&lt;br /&gt;
The mirrors/repositories the container uses may be broken by default, don&#039;t try to install anything. You&#039;ll likely get:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
And you likely won&#039;t be able to ping anything except the host machine and localhost/127.0.0.1&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -s ContainerIP/24 -j SNAT --to-source PhysicalHostIP&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10022 -j DNAT -i eth0 --to-destination ContainerIP:80&amp;lt;br&amp;gt;&lt;br /&gt;
iptables -t nat -A PREROUTING -m tcp -p tcp --dport 10443 -j DNAT -i eth0 --to-destination ContainerIP:443&lt;br /&gt;
&lt;br /&gt;
[https://www.berrange.com/posts/2011/09/27/getting-started-with-lxc-using-libvirt libvirt]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi /etc/yum.repos.d/fedora.repo&lt;br /&gt;
vi /etc/yum.repos.d/fedora-updates.repo&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Uncomment (#) the lines starting with &amp;quot;baseurl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
yum update&lt;br /&gt;
&lt;br /&gt;
==== OpenSUSE ====&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/OpenSUSE#Version_history Version history]&lt;br /&gt;
&lt;br /&gt;
http://www.lacerta.be/d7/content/opensuse-lxc-container-inside-ubuntu&lt;br /&gt;
&lt;br /&gt;
=== List containers ===&lt;br /&gt;
&lt;br /&gt;
lxc-list&lt;br /&gt;
&lt;br /&gt;
=== Set passwords ===&lt;br /&gt;
&lt;br /&gt;
Log in as the root user of the container:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fedora&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Username: root&lt;br /&gt;
Password: root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root password to something different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to do yum install vim when inside the server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo -i&lt;br /&gt;
Username: ubuntu&lt;br /&gt;
Password: ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd ubuntu&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the root user&#039;s password:&lt;br /&gt;
&lt;br /&gt;
passwd&lt;br /&gt;
&lt;br /&gt;
=== SSH in externally ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To route from externally through the host to the container, just do the below iptables rule&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables -t nat -A PREROUTING -p tcp --dport 1337 -j DNAT --to 10.0.4.60:22&lt;br /&gt;
iptables-save&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above case we are saying:&lt;br /&gt;
&lt;br /&gt;
- You want to SSH in on port 1337&amp;lt;br&amp;gt;&lt;br /&gt;
- The container&#039;s eth0 IP address is 10.0.4.60&amp;lt;br&amp;gt;&lt;br /&gt;
- Then below we are saying the physical machine has an IP address of 110.111.112.113&lt;br /&gt;
&lt;br /&gt;
Then externally from the server do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ssh root@110.111.112.113 -p2222&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And bingo! You should be in the container.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;passwd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- OpenVZ &lt;br /&gt;
&lt;br /&gt;
https://code.google.com/p/ovz-web-panel/&lt;br /&gt;
&lt;br /&gt;
apt-get install vzctl vzdump vzquota&lt;br /&gt;
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh&lt;br /&gt;
gem install net-ssh&lt;br /&gt;
gem install net-sftp --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://wiki.debian.org/LSBInitScripts LSB Init Scripts] ==&lt;br /&gt;
&lt;br /&gt;
== ls list only directories or files ==&lt;br /&gt;
&lt;br /&gt;
Directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lad */&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -la | grep -v ^d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kill tty session ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;w&lt;br /&gt;
ps aux | grep bash | grep -v grep&lt;br /&gt;
ps aux | grep tty | grep -v grep&lt;br /&gt;
kill -HUP &amp;lt;processid&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-kill-unix-linux-user-session Further info]&lt;br /&gt;
&lt;br /&gt;
== Maldet ==&lt;br /&gt;
&lt;br /&gt;
[http://www.rfxn.com/projects/linux-malware-detect Documentation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.rfxn.com/downloads/maldetect-current.tar.gz Maldet .tar.gz]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://blog.hostonnet.com/how-to-install-and-configure-maldet-linux-malware-detect-lmd Install and Configure]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /root ; wget http://serverkb.co.uk/tools/maldet.sh ; chmod +x maldet.sh ; ./maldet.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always run your scans from chroot environment (if it has one/is possible) and in Screen (screen -S NameIt), and detach by doing CTRL + A, then press D&lt;br /&gt;
&lt;br /&gt;
Scan reports are normally stored in /usr/local/maldetect/sess/ as session. files.&lt;br /&gt;
&lt;br /&gt;
maldet -a -e -l filepath&lt;br /&gt;
&lt;br /&gt;
== Manually alter time/date ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Ubuntu&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;date&lt;br /&gt;
date mmddtimeyear #as seen below&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Cent OS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /etc/&lt;br /&gt;
ls -lah&lt;br /&gt;
rm localtime&lt;br /&gt;
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime&lt;br /&gt;
date mmddtimeyear&lt;br /&gt;
     | |  |   | ---&amp;gt; 2012&lt;br /&gt;
     | |  | 24hr --&amp;gt; XX:XX without :&lt;br /&gt;
     | | dd -------&amp;gt; day&lt;br /&gt;
     | mm ---------&amp;gt; month&lt;br /&gt;
&lt;br /&gt;
/etc/init.d/ntpd restart or start&lt;br /&gt;
date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Move files into your home directory not owned by your own user ==&lt;br /&gt;
&lt;br /&gt;
Copy to /var/tmp or /tmp (for small files) and do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;chmod ugo+rw &amp;lt;filename&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PID ==&lt;br /&gt;
&lt;br /&gt;
Under construction.&lt;br /&gt;
&lt;br /&gt;
Process ID.&lt;br /&gt;
&lt;br /&gt;
To determine the usage of a specific process, do top -p PID&lt;br /&gt;
&lt;br /&gt;
The maximum number of pids can be obtained from /proc/sys/kernel/pid_max&lt;br /&gt;
&lt;br /&gt;
== .profile ==&lt;br /&gt;
&lt;br /&gt;
Put this in .profile file for on user startup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;&amp;quot; ; df -h | sed -ne &#039;1p;5p&#039; ; echo &amp;quot;rootfs&amp;quot;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; free -m&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | head -1 | sed &#039;s/^ *//g&#039;&lt;br /&gt;
echo &amp;quot;&amp;quot; ; w | tail -10 | grep -v average ; echo &amp;quot;&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proxmox ==&lt;br /&gt;
&lt;br /&gt;
To access via the web go to https://IPaddress:8006&lt;br /&gt;
&lt;br /&gt;
Rough notes:&lt;br /&gt;
&lt;br /&gt;
apt-get install sudo&lt;br /&gt;
&lt;br /&gt;
Proxmox&lt;br /&gt;
&lt;br /&gt;
/var/lib/vz&lt;br /&gt;
&lt;br /&gt;
dump is for backups&amp;lt;br&amp;gt;&lt;br /&gt;
images is for OS images&amp;lt;br&amp;gt;&lt;br /&gt;
private is for OpenVZ container file systems&amp;lt;br&amp;gt;&lt;br /&gt;
template/cache is for OpenVZ templates&lt;br /&gt;
&lt;br /&gt;
http://openvz.org/Download/template/precreated&lt;br /&gt;
&lt;br /&gt;
Create VM creates KVM&amp;lt;br&amp;gt;&lt;br /&gt;
Create CT creates OpenVZ container&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzctl enter id&amp;lt;br&amp;gt;&lt;br /&gt;
vzctl start/stop id&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
iptables -t nat -A POSTROUTING -o vmbr1 -j MASQUERADE&amp;lt;br&amp;gt;&lt;br /&gt;
restart networking on host and CT&lt;br /&gt;
&lt;br /&gt;
=== cman_tool: Cannot open connection to cman ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pvecm status&lt;br /&gt;
pvecm nodes&lt;br /&gt;
cman_tool: Cannot open connection to cman, is it running ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;service pve-cluster restart&lt;br /&gt;
pvecm delnode NodeName&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Force remove an OpenVZ container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vzctl stop 100 ; vzctl destroy ContainerID&lt;br /&gt;
cd /var/lib/vz/private&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /var/lib/vz/root&lt;br /&gt;
rm ContainerIDfolder -R&lt;br /&gt;
cd /etc/pve/nodes/ContainerName/openvz&lt;br /&gt;
mv ContainerID.conf ContainerID.bak&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure it does not exist in cat /etc/pve/.members&lt;br /&gt;
&lt;br /&gt;
=== Remount a logical partition/volume ===&lt;br /&gt;
&lt;br /&gt;
lvdisplay&lt;br /&gt;
&lt;br /&gt;
/dev/mapper/pve-data /var/lib/vz (this will be different in your file system)&lt;br /&gt;
&lt;br /&gt;
=== Unable to get local IP address ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/pve-cluster restart&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
Starting pve cluster filesystem : pve-cluster[main] crit: Unable to get local IP address&lt;br /&gt;
 (warning).&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure in /etc/hosts your domain name resolves to the server and you also have it without the .co.uk/.com etc in the file as so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ServerIPaddress domain.co.uk domain pvelocalhost&lt;br /&gt;
127.0.0.1 localhost localhost.localdomain&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/init.d/hostname.sh stop&lt;br /&gt;
/etc/init.d/hostname.sh start&lt;br /&gt;
service pve-cluster start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Transport endpoint is not connected ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;df -h&lt;br /&gt;
df: `/etc/pve&#039;: Transport endpoint is not connected&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ls -lah /etc/pve&lt;br /&gt;
ls: cannot access pve: Transport endpoint is not connected&lt;br /&gt;
d?????????   ? ?    ?                      ?            ? pve&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;umount /etc/pve&lt;br /&gt;
pvecm status&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get:&lt;br /&gt;
&lt;br /&gt;
unable to get IP for node &#039;hostname&#039; - node offline?&lt;br /&gt;
&lt;br /&gt;
The fix is the same as [[Linux#Unable_to_get_local_IP_address | this]] one, ensure you have the domain without the web extension in /etc/hosts resolving to the servers IP address. Then do:&lt;br /&gt;
&lt;br /&gt;
service pve-cluster start&lt;br /&gt;
&lt;br /&gt;
== Recover deleted files ==&lt;br /&gt;
&lt;br /&gt;
You need to install this software before you delete any files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install foremost&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then see this documentation:&lt;br /&gt;
&lt;br /&gt;
https://help.ubuntu.com/community/DataRecovery&amp;lt;br&amp;gt;&lt;br /&gt;
http://ddailygirl.wordpress.com/2010/08/17/recovering-files-after-rm-in-linux&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.howtoforge.com/recover-deleted-files-with-foremost&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.webupd8.org/2009/03/recover-deleted-files-in-ubuntu-debian.html&lt;br /&gt;
&lt;br /&gt;
== Remove file starting with dash ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -- -filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove folder starting with dash&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;rm -rf -- -folder/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove/rename file called tilde ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv &#039;~&#039; newfilename&lt;br /&gt;
rm &#039;~&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restart service or service ==&lt;br /&gt;
&lt;br /&gt;
Useful for differently named ones, e.g.&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/mysqld ] &amp;amp;&amp;amp; service mysqld restart ; [ -f /etc/init.d/mysql ] &amp;amp;&amp;amp; service mysql restart&lt;br /&gt;
&lt;br /&gt;
[ -f /etc/init.d/httpd ] &amp;amp;&amp;amp; service httpd restart ; [ -f /etc/init.d/apache2 ] &amp;amp;&amp;amp; service apache2 restart&lt;br /&gt;
&lt;br /&gt;
== Roughly list file count ==&lt;br /&gt;
&lt;br /&gt;
This includes nested directories:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;find /full/file/path -type f | wc -l&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SCP Command - Secure Copy ==&lt;br /&gt;
&lt;br /&gt;
To secure copy a file from one Linux server to another, use the following syntax form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P PORT file user@IPAddress:/filepath&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 index.html root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To move a folder, put -r in between the port and the file(s)/folder(s) like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;scp -P 22 -r testdirectory/ root@127.0.0.1:/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you receive the following error while trying to SCP a file from one server to the other:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;stdin: is not a tty&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can solve the issue quickly by doing the following on the destination server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vi ~/.bashrc&lt;br /&gt;
  &lt;br /&gt;
if [ $(expr index &amp;quot;$-&amp;quot; i) -eq 0 ]; then&lt;br /&gt;
return&lt;br /&gt;
fi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Screen ==&lt;br /&gt;
&lt;br /&gt;
Re-join screen session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -r&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;screen -D -r &#039;1234.somescreensession&#039;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A better alternate is [[Linux#tmux | tmux]].&lt;br /&gt;
&lt;br /&gt;
[http://www.ubuntugeek.com/screen-manages-multiple-sessions-on-one-terminal.html#more-1415 Manage Multiple sessions in one Terminal]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer Scrollback] (vim /home/.screenrc + defscrollback 1000)&amp;lt;br&amp;gt;&lt;br /&gt;
[http://polishlinux.org/howtos/screen-tips-tricks Tips and Tricks]&lt;br /&gt;
&lt;br /&gt;
== Setting the time ==&lt;br /&gt;
&lt;br /&gt;
http://geoffhankerson.com/node/112&amp;lt;br&amp;gt;&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
== Standard redirection ==&lt;br /&gt;
&lt;br /&gt;
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/&lt;br /&gt;
&lt;br /&gt;
STDIN, STDOUT and STDERR.&lt;br /&gt;
&lt;br /&gt;
0, 1 and 2&lt;br /&gt;
&lt;br /&gt;
1&amp;gt;/dev/null&amp;lt;br&amp;gt;&lt;br /&gt;
2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
== sudo ==&lt;br /&gt;
&lt;br /&gt;
If you exit out of root access and want to run the last command you entered without authentication, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo !!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== System Logs and Shutdown troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are having an issue, a reboot should not be performed if the server can be accessed in any way (e.g. locally in the data centre, only if it is a Dedicated server). This is because after a reboot there is little you can find out from the logs as the important logs get cleared on restart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;last reboot&lt;br /&gt;
last&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do this  to check which files exist:&lt;br /&gt;
&lt;br /&gt;
ls -lh /var/log/syslog ; ls -lh /var/log/kern.log ; ls -lh /var/log/dmesg ; ls -lh /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Then do one or more of these depending on which exist:&lt;br /&gt;
&lt;br /&gt;
grep -i error /var/log/syslog ; grep -i panic /var/log/syslog ; grep -i warning /var/log/syslog&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/dmesg ; grep -i panic /var/log/dmesg ; grep -i warning /var/log/dmesg&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/kern.log ; grep -i panic /var/log/kern.log ; grep -i warning /var/log/kern.log&amp;lt;br&amp;gt;&lt;br /&gt;
grep -i error /var/log/messages ; grep -i panic /var/log/messages ; grep -i warning /var/log/messages&lt;br /&gt;
&lt;br /&gt;
errpt may show an error report on some Unix OS&#039;.&lt;br /&gt;
&lt;br /&gt;
To find .log files, run [[Linux#updatedb_.28locate_command.29 | updatedb]] and then locate *.log&lt;br /&gt;
&lt;br /&gt;
To restart and [http://go2linux.garron.me/reboot-check-disks-for-errors-avoid-force-fsck on boot do a disk check] do (or -rF):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;shutdown -Fr now&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [http://www.pendrivelinux.com/how-to-open-a-tar-file-in-unix-or-linux tar command] ==&lt;br /&gt;
&lt;br /&gt;
To archive and compress a folder/files do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -czvf files.tgz files/&lt;br /&gt;
tar -czvf folder.tar.gz folder/&lt;br /&gt;
tar cvf mubackup.tar mu/ ; gzip -9 mubackup.tar&lt;br /&gt;
&lt;br /&gt;
#.tgz is same as .tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c creates the archive (tar), z compresses it into the gzip, v is verbose, f is the file/folder&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#for tar&lt;br /&gt;
tar xvf file.tar&lt;br /&gt;
&lt;br /&gt;
#for .tgz or tar.gz&lt;br /&gt;
tar zxvf file.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.fluidthoughts.com/howto/tar-gzip/ Guide 1]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/ Guide 2]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://superuser.com/questions/305128/how-to-specify-level-of-compression-when-using-tar-zcvf 3] and [http://superuser.com/questions/156207/untar-ungz-gz-tar-how-do-you-remember-all-the-useful-options 4]&lt;br /&gt;
&lt;br /&gt;
For bz2 files, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tar -xvjpf file&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== top ==&lt;br /&gt;
&lt;br /&gt;
The TIME column in top is displayed in minutes:seconds.hundredths&lt;br /&gt;
&lt;br /&gt;
== tmux ==&lt;br /&gt;
&lt;br /&gt;
C-c is CTRL+C&amp;lt;br&amp;gt;&lt;br /&gt;
C-m is ENTER&lt;br /&gt;
&lt;br /&gt;
=== New session ===&lt;br /&gt;
&lt;br /&gt;
Latest:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new -s session_name&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux new-session -n NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Detach from a session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CTRL +B then D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux kill-session -t myname&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this fails and it says:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;session not found&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&lt;br /&gt;
tmux kill-session -t X&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- where X is the number of the session on the left.&lt;br /&gt;
&lt;br /&gt;
=== List sessions available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux ls&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Re-attach to session ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux attach&lt;br /&gt;
tmux attach -t ID or NameTheSession&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remotely execute a command ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;tmux send-keys -t ID &amp;quot;command&amp;quot; ENTER&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User ID 99 ==&lt;br /&gt;
&lt;br /&gt;
This is most commonly the user nobody. This can be caused by PHP or done on purpose. cat /etc/passwd | grep 99 ; vim /etc/passwd&lt;br /&gt;
&lt;br /&gt;
== User is not in the sudoers file ==&lt;br /&gt;
&lt;br /&gt;
If you try to sudo into a server or run sudo and get the following message:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;&#039;is not in the sudoers file.  This incident will be reported.&#039;&#039;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Do the following command as root and add the username into the file in the same format as the root user:&lt;br /&gt;
&lt;br /&gt;
visudo&lt;br /&gt;
&lt;br /&gt;
== Use unusual characters in filenames ==&lt;br /&gt;
&lt;br /&gt;
If you want to specify a space, lets say the file = /usr/local/etc/&#039;&#039;&#039;testingdatabase.sql&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You need to name the file/folder as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mv /usr/local/etc/testingdatabase.sql /usr/local/etc/testing\ database.sql&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will make the file be &#039;&#039;&#039;testing database.sql&#039;&#039;&#039; , on command line this will appear as &#039;&#039;&#039;testing\ database.sql&#039;&#039;&#039; .&lt;br /&gt;
&lt;br /&gt;
A backslash symbol \ needs to be used before an apostrophe &#039; , bracket (), exclamation/bang ! symbol or question marks ?:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;01\ -\ It\&#039;s\ You.txt&lt;br /&gt;
#How it appears: 01 - It&#039;s You.txt&lt;br /&gt;
&lt;br /&gt;
02\ -\ Boom\!.m3u&lt;br /&gt;
#How it appears: 02 - Boom!.m3u&lt;br /&gt;
&lt;br /&gt;
03\ -\ Why\ Wont\ You\ Work\?.sh&lt;br /&gt;
#How it appears: 03 - Why Wont You Work?.sh&lt;br /&gt;
&lt;br /&gt;
04\ -\ Musical\ Playlist\ For\ \(VPS\)\ Server.m3u&lt;br /&gt;
#How it appears: 04 - Musical Playlist For (VPS) Server.m3u&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== updatedb (locate command) ==&lt;br /&gt;
&lt;br /&gt;
This command is used when you cannot &#039;&#039;&#039;locate&#039;&#039;&#039; a file and you get &amp;quot;&#039;&#039;locate: warning: database /var/lib/slocate/slocate.db&#039; is more than 8 days old&#039;&#039;&amp;quot;. It is advised to run updatedb &#039;&#039;&#039;at least once a month&#039;&#039;&#039;. However if you get the following error when using it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;updatedb: fatal error: load_file: Could not open file: /etc/updatedb.conf: No such file or directory&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to create or edit this file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/updatedb.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and put the following inside of it:&lt;br /&gt;
&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Alternatively run the below script after reading this file http://serverkb.co.uk/tools/README.txt:&lt;br /&gt;
&lt;br /&gt;
http://serverkb.co.uk/tools/updatedbscript.sh&lt;br /&gt;
&lt;br /&gt;
To vim a file you locate, see [http://stackoverflow.com/questions/8228831/why-does-locate-filename-xargs-vim-cause-strange-terminal-behaviour this]. vim $(command)&lt;br /&gt;
&lt;br /&gt;
=== Cannot find an existing file ===&lt;br /&gt;
&lt;br /&gt;
Ensure that the directory path of the file that &#039;&#039;&#039;does&#039;&#039;&#039; exist is not in the following section in /etc/updatedb.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;!-- Alternate prune file:&lt;br /&gt;
PRUNE_BIND_MOUNTS=&amp;quot;yes&amp;quot;&lt;br /&gt;
# PRUNENAMES=&amp;quot;.git .bzr .hg .svn&amp;quot;&lt;br /&gt;
PRUNEPATHS=&amp;quot;/tmp /var/spool /media&amp;quot;&lt;br /&gt;
PRUNEFS=&amp;quot;NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf (FROM HERE IS DIFFERENT) fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs&amp;quot; --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== vim ==&lt;br /&gt;
&lt;br /&gt;
To make a copy the line below where you cursor is, hold CTRL + e. Then put a hash (comment) in front of this line. This is useful for backing up an old value before changing it.&lt;br /&gt;
&lt;br /&gt;
=== Create backup of file whilst in vim ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim file&lt;br /&gt;
:!cp % %-&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Press enter and continue to edit&lt;br /&gt;
&lt;br /&gt;
Credit to User [http://www.commandlinefu.com/commands/by/mpb MPB]&lt;br /&gt;
&lt;br /&gt;
=== Enter Insert mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter i (I)&lt;br /&gt;
&lt;br /&gt;
=== Enter Replace mode ===&lt;br /&gt;
&lt;br /&gt;
Press the letter r (R)&lt;br /&gt;
&lt;br /&gt;
=== E21: Cannot make changes, &#039;Modifiable&#039; is off ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search in file for multiple terms ===&lt;br /&gt;
&lt;br /&gt;
Go to search mode i.e. type &#039;/&#039; and then type \v followed by the words you want to search separated by &#039;|&#039; (pipe).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/\vword1|word2|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to search mode and type the words you want to search separated by &#039;\|&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/word1\|word2\|word3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.&lt;br /&gt;
&lt;br /&gt;
=== See changes made before exiting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:w !diff % -&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing a jar/zip file ===&lt;br /&gt;
&lt;br /&gt;
(zip#Write) sorry, your system doesn&#039;t appear to have the zip pgm&lt;br /&gt;
&lt;br /&gt;
1) Check zip is installed&lt;br /&gt;
&lt;br /&gt;
2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;:set modifiable&lt;br /&gt;
:set write&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)&lt;br /&gt;
&lt;br /&gt;
E382: Cannot write, &#039;buftype&#039; option is set &lt;br /&gt;
&lt;br /&gt;
Check if the file has -e on it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;lsattr filename&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you likely cannot edit it.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the file (e.g. a jar) and use an Archive tool like 7-zip to edit it.&lt;br /&gt;
&lt;br /&gt;
== [http://www.cymru1.net/linux-vps/vps-hints-and-tips.php VPS Hints and Tips] ==&lt;br /&gt;
&lt;br /&gt;
To check for the filepath of a command run top and then press c.&lt;br /&gt;
&lt;br /&gt;
If it is a container on a node, there are generally no datacentre / rack level restrictions as the container is virtualised on a node. The only restrictions are what is put in place via the container itself effectively.&lt;br /&gt;
&lt;br /&gt;
To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:&lt;br /&gt;
&lt;br /&gt;
lsof -i -U&lt;br /&gt;
&lt;br /&gt;
== WHOIS script ==&lt;br /&gt;
&lt;br /&gt;
[http://www.ivarch.com/programs/pv.shtml Pipe Viewer], [http://linux.die.net/man/1/pv PV info page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apt-get install pv ; cd /var/www/vhosts ; ls -l | awk &#039; {print $9}&#039; &amp;gt; domainlist ; wget serverkb.co.uk/tools/findregistrar.sh ; chmod +x findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For CentOS use yum -y install jwhois.x86_64&lt;br /&gt;
&lt;br /&gt;
Edit the file and replace domain registrar with the one you want to find. Then do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;./findregistrar.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== write error ==&lt;br /&gt;
&lt;br /&gt;
If you get the following error when doing write user TTYsession or write user Session:&lt;br /&gt;
&lt;br /&gt;
write: write: you have write permission turned off.&lt;br /&gt;
&lt;br /&gt;
Do this to fix the problem:&lt;br /&gt;
&lt;br /&gt;
mesg y&lt;br /&gt;
&lt;br /&gt;
== [http://linuxcommand.org/writing_shell_scripts.php Writing Shell Scripts] ==&lt;/div&gt;</summary>
		<author><name>Rootadminacc</name></author>
	</entry>
</feed>