1. Find out Ubuntu version using Command Line

cat /etc/issue OR cat /etc/issue.net OR lsb_release -a

2. Find out Linux Kernel Version & Ubuntu Version
  1. Kernel Version: uname -a
  2. Ubuntu Version: lsb_release -a
3. List All users

cat /etc/passwd | cut -d: -f1

4. List all groups

cat /etc/group |cut -d: -f1

5. Changing Folder/File permission,group and ownership
  1. change the owner with chown, e.g. chown guillermooo
  2. change the group with chgrp, e.g. chgrp root
  3. change the rights with chmod, e.g. chmod u+w filename.ext (Adds writing permission for the owner of the file filename.ext)
6. To Log into MySQL as root

sudo mysql -h localhost -u root -p

  1. mysql> show databases;
  2. mysql> show tables;
  3. mysql> use database_name;

REF: http://www.pantz.org/software/mysql/mysqlcommands.html

7. Restart Apache

sudo service apache2 restart OR sudo /etc/init.d/apache2 restart

8. Change Admin Password (passwd)

Change Admin Password for user jsmith: sudo passwd jsmith

9. Add User Account

sudo adduser username

10. Delete User Account

sudo deluser username

11. Installing PHP5

sudo apt-get install php5 libapache2-mod-php5

  1. Running PHP5 scripts from command line: sudo apt-get install php5-cli
  2. Execute PHP5 scripts without installing PHP5 Apache module: sudo apt-get install php5-cgi
12. Installing PHP5-MYSQL (To use MySQL with PHP5)

sudo apt-get install php5-mysql


sudo apt-get install mysql-server


sudo netstat -tap | grep mysql

15. Restart MYSQL

sudo service mysql restart


sudo dpkg-reconfigure mysql-server-5.1


mysql -u root -p

18. Compressing & Compressing a gzip file
  1. gzip filename.txt - Compressing
  2. gunzip filename.txt.gz - Uncompressing

REF: http://www.debianadmin.com/create-and-extract-bz2-and-gz-files.html

REF: http://www.cyberciti.biz/faq/howto-compress-expand-gz-files/

19. How to mount a Flash Drive on a server
  1. ~$ sudo mkdir /mnt/usb --- CREATE A FOLDER
  2. ~$ sudo mount /dev/sdb1 /mnt/usb/ --- MOUNT THE DRIVE INTO THE FOLDER YOU CREATED

REF: http://linuxservertutorials.blogspot.com/2008/11/ubuntu-server-mount-usb-drive.html

20. How to unmount a Flash Drive on a server

sudo umount /dev/sdb1

21. How to update php.ini on apache


22. How to backup a MySql Database into a folder in a .sql.gz compressed file

mysqldump --opt -u root -p your_current_existing_database | gzip > database_backup_date.sql.gz

23. Detecting USB hard drive

sudo fdisk -l

REF: http://linuxconfig.org/Howto_mount_USB_drive_in_Linux

24. How to remove a directory

rm -r directory

25. How to change mysql Database User's password

mysql> update user set password=PASSWORD("NEW-PASSWORD-HERE") where User='tom';

26. How to see all mounted drives

mount -l OR df -hT

27. Find Out What Ports Are Listening / Open On My Linux & FreeBSD Server
  1. lsof -i - To display the list of open ports
  2. netstat -vaun - To display only open UDP ports

REF: http://www.cyberciti.biz/faq/how-do-i-find-out-what-ports-are-listeningopen-on-my-linuxfreebsd-server

28. How to kill a process

kill -9 3216 - Where 3216 is Process ID

29. How to view running process


REF: http://www.cyberciti.biz/faq/show-all-running-processes-in-linux

ps -ef | grep wget | grep -v grep

REF: http://superuser.com/questions/490601/how-to-know-if-file-is-already-finished-downloading-in-linux-command-line

30. How to setup date time stamp (Ubuntu)

sudo date -s "21 Feb 2013 01:12:00"

31. How to list cron jobs running

crontab -l OR for user root is: sudo crontab -l

EDITOR="nano" crontab -e - Edit cron tab

32. How to reboot server

sudo reboot

33. How to install MAMP
  • sudo apt-get install mysql-server mysql-client
  • sudo apt-get install apache2
  • sudo apt-get install php5 libapache2-mod-php5
  • sudo /etc/init.d/apache2 restart

REF: http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-ubuntu-11.04-lamp

34. How to change a file's owner and group in Linux - 1.0
  1. chown -R username somedir

REF: http://www.tuxfiles.org/linuxhelp/fileowner.html

35. How to point a domain to its www/ folder in a physical disc on apache
  1. Edit default or main folder [sudo nano /etc/apache2/sites-available/default]
  2. Add Virtual Record at the bottom of the file pointing the domain to the folder

            ServerName domainname.co.za
            ServerAlias www.domainname.co.za
            ServerAdmin youremail@domainname.co.za
            DocumentRoot /var/www/domainname.co.za/html/

            <Directory /var/www/domainname.co.za/html/>
                    Options Indexes FollowSymLinks MultiViews +Includes
                    AllowOverride None
                    Order allow,deny
                    Allow from all

  3. Save the file and go to your sites-enable folder and cat the default file that was initially linked with [ln -s ../sites-available/default]
  4. if new virtual host script from b) above appears, then restart apache server [sudo service apache2 restart]
  5. Go to your browser and type www.domainname.co.za

Appendix: A

Appendix: B

Appendix: C

Appendix: D

Appendix: E (MySQL Command)

List of all MySQL commands:

Note that all text commands must be first on line and end with ';'

?                   (\?)    Synonym for `help'.
clear            (\c)    Clear the current input statement.
connect        (\r)    Reconnect to the server. Optional arguments are db and host.
delimiter      (\d)    Set statement delimiter.
edit               (\e)    Edit command with $EDITOR.
ego               (\G)    Send command to mysql server, display result vertically.
exit                 (\q)    Exit mysql. Same as quit.
go                  (\g)    Send command to mysql server.
help               (\h)    Display this help.
nopager        (\n)    Disable pager, print to stdout.
notee              (\t)    Don't write into outfile.
pager              (\P)    Set PAGER [to_pager]. Print the query results via PAGER.
print                (\p)    Print current command.
prompt            (\R)    Change your mysql prompt.
quit                   (\q)    Quit mysql.
rehash            (\#)    Rebuild completion hash.
source            (\.)    Execute an SQL script file. Takes a file name as an argument.
status              (\s)    Get status information from the server.
system            (\!)    Execute a system shell command.
tee                    (\T)    Set outfile [to_outfile]. Append everything into given outfile.
use                  (\u)    Use another database. Takes database name as argument.
charset            (\C)    Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings         (\W)    Show warnings after every statement.
nowarning       (\w)    Don't show warnings after every statement.