Linux Commands

This is a list of Linux commands I find very useful. A collection for my own use. No guidance provided.

mount -t iso9660 /dev/sdc /mnt/cdrom

gpg –gen-key  (will be saved under .gnupg/)

nmap -sT -O localhost

netstat -a

lsof -i

last

lastb

vi /etc/nologin

find / -perm -4000 | xargs ls -ld

find / -perm -2000 | xargs ls -ld

 

107 sudo yum install wget
108 wget
109 yum search zip
110 sudo yum install zip unzip
111 yum check-update
112 sudo yum update openssl
113 sudo yum info nano
114 sudo yum list python
115 sudo yum list gcc
116 sudo search python
117 sudo yum search python
118 yum grouplist
119 yum groupinfo “Basic Web Server”
120 sudo yum groupinstall “Basic Web Server”

 

 

128 ls -Z /etc/passwd
129 ps ax -Z
130 h
131 history
132 sestatus
133 setenforce 0
134 sudo setenforce 0
135 sestatus
136 vi /etc/sysconfig/selinux
137 seatatus

 

[abasu@centosvm ~]$ firewall-cmd –get-zones
work drop internal external trusted home dmz public block
[abasu@centosvm ~]$ sudo !!
sudo firewall-cmd –get-zones
work drop internal external trusted home dmz public block
[abasu@centosvm ~]$ sudo firewall-cmd –get-active-zone
public
interfaces: enp0s3
[abasu@centosvm ~]$ sudo firewall-cmd –zone=public –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
[abasu@centosvm ~]$ sudo firewall-cmd –zone=public –add-port=80/tcp –permanent
success

141 sudo firewall-cmd –get-zones
142 sudo firewall-cmd –get-active-zone
143 sudo firewall-cmd –zone=public –list-all
144 sudo firewall-cmd –zone=public –add-port=80/tcp –permanent
145 sudo service firewalld restart
146 sudo firewall-cmd –zone=public –list-all
147 sudo firewall-cmd –zone=public –remove-port=80/tcp –permanent

149 sudo firewall-cmd –zone=public –add-service=http –permanent

sudo aureport

 

160 sudo yum install elinks
161 elinks localhost
162 elinks google.com
163 service httpd status
164 service httpd start
165 service httpd status
166 service httpd restart
167 service httpd status
168 service firewalld start
169 vi /etc/httpd/conf/httpd.conf
170 ls -Z
171 sudo chcon -r -t user_home_t .
172 sudo aureport –avc
173 sudo aureport
174 sudo yum install samba-client
175 sudo yum install samba
176 sudo vi /etc/samba/smb.conf
177 sudo testperm
178 sudo smbpasswd -a abasu
179 sudo service smb start
180 sudo firewall-cmd –zone=public –add-service=samba –permanent
181 service firewalld restart

 

1982 systemd-analyze
1983 systemd-analyze blame
1986 systemd-analyze plot > ~/Desktop/startup.svg

 

2003 service –status-all
2006 systemctl list-unit-files

 

2014 tcpdump -w capturefile.cap
2015 tcpdump -r capturefile.cap dst port 80

/etc/profile –> /.bash_profile –> .bashrc

source .bashrc  is same as the dot command . .bashrc

create a swapfile:

dd if=/dev/zero of=/newswapfile bs=1024 count=1048576

The command creates a swap file named “newswapfile.” The input file “/dev/zero” is a special Linux file that provides null characters. The newly created swap file is 1 GB in size.

  • mkswap /dev/hdb1
  • swapon /dev/hdb1
  • mkswap /newswapfile
  • swapon/newswapfile

 

 

 

  • xclock
  • xclock -update 1 -geom 500×500-200-200
  • xcalc
  • xwininfo
  • xdpyinfo
  • xhost +
  • orca

 

 

  • useradd -m -d /home/pat pat   (m=make home directory)
  • sudo useradd -m -d /home/jordan -u 2000 -g 100 -s /bin/bash jordan
  • sudo usermod -l mordon -u 9000 -g 115 -G 116 -s /bin/csh jordan
  • sudo userdel -r jordan
  • getent passwd abasu
  • getent group abasu
  • vi /etc/nsswitch.conf 

declare – show all shell functions

HISTCONTROL=erasedups
HISTFILE=/home/abasu/.bash_history
HISTFILESIZE=2000
HISTSIZE=1000

Vi –

  • set ic
  • set hls is

man -k password == appropos password

ports that a linux accepts can be found using vi /etc/services

