Unix reference
Table of Contents
:ID: 4ac31a1d-cdb1-4722-8215-3ed01414084b
This is a quick reference for some common Unix commands, tools and configuration.
See also Shell tips
# Permissions
See also this cheatsheet for more.
# View file permissions and ownership
ls -l
type | user | group | other |
---|---|---|---|
- | rwx | rw- | r-- |
Type could be d
(ie, directory)
# Change permissions
chmod u+rw file
Adds (+), for user (u), read and write (rw) permissions. See chmod --help
.
# Change ownership
chown username file chown username:groupname file chgrp groupname file
# Groups
# List groups
cmd | description |
---|---|
groups | list your groups |
groups username | list a user’s groups |
getent group groupname | list users in a group |
cat /etc/group | list all groups on the system |
# Manage group membership
Use gpasswd
# User Information
The id
utility can provide information like uid, groups, etc. Use a flag to
pull out specific information (-u
=> uid)
id username
Need to restart after changing group membership
# Magic SysRq key
Send low level commands regardless of system state (freeze)
- Hold down
ALT
+SysRq
- If on a laptop or keyboard with no
SysRq
key useFn
+Prtsc
and release (be keep holdingALT
)
- If on a laptop or keyboard with no
- See also https://en.wikipedia.org/wiki/Magic_SysRq_key
REISUB
for a safe restart
# Repositories (apt)
# Release file expired error
A couple options:
- Find another mirror. One that isn’t expired. Or…
Instruct apt to always skip the validity check
touch /etc/apt/apt.conf.d/99no-check-valid-until && \ echo 'Acquire::Check-Valid-Until no;' > /etc/apt/apt.conf.d/99no-check-valid-until
# Install specific version (if available)
apt-get install something=1.1.1
# Check for available versions
apt-cache policy ruby-full
# Add a repository
First add software-properties-common:
apt-get install -y software-properties-common
Then added the repo:
add-apt-repository ppa:kelleyk/emacs
And update
apt-get update
# File System
The following are just basic examples. There’s a lot you can do with these
tools. Use --help
or man pages.
# Display file system information
# df
Example: (human-readable)
df -h
# Disk Usage
# du (disk usage)
Example: (human-readable)
du -hs
# Copy files over SSH
# scp
Example: (recursive). This will use remote directories the map to the specified user’s home directory. Enter remote user’s pw when prompted.
scp -r "scp://pi@192.168.68.55/user/dir/path/to/stuff" ~/Downloads
# Make disk image
After attaching the disk you want imaged, use df -h
to
get the mount point. Then use use the dd
utility and specify the imput and
output. Example:
sudo dd if=/dev/mmcblk0p2 of=~/myimage.img
There will be no output while the image is made.
# Make a Hexdump
# xxd
xxd -ps /path/to/file | tr -d '\n'
# Devices
See also Pop_os (eg, lsusb
, etc)
# Logging
# Boot process
# dmesg
A command line utility to view (among other things) kernel messages
regarding hardware devices. Is something going wrong with the boot process,
some devices not working? Look at dmesg
.
# System logging
/var/log/syslog
# Other logging
Look in /var/log/
directory at all the other log files. Applications will
write logs here. For example /var/log/httpd
# SSH
# Allow SSHing onto a system
- Install
openssh-server
. This is configured viasystemd
to automatically start. - Use
ufw
to open port 22 (if firewall is active)