Deployment Recipes Part 9 – Python, Web2py, Apache and Debian – Linux commands

Let’s look at a few handy linux commands. These would aid you for doing day to day tasks successfully on your linux box. A user must have knowledge of all these commands if he is the sole user operating and managing the entire functionality. Just to let you know I am old-school and I prefer to use nano as my preferred editor of choice. It is simple and one can remember all its commands on the go. We will come to it in another article though.

Linux Commands

rm *  — removes files all files

rm -rf <subdir-name> — deletes directory in unix/linux

rm –rf * removes all directories recursively

rm -rf /home/www-data/web2py/applications/Target/sessions/{*,.*}  Removes all files in directory (including hidden files and subdirectories). Here sessions in the application

zip –r zipfilename  directory –x .*   — Zip a directory and all its files

Examples: (Here _prod is the file name that we want without .zip followed by folder name)

zip -r Aavia9_HMS_prod Aavia9_HMS -x.*

zip -r artpic_prod artpic -x.*

zip -r Target_prod Target -x.*

zip archivename.zip filename1 filename2 filename3

To unzip

unzip filename.zip

Change folder permissions for any folder

sudo chmod -R ugo+rw /DATA/SHARE
More permission changes for example for application (artpic)
sudo chmod –R ugo+rw sessions 
sudo chmod –R ugo+rw static  [ for uploading user or other images] 
sudo chmod –R ugo+rw display_images [in static for storing resized images]
sudo chmod –R ugo+rw errors [ So that the errors get written] 
sudo chmod –R ugo+rw databases [This needs to be done so if there are any dbchanges, they will get reflected automatically ]
chmod ugo+rwx  languages [Read Write Execute]
Permission changes in static folder
sudo chmod -R ugo+rw user_uploads
sudo chmod -R ugo+rw comp_images
sudo chmod -R ugo+rw images
sudo chmod -R ugo+rw news_images
sudo chmod -R ugo+rw prof_pix
sudo chmod -R ugo+rw review_images
sudo chmod -R ugo+rw blog_images
OR - 
chmod 775 [Folder destination]
chmod 775 /home/www-data/web2py/applications/artpic/uploads
 

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all).

  • chmod ugo+rwx foldername to give read, write, and execute to everyone.
  • chmod a=r foldername to give only read permission for everyone.
 

Set files in read-only mode

The syntax is:
## use only for files ##
chmod 0444 /var/www/html/*
chmod 0444 /var/www/html/*.php

Set directories in read-only mode

TO set directories in read-only mode, enter:
## use only for dirs ##
chmod 0444 /var/www/html/
chmod 0444 /path/to/your/dir/
# ***************************************************************************
# Say webserver user/group is www-data, and file-owned by ftp-data user/group
# ***************************************************************************
# All files/dirs are read-only
chmod -R 0444 /var/www/html/
# All files/dir owned by ftp-data
chown -R ftp-data:ftp-data /var/www/html/
# All directories and sub-dirs has 0445 permission (so that webserver user www-data can read our files)
find /var/www/html/ -type d -print0 | xargs -0 -I {} chmod 0445 "{}"

Also, in db.py we should have a line like below to create new tables etc-
 db = DAL('postgres://postgres:krishna@66.155.41.116:5432/pixy', pool_size=50, migrate_enabled=True, check_reserved=['all'] )

ls -la – list contents with details

ls -lt – list contents with time. Sorted by time

List all users

awk -F: ‘/\/home/ {printf “%s:%s\n”,$1,$3}’ /etc/passwd

or

awk -F: ‘{printf “%s:%s\n”,$1,$3}’ /etc/passwd

Delete users

userdel user’s username

Optional: You can also delete that user’s home directory and mail spool by using the -rflag with the command: 

userdel -r user’s username

list proceses

ps –aux

kill process

kill -9 <pid>      à  This is SIGKILL

kill <pid>        à This is SIGTERM

Diskspace commands

  1. df command – Shows the amount of disk space used and available on Linux file systems.
  2. du command – Display the amount of disk space used by the specified files and for each subdirectory.
  3. btrfs fi df /device/ – Show disk space usage information for a btrfs based mount point/file system.

Open the terminal and type the following command to check disk space.

  1. The basic syntax for df is:
    df [options] [devices]
    Type:
  2. df
  3. df –H

Specific file system output ..

$ df /dev/sda
$ df -h /dev/sdc1
$ df /data/

RAM checking commands

Display the amount of memory in bytes:
free -b

Show the amount of memory in mebibytes:
free -m

Get the amount of memory in megabytes:
free --mega

Find the amount of memory in gibibyte:
free -g

Want to see the amount of memory in gigabytes? Pass --giga option as follows:
free --giga

Pass the -t option to get totals info about memory:
free --giga –t

cat /proc/meminfo

Working with Bash

Add line in bash to make python 2.7 your default if it is not –

alias python=’/usr/local/bin/python2.7′

cd \

cd root

edit bash

nano ~/.bashrc

Apply the bash –

source ~/.bashrc

or use

exec bash or . .bashrc

Dhakate Rahul

Dhakate Rahul

Leave a Reply

Your email address will not be published. Required fields are marked *