Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active March 2, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/5eb7652ab98e3d1fc989ac3ff14af312 to your computer and use it in GitHub Desktop.
Save techthoughts2/5eb7652ab98e3d1fc989ac3ff14af312 to your computer and use it in GitHub Desktop.
some linux notes
ssh 10.0.4.3 -l jake
# read the manual pages - kind of like help
man
man cp # read the manual on the cp command
man 2 sync # gets you man page 2
manpath # where are man files located
<<'###ManPageSections'
1 User level commands and applications
2 System calls and kernel error codes
3 Library calls
4 Device drivers and network protocols
5 Standard file formats
6 Games and demonstrations
7 Miscellaneous files and documents
8 System administration commands
9 Obscure kernel specs and interfaces
###ManPageSections
<<'###FindingHelp'
Debian debian.org/doc
Ubuntu help.ubuntu.com
RHEL redhat.com/docs
CentOS wiki.centos.org
FreeBSD freebsd.org/docs.html
###FindingHelp
# determine if binary is already in your search path
which cp # tells you where cp is
# whereis does a more broad search for a binary
whereis cp
# consults pre-compiled index of filesystem to locate filenames
locate signal.h
# system packaging
rpm
rpm -q python # checks if python is installed
rpm -qf /etc/httpd # checks which package file belongs to
dpkg-query -S /etc/apache2 #ubuntu method for finding package file belongs to
rpm -qa | wc -l # number of installed packages
rpm -ql python # shows you all installed files as part of the package
# installing things
sudo apt-get install tcpdump #ubuntu
sudo yum install tcpdump #rhel
# L - location
# o output to file
# s silent
curl -o /tmp/packageName -sL https://packagedownload.com
sudo sh /tmp/packageName
wget http://alink.com
# install updates
yum update kernel -y #auto answer yes to all questions
sudo -i
sudo -i -u username
su # root interactive shell - logs who became root
su -username # become a different user if you know the password
visudo # configure sudoers
visudo -c -f sudoers # validate the sudoers file
cut -d: -f1 /etc/passwd # list users
# boot order
efibootmgr
# o - explictily set boot order
sudo efibootmgr -o 0004,0002 # changing the boot order
#investigate status of systemd
systemctl # default is to list-units
systemctl list-units --type=service
systemctl list-unit-files --type=service
systemctl status -l dbus # checks status of specific unit
sudo systemctl enable dbus # enable a unit
sudo systemctl start dbus # start a unit
systemctl reboot # reboot
systemctl daemon-reload # reloads unit fules and systemd config
sudo systemctl isolate multi-user.target # switch system's current operating mode
systemctl get-default # how is server configured to boot?
sudo systemctl set-default multi-user.target # change boot method
systemctl list-units --type=target # show boot options
sudo systemctl add-wants multi-user.target my.local.service # add dependency
# setting up a new service
# put unit file in /etc/systemd/system
sudo systemctl enable custom.service
# systemd logging
journalctl # all log entries (oldest first)
# shutting down/rebooting
halt # system halt
halt -p # powers down
reboot # reboots
shutdown # warn logged on users - mostly obsolete
# processes
<<'###Signals'
1 HUP Hangup
2 INT Interrupt
3 QUIT Quit
9 KILL Kill NO CATCH
10 BUS Bus error
11 SEGV Segmentation fault
15 TERM Spftware termination
17 STOP Stop NO CATCH
18 TSTP Keyboard Stop
19 CONT Continue after stop
28 WINCH Window changed
30 USR1 User Defined 1
31 USR2 User Defined 2
###Signals
ps # shows status of running processes
ps aux # <-- very useful
# a - show all processes
# x - even processes that don't have control terminal
# u - user oriented format
ps auxww # show with all the info
ps aux | grep -v sshd # look up a single process
ps aux | grep -v grep | grep sshd # without grep return
pidof /usr/sbin/sshd # get pid of process
pgrep sshd # find pid of process
top # real time process info - task manager1
# tap 1 to switch to core view
kill pid # default sends TERM (polite)
kill -9 pid # true KILL
sudo killall httpd # kills all apached web server processes
sudo pkill -u jake # kill processes found from user jake
sudo strace -p 586 # run a trace on a pid
# memory
vmstat
# FILES-FILES-FILES-FILES-FILES-FILES
<<'###FileType'
- Regular File editor,cp rm
d Directory mkdir rmdir, rm -r
c Char Device File mknod rm
b Block Device File mknod rm
s Local Dom Socket
p Named Pipe
l Symolic Link ln -s rm
###FileType
<<'###lsbreakdown'
drwxr-xr-x. 2 root root 35 Feb 24 22:19 yo.service.d
d is for directory (1st)
rwxr permission bits
-xr setuid/setgid
x sticky bit
2 is hard link count - dir have at least 2
root = file owner
root = group owner
Feb 24 22:19 last modified
###lsbreakdown
file /tmp # basic info about a directory
file tmp.txt # basic info about a file
ls # list directory contents
ls -l tmp.txt # detailed info - determine ownership of a file
ls -l /tmp # detailed info on a directory
ls -i tmp.txt # identify inode number
ls -a # show all files in dir, even those with a .
ls -t # sort file by modification time
ls -F # diff between dir and exe
ls -R # list recursively
ls -h # file size in human-readable
cp # copy a file
cp names.csv /tmp # copy to /tmp
mv # move file
# making a new directory
sudo mkdir -p /yo/yo.service.d
# delete files
rm
rm -i tmp.txt # delete file with confirmation
# delete directory
rmdir yo
# delete a non-empty dir without confirmation
sudo rm -rf yo
# create symbolic links
sudo ln -s tmp /tmp/jake
# create and start editing a file
cat a.file # Get-Content of file
sudo bash -c 'cat > /tmp/try.yo'
cat example1 example2 example3 > example4
less a.file # browse a larger file
head a.file # fist 10 lines of text
head -n 20 a.file # first 20 lines of text
tail a.file # the last 10 lines of text
grep Alice a.file # find occurences of Alice in file
grep -v Alice a.File # all lines that don't contain Alice
grep -i Alice a.File # regardless cap
cut -f 3 -d"," # deal with csv's
# make a file executable
sudo chmod +x /tmp/a.file
lsof # lists all open files belonging to all active processes
<<'###chmod-encoding'
Octal Binary Perms
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx
###chmod-encoding
# user can read, write, execute. group can read, execute. others may read.
chmod u=rwx,g=rx,o=r tmp.txt
chmod a-x tmp.txt # removes execute from all categories
chmod g=u # makes group same as users
chmod --reference=filea fileb #makes fileb's mode same as filea's
chmod -R g+w mydir # recursively adds group write perm to mydir and all contents
find /tmp/yo/ -type f -exec chmod a-x {} ';' # adjust execute bits on just files
# change file ownership
sudo chown -R jake /tmp/jake # recursively change everything in this dir to owner jake
# change group ownership
chgrp
# eval file attribute flags
lsattr tst.txt
# change file attribute flags
chattr a tst.txt
# find just files
find /tmp/yo/ -type f
# FILES-FILES-FILES-FILES-FILES-FILES
# VIM-VIM-VIM-VIM-VIM-VIM-VIM-VIM-VIM
# yy - yank (copy) a line
# dd - delete (cut) a line
# p - put (paste) the clipboard after cursor
# i - insert before the cursor
# :wq or :x or ZZ - Write (save) and quit
# :q - quit (fails if unsaved changes)
# :q! or ZQ - quit and throw away unsaved changes
# 0 - Start of line
# ^ - Start of line (after whitespace)
# $ - End of line
# gg - first line
# G - last line
# n - next matching search pattern
# N - previous match
# * - next whole word under cursor
# # - previous whole word under cursor
# u - undo
# Ctrl+r - re-do
# VIM-VIM-VIM-VIM-VIM-VIM-VIM-VIM-VIM
# NANO-NANO-NANO-NANO-NANO-NANO-NANO
# Alt+6 - copy current line into cutbuffer
# Ctrl+K - Cut current line into cutbuffer
# Ctrl+U - Past contents of cutbuffer
# Ctrl+S - Save current file
# Ctrl+O - Offer to write file (save as)
# Ctrl+X - Close buffer, exit Nano
# NANO-NANO-NANO-NANO-NANO-NANO-NANO
# crons & timers
# cron
crontab #filename install filename as your crontab
crontab -e # open a crontab in your editor
crontab -l # lists the contents of crontab
crontab -r # removes crontab
# systemd timers
systemctl list-timers # list timers
systmctl start systemd-tmpfiles-clean # manually run a scheduled task
# network
nmcli -p device # connection state info
nmcli con # uuid of connection info
nmcli con down id "eth0"
nmcli con up id "eth0"
nmcli con s id "eth0" # lots of info about the connection
nmcli con e id "eth0" # open in the interactive connection editor
# making changes manually in the file:
cd /etc/sysconfig/network-scripts
cat ifcfg-eth0
nmcli connection reload
nmtui # graphic based editor
# disk stuff
sudo fdisk -l # get a list of disk info
mount # see all filesystems currently mounted
mount -o rw,remount / # re-mount a read-only file systems as read-write
sudo mount /tst/sda45 /users #installs file system on disk part /dev/sda4 under /users
unmount # detach filesystems
# see who is using a mountpoint currently
fuser -c /home # just the pids
fuser -cv /home # with user info
df -h # filesystem disk use
du -h # directories using space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment