Following is an handy list of frequently used Linux (Ubuntu flavour) console commands
Find Files
find . -name '*.cnf' find . -name 'hello.workd'
The dot here represents all files and folders in current path
Mysql DUMP - Import and Export
- Export
mysqldump -u username -p database_name > file_name_to_save.sql
- Import
mysql -u username -p database_name < filename.sql
Install LAMP on Ubuntu
sudo apt-get install tasksel sudo tasksel sudo tasksel install lamp-server
Install Apache2 on Ubuntu
sudo apt-get update sudo apt-get install apache2
The /var/www path is the document root for the apache web apps.
SCP - File copy from one PC to another PC
Syntax - scp source target
Examples scp root@192.168.0.1:/path/to/folder_or_file root@128.0.0.0:/example/folder scp /home/* root@192.168.0.1:/path/to/folder_or_file scp root@192.168.0.1:/path/to/folder_or_file /home/sample_folder/
Other general commands
- Find any word in multiple files
grep -r word *
- Check disk space usage for a particular folder
du -hs /path/to/folder
- Check total disk space usage for entire Hard Disk
df -h --total
- Check for available and used RAM on logged in machine
free -m
Important File Paths
- Apache Logs
/var/log/apache2/error.log /var/log/apache2/access.log
- Apache Configuration
/etc/apache2/
- Apache Restart
Ubuntu ==> /etc/init.d/apache2 restart OR service apache2 restart Debian ==> service httpd start OR service httpd restart OR service httpd stop
MYSQL - Load data using csv or text files
LOAD DATA LOCAL INFILE 'publicities.csv' INTO TABLE publicities CHARACTER SET 'utf8' FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n';
Others
/etc/hostname ==> contains just the name of the machine
/etc/hosts ==> has entries for localhost. Example below 127.0.0.1 localhost.localdomain localhost 127.0.1.1 my-machine
Crontab Commands - "Whenever" gem
- Show scheduled crontab file
crontab -l
- Remove current scheduled cronjob
crontab -r
- Re-kick and reschedule fresh cron jobs (it will read config/schedule.rb file and schedule these jobs)
bundle exec whenever --update-crontab --set environment=production bundle exec whenever --update-crontab --set environment=staging