This is an assorted list of Unix commands. These are commands I've found useful in the past that I don't want to forget.
- Filesystem Commands
- Zeroing out a file
- Grep multiple files across multiple directories
- Find files larger than 1000000 bytes
- Find files modified 3 or fewer days ago
- Delete object files and print what's deleted
- Show list of directories and their sizes in kilobytes
- Show how much space a directory is taking up
- Determine what process has a file open
- Monitor a directory for open filehandles. Repeat command every second forever.
- Show space on drives
- Querying file locks max value on HP-UX
- Create a file of a given size
- Delete file by inode
- Search/Replace in a file
- Delete logfiles without an open file handle
- Determine if it is an HDD or SSD (0 means SSD, 1 means HDD)
- Manually formatting and mounting a block device
- Kubernetes Commands
- Vim
- Removing ^M characters at end of lines in vi
- Comment a block of text in vim
- Copy column in vim
- Opening a new file in vim
- List buffers
- Switch to a different buffer
- Open file in new tab
- Multiple Windows in Vim
- Enable mouse in vim (lets you resize split windows)
- Set tab to 4 spaces
- Enable tab character
- Miscellaneous
- Sending a text file via e-mail
- Show how many rows and columns your display is set to
- System logs are located at:
- List all files in tar archive
- Tar a directory
- See which packages are assigned where in a failover
- Getting a list of installed packages
- Getting list of products from a depot file (HP-UX)
- Installing product from a depot (HP-UX)
- Converting unix epoch seconds to exec serial date format
- Print contents of a file in reverse order
- Get checksum of a file
- Search contents of all files in a directory for a string
- Grep string, including 10 lines before and after
- Repeat a command every 5 seconds
- Show OS limits for a process (Linux only)
- Print file in binary format
- Print file in hexadecimal format
- Print file in octal format
- See all environment variables for a process running on Linux:
- Getting Centrify info on a user
- Check if a server is a physical or virtual
- List kernel parameters
- SSH to box without password
- Getting process list with full arguments an HP-UX
- Syncronize panes in Tmux
- Bind key for synchronize-panes in Tmux
- Switching version of a tool on Redhat
- Color diff in two columns
- Networking
- Compiler Stuff
- RPM
- RPM Commands
- Check for a package in linux
- Info on a package
- Info on a package that is not installed
- List files in a package
- Which rpm owns a particular file
- List files in an rpm archive
- Install local rpm file
- List most recently installed rpms
- List dependencies of an rpm
- List Repos
- Find out what RPM provides file
- Get info on a package
- Install a local rpm via yum
- Make yum see the lastest packages
- Run Puppet
- Mock Commands
- FPM Commands
- RPM Commands
- Postgres
- Services
- Java Keytool
- List Certs in a Keystore
- Add Cert to Keystore
- Delete Cert from Keystore
- Download Cert from Wedsite
- Creating a self-signed cert
- Creating a pfx file
- Export the private key from PFX
- Convert PFX to PEM file
- Remove passphrase from private key
- Convert PFX to key and cert file
- Validating the key and cert (md5 should be the same)
- Docker
- Mac
- Git
cat /dev/null > <filename>
find . -type f -print | xargs fgrep -i -l "text_to_grep_for"
ll -R <directoryname> | awk '{if ($5 > 1000000) print $5 "\t" $9}'
find . -xdev -size +1000000c
find . -xdev -size +1000000c -exec ls -al {} \; | sort -k 5n
find . -xdev -size +1000000c -exec ls -al {} \; | sort -r +4n
find . -xdev -type f -mtime 3 -exec ls -al {} \; | sort -rk +5n
find . -xdev -type f -mtime 3 -exec ls -al {} \; | sort -r +4n
find . -name "*.o" -exec echo 'rm -f {}' \; -exec rm -f {} \;
du -xhk | sort -k 1n
du -xk | sort +0n
du -shx
Show how much space subdirectories are taking up:
du -shx $(ls -d */)
fuser -u /path/to/file
psg <pid>
while true; do lsof +d /tmp; sleep 1; done
df -k
kcusage | grep nflocks
dd if=/dev/zero of=don.out bs=1024 count=10240
ls -li
find . inum <inode number> -exec rm -l {} \;
sed -ri 's/(test1|test2)/value3/g' app.cfg
find /tmp -type f -exec bash -c "fuser {} || rm {}" \;
cat /sys/block/sdc/queue/rotational
lsblk
file -s /dev/xvdb
mkfs -t ext4 /dev/xvdb
mkdir /mnt/jenkins
mount /dev/xvdb /mnt/jenkins
ll /mnt/jenkins
df -h
az aks get-credentials --name <resource name> -g <resource group>
az aks get-credentials --name <resource name> -g <resource group> --admin
kubectl config -get-contexts
kubectl get pods --all-namespaces
kubectl get pods -l app=nginx-ingress --all-namespaces
kubectl get pods -l app=nginx-ingress -o wide --namespace=kube-system
kubectl describe pods <pod name> --namespace=kube-system
kubectl get services --all-namespaces
kubectl get svc <service name> --namespace=kube-system
kubectl describe services --all-namespaces
kubectl describe svc <service name> --namespace=kube-system
kubectl describe deployment <deployment name>
kubectl get configmaps
kubectl get configmaps --namespace=kube-system
kubectl get configmaps --namespace=kube-system -o yaml
kubectl exec -it <pod name> -- /bin/bash
kubectl exec -it <pod name>-n <namespace> -- /bin/bash
kubectl get ep
kubectl get secrets --all-namespaces
kubectl get ingress
kubectl get events --all-namespaces
kubectl logs <pod name> --namespace <namespace name>
kubectl logs -f <pod name>
kubectl autoscale deployment <deployment name> --cpu-percent=50 --min=1 --max=10
kubectl get hpa
kubectl describe hpa
kubectl scale --replicas =3 <deployment name> -n <namespace name>
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out don_test.crt -keyout don_test.key
kubectl create secret tls <secret name> --cert=don_test.crt --key=don_test.key
az network public-ip create -g <resource group name> -n <namespace name> --alocation-method static --reverse-fqdn example.westus.cloudapp.azure.com --dns-name example
helm install <chart name> --namespace <namspace name> --set controller.service.loadBalancerIP="<insert ip here>" --set controller.replicaCount=2
kubectl apply -f <yaml filename>
Perf |where CounterName == "cpuUsageNaneCores and ObjectName == "K8SContainer"
| where TimeGenerated > ago(1d)
| summarize avg(CounterValue), percentiles(CounterValue, 50, 95) by bin(TimeGenerated, 1h)
KubeEvents | where TimeGenerated > ago(1d)
KubeEvents | where SourceComponent == "cluster-autoscaler"
:%s/^V^M//g
The ^V is a CONTROL-V character and ^M is a CONTROL-M. When you type this, it will look like this:
:%s/^M//g
alternate command:
dos2unix <filename>
- control-V
- <highlight text with cursor> (use arrow keys. Only one column will be highlighted)
- shift-I
- #
- escape
- control-V
- <highlight text with cursor>
- p
:n <filename>
:e <filename>
:ls
:b<buffer number>
:bnext
:bprev
:tabe <filename>
Syntax | Description |
---|---|
:split <filename> | split window and load another file |
vplit <filename> | vertical split |
ctrl-w up arrow | move cursor up a window |
ctrl-w ctrl-w | move cursor to another window (cycle) |
ctrl-w_ | maxmize current window |
ctrl-w= | make all equal size |
10 ctrl-w+ | increase window size by 10 lines |
:hide | close current window |
:only | keep only this window open |
:set mouse=a
set smartindent
set tabstob=4
set shiftwidth=4
set expandtab
set noexpandtab
mailx -s "SUBJECT" email@example.com < file.out
resize
/var/log/messages
/var/adm/syslog
tar -tvf filename.tar
tar -cvf <name>.tar <directoryname>
cmviewcl
/usr/sbin/cluster/utilities/clfindres
Or this command:
/usr/sbin/cluster/clstat
swlist
swlist -l patch
lslpp -L
swlist -d -s <depot filename>
swinstall -s <depot filename>
=A1/86400+(25569-(5/24))
sed -s '1!G;h;$p'
cksum <filename>
grep "string to search" *
grep –B 10 –A 10 string_to_search <filename>
watch -n5 <command>
cat /proc/<PID>/llimits
xxd -b <filename>
hexdump <filename>
od <filename>
xargs -n 1 0 < /proc/<PID>/environ
adinfo -u <user id>
dmidecode -t 1
Output:
"Manufacturer: Vmware, Inc." is a virtual
lparstat -I | grep Type
Output:
Shared-SMT is a virtual
Dedicated-SMT is physical
model
Output:
"ia64 hp server Integrity Virtual Machine" is a virtual
"ia64 hp server rx260" is a physical
systeminfo
Output:
"System Manufacturer: System Manufacturer" is a physical
"System Manufacturer: Vmware, Inc. System Model: VMWare Virtual Platform" is a virtual
/usr/sbin/kmtune -l
kctune
cat /stand/tunes
List details about a particular parameter
kctune -v -q maxuprc
sysctl -a
ssh-keygen -t rsa
ssh-copy-id <userid>@<hostname>
ssh <userid>@<hostname>
/usr/bin/env UNIX95=1 /bin/ps -eo 'state,uid,ppid,args'
:setw synchronize-panes
bind a set-window-option synchronize-panes
scl enable python27 python (opens a python shell)
scl enable python27 bash (opens a new bash shell with python configured)
sdiff -w 230 <file 1> <file 2> | colordiff | less -r
ss
netstat -a | grep LISTEN | grep -v unix
lsof -i :9703
Alternatively, you can run:
netstat -Aan | grep <port number>
rmsock <socket number> tcpcb
fuser -v -n tcp 5432
lsof -l
tcpdump -nn -I eth0 port 5432
sudo tcpdump -nn
netstat -s -t | egrep "trans|select"
telnet localhost 9000
nc -vz localhost 9000
nc -vzu localhost 5514
nm -a <filename>
dump -Tv <filename>
set PATH to "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin"
cmd
cd "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin"
vcvarsall.bat
cd "dir_where_your_binary_is"
dumpbin /all <filename>
objdump -f <filename>
ar x <filename>
ldd <filename>
find . -name "*.sl" .-exec sh -c 'echo lib: $0; nm -a $0 | grep tp_sleep' {} \;
rpm -qa | grep ssh
rpm -qi <package name>
rpm -qip <file name>
rpm -ql <package name>
rpm -qf <filename>
rpm -qpil <filename>
rpm -ivh <filename>
rpm -a --last | head -10
rpm -qR <package name>
yum repolist enabled
yum repolist all
zypper repos
yum whatprovides <filename>
yum info <filename>
yum localinstall <file name>
yum clean expire-cache
puppet agent -t
mock -r epel-6-i386 --init
mock -r epel-6-x86_64 --init
mock -r epel-i386 --shell
mock -r epel-6-x86_64 --shell
mock -r epel-6-i386 --copyin <filename> /
mock -r epel--i386 --copyout <file path> .
mock -r epel-6-i386 --install <rpm packagename>
mock -r epel-6-x86_64 --install <rpm packagename>
fpm -s dir -t deb -n jenkins -v 1.396 --prefix /opt/jenkins -d "sun-java6-jre (> 0)" jenkins.war
fpm -s dir -t deb -n jenkins -v 1.396 --prefix /opt/jenkins -d "sun-java6-jre (> 0)" jenkins.war
psql -l
psql
\c <database name>
\d
service <service name> start
service <service name> stop
service <service name> restart
service <service name> status
systemctl start <service name>
systemctl stop <service name>
systemctl restart <service name>
systemctl status <service name>
SysV Init
chkconfig –list
Systemd
systemctl list-unit-files --type=service
SysV Init
chkconfig <service name> off
chkconfig <service name> on
Systemd
systemctl disable <service name>
systemctl enable<service name>
/usr/java/latest/bin/keytool -keystore /usr/java/latest/jre/lib/security/cacerts --list
/usr/java/latest/bin/keytool -keystore /usr/java/latest/jre/lib/security/cacerts -import -file <path to cert> -alias example.domain.com -storepass PASSWORD -noprompt
/usr/java/latest/bin/keytool -keystore /usr/java/latest/jre/lib/security/cacerts -delete -alias example.domain.com -storepass PASSWORD -noprompt
openssl x609 -in <(openssl s_client -connect example.domain.com:443 -prexit 2>/dev/null)
openssl req -newkey rsa:2048 -nodes -keyout filename-key.pem -509 -days 365 -out filename-cert.pem
openssl pkcs12 -export -out filename.pfx -inkey filename-key.pem -in filename-cert.pem
openssl pkcs12 -export - filename.pfx -nocerts -out filename-key.pem -nodes
opensssl pkcs12 -in filename.pfx -nokeys -out filename-cert.pem
openssl rsa -in filename-key.pem -out filename-key2.pem
openssl pkcs12 -in filename.pfx -clcerts -nokeys -out filename.cer
openssl pkcs12 -in filename.pfx -nocerts -nodes -out filename-encrypted.key
openssl rsa -in filename-encrypted.key -out filename.key
openssl pkcs12 -nokeys -clcerts -in filename.pfx -out filename.cer
openssl x509 -noout -modulus -in filename-cert.pem | openssl md5
openssl rsa -noout -modulus -in filename-key.pem | openssl md5
gpasswd -a <user name> docker
docker run -t -I ubuntu /bin/bash
docker exec -I -it <container name> bash
cat filename.tar | docker import - <image name>
docker inspect <container name>
service docker stop
ip link set dev docker0 down
brctl delbr docker0
iptables -t nat -F POSTROUTING
route -n
systemctl daemon-reload
service docker start
scutil -set ComputerName "<computer name>"
scutil -set HostName "<computer name>"
scutil -set LocalHostName "<computer name>"
dscl "/ActiveDirectory/DOMAIN/fqdn" read /Users/userid
git diff --name-only <commit id> HEAD
git diff --name-only <commit id> HEAD
git log --name-only --since "5 days ago" --until="now" --all
git log --name-status --since "5 days ago" --until="now" --all | grep -E '^[A-Z]\b' | sort -k 2,2 -u
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
cut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
git branch -a --contains <commit>
git whatchanged --all --find-object=<blob id>