Useful Unix Console Commands

by | Jul 14, 2015 | Important | 0 comments

Apache

v0.17061601 | Ubuntu 14.04

Apache Password Protect

Apache Restart

Linux Password Recovery.

1) Reboot the machine holding “SHIFT” on the bios screen and enter the recover mode.

2) Remount the “/” drive as writable.

3) Set the password for the username..

efoufhiushfsiuefh

1) Reboot the machine holding “SHIFT” on the bios screen and enter the recover mode.

2) Remount the “/” drive as writable.

3) Set the password for the username..

File Commands

View the End of a Log file, Continually

Control the Number of Lines Outputted

View the Ends of Multiple Log files

HAProxy v1.6

0.17061501

HAProxy-HTTPS-Config_17061501.txt
HAProxy-HTTPS-MultiDomain-Config_17061501.txt

Create an SSL Cert for HAProxy

Create a PEM file from SSL Cert

This is a collection commonly used Unix commands.

Empty Log Files

File Transfer

Complete Directory Transfer

Compress & Decompress a File

Recursively Give Directories 755 Permissions

Recursively Give Files 644 Permissions

Listing USB Devices (Ardunio)

Listing Files

Find Files by Name

Find Files by Extention

Drive Summary Commands

DF Free Space on the Filesystem.


Example:
Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 148Gi 120Gi 28Gi 81% /
devfs 198Ki 198Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home

Discus Free Space on the Filesystem.

DU Space used by Folders under Target Path


Example:
9.8M /var/backups
417M /var/cache
4.0K /var/crash
1.8G /var/lib
4.0K /var/local
0 /var/lock
57M /var/log
4.0K /var/mail
4.0K /var/opt
0 /var/run
9.4M /var/spool
4.0K /var/tmp
88K /var/www

Empty Large Mail System

Empty Over Sized Root Mail Dir

Log Rotate and Log File Commands

Empty a Log File

Log Rotate logrotate.conf Log Size Limits


minsize 100M
Log files are rotated when they grow bigger than size bytes,
but not before the additionally specified time interval (daily,
weekly, monthly, or yearly). The related size option is simi-
lar except that it is mutually exclusive with the time interval
options, and it causes log files to be rotated without regard
for the last rotation time. When minsize is used, both the
size and timestamp of a log file are considered.

size 100M
Log files are rotated only if they grow bigger then size bytes.
If size is followed by k, the size is assumed to be in kilo-
bytes. If the M is used, the size is in megabytes, and if G is
used, the size is in gigabytes. So size 100, size 100k, size
100M and size 100G are all valid.

maxsize 250M
Log files are rotated when they grow bigger than size bytes even before
the additionally specified time interval (daily, weekly, monthly,
or yearly). The related size option is similar except that it
is mutually exclusive with the time interval options, and it causes
log files to be rotated without regard for the last rotation time.
When maxsize is used, both the size and timestamp of a log file are
considered.

OS Commands

Unix OS Version

Restart

Shutdown

Find Service

Find, Partition and Mount a New Drive

Remove Drive, Partition

PHP Commands

PHP Version and Info

Bash Script Executable by PHP

PHP Location

Globally Install Composer (Ubuntu 14.04)

PHP Clear Cache From Console


Allow or Block DNS Record Based Access With CSF Firewall, Good for WordPress.

Composer Commands

Install Git Repo as a Dependency in Composer

GIT Commands

Basic GIT

GIT Setup

Process Commands

Query a Process’s Status and Current Task

Kill Process By Name

Show Process ID Attached to Port

Kill Process Attached to Port

List Running Process by Memory Usage

TOP output to console for other apps to use.

TOP output to file.

A better version of Top, Htop

Init.d Prevent Auto Start

Mail Commands

Postfix for Send Externally (Don’t forget)

Mail Install

Mail Test

Mail Via MPack

Mail Via Sendgrid and CURL

Centos Commands

Centos Shutdown

Centos Restart/Clear Cache Apache

MySQL Commands

MySQL Login

Dump Database to File

Dump Database Schema to File

Import to File to Database

OPCache Config

Production

User Commands

Create User Home DIR

Add a User to an Existing Group

Change User Password

Change User Terminal

Add user to Sudoers

Switch User

Delete User

Apt-Get Commands

Apt-Get Update Repos

Apt-Get Install Package

Apt-Get Upgrade Check Only

Apt-Get Search for Something.

Nmap Commands

Print Status of Port 80 for the IP Range

Example Output :
Host: xxx.xxx.xxx.228 () Ports: 80/open/tcp//http//mini_httpd 1.17beta1 26may2002/
Host: xxx.xxx.xxx.229 () Status: Up
Host: xxx.xxx.xxx.229 () Ports: 80/filtered/tcp//http///
Host: xxx.xxx.xxx.230 () Status: Up

Screen Commands

Always use screen when with the console. Multitask and prevent connection interuptions.

Multitasking Console Controls

Key Shortcuts

CTRL + A + C, Create a new session.
CTRL + A + N, Next session.
CTRL + A + P, Previous session.
CTRL + A + D, Detatch session (Exit but will remain open).
CTRL + A + K, Kill the session.

Serial monitor (USB Device)

Telnet/Pentest Commands

Telnet Connect HTTP(80)

HEAD Only

GET HTTP/1.0

Example Output :HTTP/1.1 200 OK
Server: nginx
Date: Tue, 04 Oct 2016 11:31:45 GMT
Content-Type: application/json
Content-Length: 31
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

{
"origin": "31.24.217.94"
}
Connection closed by foreign host.

Parse and Mongo Commands

Parse Server Start

Mongo Admin Start

Mongo Start

Update, install and start

CURL Commands

API Console command Examples

OpenWrt Commands

OPKG Basics

opkg Collected errors: * parse_from_stream_nomalloc: Missing new line character at end of file! FIX

PIP Install

Maintenance Snippets


Time Sync Server Addresses – Server Listing Link


Dirt Cleanup Script