The most common Linux commands that I use and forget.
* Primarily using Ubuntu from AWS images.
Directory Structure
http://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/
Commands
View current sessions
who
apt-get
apt-get update
sudo apt-get update
sudo apt-get autoclean
remove files that can't be downloaded anymore
sudo apt-get autoremove
remove unused dependencies
adduser
reboot
sudo passwd
change root password
su
login as root
sudo service SERVICENAME status/start/stop/restart
copy directory and contents
cp -r dirSource dirDestination
create an empty file
touch filename.txt
get ip address
/sbin/ifconfig
hostname -I
sudo pkill -u username
delete non-empty directory
rm -rf myDirectory
change file/directory owner
sudo chown username:group directory
Recursively
sudo chown -R username:group directory
Run a Shell Script
sh myshellscript.sh
or
bash myshellscript.sh
Find a file
by name
find -name "filename"
by name (ignore case)
find -iname "filename"
List Top Processes
top
List All Users
cat /etc/passwd
Add User
adduser new_username
Apache
edit config file
pico /etc/apache2/apache2.conf
install apache
sudo apt-get install apache2
restart apache
sudo service apache2 restart
error log
/var/log/apache2/
sites available
etc/apache2/sites-available
disable directory listing
remove Indexes from apache2.conf/httpd.conf
ex: Options Includes Indexes FollowSymLinks MultiViews
Apache rewrite_module
check if it is installed
apache2ctl -M
enabled rewrite_module
a2enmod rewrite
restart apache
service apache2 restart
allow rewrites in your apache config file
<Directory /var/www>
AllOveride All
apachectl start
apachectl stop
apachectl restart
/sbin/service httpd restart
apachectl status
MySQL
sudo apt-get install mysql-client-core-5.6
sudo apt-get install mysql-server
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo service mysql restart
sudo stop mysql
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart
/etc/init.d/mysqld status
Connect to a MySQL Instance
mysql -u <db-username> -p
mysql -u root -p
mysql -h <host> -P <port # optional> -u user -p
mysql -h something1.something2.us-east-1.rds.amazonaws.com -P 3306 -u root -p
Execute a command
select * from mydbname.users;
Close connection
quit
PHP
sudo apt-get install php5
sudo apt-get install php5-gd
sudo apt-get install php5-mysql
sudo apt-get install php5 php5-gd php5-mysql
sudo apt-get install php5-curl
//possible php.ini paths in Ubunutu
/etc/php5/apache2
/etc/php5/cli
find the php.ini file
php -i | grep "Loaded Configuration File"
Git
apt-get install libcurl4-gnutls-dev libexpat1-dev gettext
apt-get install git
Tar/Zip
unzip
apt-get install unzip
unzip MyFile.zip
tar
compress a directory
tar -zcvf newfilename.tar.gz my_directory/
decompress a tar file
tar -zxvf newfilename.tar.gz
Configs
/etc/apache2/conf/httpd.conf
XRDP
sudo apt-get install xrdp
Drupal
wget http://drupal.org/files/projects/drupal-7.28.tar.gz
tar -zxvf drupal-7.28.tar.gz
mv drupal-7.28 /var/www/
cp -r drupal-7.28 drupal01
AWS
root/ec2-user/ubuntu
to login using SSH
MISC
apt-get install wget
wget http://www.example.com/mystuff.zip
ClamAV
apt-get update
apt-get install clamav
Clam UI
apt-get install clamtk
update virus db
freshclam
check all files on the computer, displaying the name of each file
clamscan -r /
check all files on the computer, but only display infected files
clamscan -r -i /
check all files and output FOUND infected files to file
clamscan -r / | grep FOUND >> /avreport.txt
pico /avreport.txt
Cron - cron job functions
crontab -l
crontab -u username -l