/ linux

List of frequently used Linux - Ubuntu console commands

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

  1. Export
mysqldump -u username -p database_name > file_name_to_save.sql
  1. 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

  1. Find any word in multiple files
grep -r word *
  1. Check disk space usage for a particular folder
du -hs /path/to/folder
  1. Check total disk space usage for entire Hard Disk
df -h --total
  1. Check for available and used RAM on logged in machine
free -m

Important File Paths

  1. Apache Logs
/var/log/apache2/error.log
/var/log/apache2/access.log
  1. Apache Configuration
/etc/apache2/
  1. 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

  1. Show scheduled crontab file
crontab -l
  1. Remove current scheduled cronjob
crontab -r
  1. 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
Rohan Daxini

Rohan Daxini

Founder at Kiprosh | Ruby, Elixir, JS & C lover | Life Long Learner | Books | Technology | Mindfulness | Gratitude

Read More