for open ports in a system, we can user netstat

ls > dirlist 2>&1

gpg --gen-key gpg --export -a

ulimit -a

 

  • systemctl – Centos system info
  • hostname
  • uname -r – Kernel revision
  • uname -a
  • uptime
  • uptime -p
  • dmesg
  • dmesh -h
  • free -m (memory in megabytes)
  • shutdown -h -t now
  • telinit
  • route add default gw 198.168.1.0
  • expand
  • renice 19 9999 (priority set to lowest possible value)
  • mkisofs
  • cdrecord
  • growisofs
  • fdisk -n (create a new partition)
  • killall processname
  • splashimage (grub)
  • SUID files are set to run as a root. Security Risk!
  • learn about /etc/skel

User info

  • whoami
  • logname
  • who -H
  • w
  • id
  • groups
  • lastlog
  • last
  • last -F
  • sudo lastb  (for bad logins only)

Time/date

  • timedatectl
  • timedatectl list-timezones
  • timedatectl list-timezones | grep America
  • timedatectl set-timezone America/Vancouver
  • timedatectl set-time 23:40:59
  • timedatectl set-time 2019-12-22
  • timedatectl set-time ‘2019-12-22 23:40:59’
  • timedatectl set-ntp true; sudo systemctl restart sysmd-timedated
  • localectl
  • localectl list-locales
  • localectl list-locales | grep ^en
  • localectl set-locate LANG=en_US.utf8
  • localectl list-keymaps | grep ^us
  • localectl set-keymap us
  • date
  • date –utc
  • date +”%h %d %Y”
  • date +”%s”
  • date –date=’@1481192019′
  • date –date ‘+10 days’
  • date –date ‘next thursday’
  • cal -3
  • cal 1752

Hardware info (IRQ, DMA, and I/O information):

  • sudo dmidecode
  • sudo dmicedode –type bios
  • sudo dmidecode –type system
  • sudo dmidecode –type baseboard
  • cat /proc/cpuinfo
  • lscpu
  • lsblk      – for partitions
  • lsblk -f (coolest command to look for partitions in linux)
  • sudo fdisk -l
  • cat /proc/meminfo
  • Older IDE CD-ROMS could be a problem.
    8-bit NIC are PIO bound – problem hardware.Resource conflicts:
    = DMA
    = IRQ
    = I/OFind hardware conflicts:
    ================
    review /proc – directories and files that are a representation of the running kernel
    /proc/ioports
    /proc/dma
    /proc/interrupts
    /proc/usb
    /proc/pcilsmod – show loaded modules an dependencies.
    lapci – PCI bus information.
    lsscsi – SCSI drivers
    lsdev – deviced recognized by the system
    lsraid – RAID device information.
    lsusb – usb information.

Partitioning:

  • PIBS – Performance, Integrity, Backup and Security.
  • Move /home directory and /swap directory in separate partitions.
  • Separate public folders from system folders.
  • user tar and dd for backing up partitions.
  • 4 primary partitions / 3 primary and 1 extended partitions.
  • Note: boot files must be on a primary extension.
  • Cylinder boundary – 1024!
  • Do not install Linux on a large hard disk. recommended boot partition size is 200 MB.
  • fdisk  /dev/sda (p to print partition table)
  • 82 is for swap partition!
  • cfdisk – curser based program for disk partitioning.

Booting:

  • Bootloader is either at the MBR or at the first sector of the Linux partition.
  • LILO – the Linux Loader
    • /sbin/lilo –> /etc/lilo.conf
    • lolo.conf is a two part file.
    • Crtl+X tp get into a LILO: or boot: screen.
    • default runlevel at /etc/inittab (in old systems)
    • on the BOOT: or LILO: menu type linux 1 to enter into a single user more, or linux 3 to enter into text mode.
    • Always re-run LILO (/sbin/lilo) after a kernel update, changing disk size, changing partition size or moving /boot directory.

Messages

  • journalctl
  • tail -f

File Compression

  • gzip services-file
  • gunzip services-file.gz
  • bzip2 services-file
  • bunzip2 services-file.bz2
  • xz services-file
  • unxz services-file.xz
  • zip services-file.zip services-file
  • unzip services.zip

Environment Variables

  • env
  • printenv
  • set

Runlevel

  • who -r
  • runlevel

truncate -s 1MB file1

  • find . -name “basu” -type d
  • find . -name “basu” -type f
  • find . -name “basu” -type l
  • find . -name “basu” -type c
  • find . -size +10M