Linux Commands

Quick Reference


Documentation

view program manual:        man {program}
view program help:            {program} --help (or -h may work)

General

List recently used commands:        history
Clear terminal window:                   clear
run as super user:                            sudo
load desktop from terminal:            startx
run gui program as super user:       gksu
shutdown (halt or restart):               sudo shutdown now [-h] [-r]

Software versions

kernel/os/platform:                         uname -a
distribution:                                     lsb_release -a
package:                                          dpkg --list (package) e.g. dpkg --list python
list all packages to file:                    dpkg --get-selections > /home/steve/myPackages.csv
...or using apt:                                apt list --installed
program version:                            {program name} --version or -v

List files, harwdare, environment

files in current dir:           ls [-l]    inc hidden files [-a]
USB devices:                  lsusb
PCI:                                 lspci
open files:                       lsof
block devices:                lsblk
hardware:                      lshw
modules:                         lsmod
environment vars:            env
cpu:                                cat /proc/cpuinfo

Memory, drives, volume, file system

disk usage:                       df [-h] [-hT]
RAM:                                free [-h]
RAM:                                cat /proc/meminfo
mount filesystems:            mount / umount
Force run fsck next boot:   in root dir: sudo mkdir forcefsck

file, folder, drive operations

change directory:            cd
make/remove:                  mkdir/rmdir
view file contents:            cat {path+file}
compare file:                    diff
copy file:                           cp
remove file:                      rm {file}
move or rename file:        mv /file/path/oldName /file/path/newName
find file:                             find
find text in files:               grep {e.g.    grep -rnw '/home/pi/' -e 'follow the money'}
find program files:            where is {program}
create program alias:        alias {program name only}
File/image copy:               dd or dcfldd
remove old .debs:             sudo apt-get clean

change mode (r/w/exe):    chmod {e.g. chmod u=rw,g=rw,o=r /home/me/myFile}
execute permission:         chmod +x {filename}

Process & Services

view current processes:        top
view user processess:           top -u {user}
get process id (pid):              pgrep {process name}
send signal to process:         kill {pid}
list services:                          service --status-all   ...where "+" = running, "-" = stopped 
run as user (from root):       runuser -l {user} -c {command}      

Network and web

check interface details:         ifconfig
bring up/take down:              ifup/ifdown
display/change wireless:       iw list
config wireless:                    iwconfig
detailed:                                iwlist
port scanner:                        nmap {ip}
find network devices:            e.g. nmap 192.168.0.0/24
net statistics:                        netstat -a
active tcp/udp:                      netstat -atu    (or -atuc for continuous)
inspect tables:                       iptables --list
my traceroute:                     mtr {ip}
echo request:                       ping {ip}
generate WPA PSK:              wpa_passphrase {ssid} {passphrase}
get a web page/file:              wget
remote ssh access:                ssh {user}@{ip}    e.g. ssh pi@192.168.0.99
exit remote ssh session:       exit

Samba; test config file:        testparm
Samba; display shares:        smbtree

Boot time analysis

boot stats/info:                      systemd-analyze
list, longest first:                    systemd-analyze blame
time critical chain:                 systemd-analyze critical-chain


Full reference:      http://ss64.com/bash/


Raspbian specific

Raspberry Pi config:             raspi-config
update Pi firmware:              rpi-update
Pi software ref (date):           cat /boot/issue.txt
update software:                   sudo apt update && apt upgrade
copy Pi image from SD:       dd if=/dev/{sd id} of=/home/{user}/{img name} bs=1M
    e.g.   sudo dd if=/dev/mmcblk0 of=/home/steve/Pi_Images/blissflixx.img bs=1M

cpu, serNo, revision:            cat /proc/meminfo
RAM for cpu:                        vcgencmd get_mem arm
RAM for gpu:                        vcgencmd get_mem gpu

Change dir to root dir;            sudo cd /root will not work, so use:-
    sudo -i
    cd /root


to-do
redirection, pipe

No comments:

Post a Comment