Zach's Mugspideyclick logo

GitHub

GitLab

Linkedin

Instagram

Youtube

SoundCloud

Email

Linux Tips

This is just a catch-all for the many little useful Linux tricks I want to remember.

User Administration (Ubuntu)

  • List users: less /etc/passwd
  • Create user:

    • -m creates a home directory

    • -c adds a comment

    • -G adds the user to one or more secondary groups (customize this one)

sudo useradd -m \
    -c "Firstname Lastname" \
    -G wheel,docker \
    fLastname
  • Delete user: sudo deluser --remove-home fLastname

Disk Space

df is good for finding how much space is used on all your disks: df -h

du is the Disk Usage command. Here's an easy way to find the biggest directories in your installation: du -hs * | sort -rh | head -5

Sed

Quick replace line in file (absolute value): sed -i 's/User=.*/User=root/' install/audit.service

Quick replace line in file (variable): sed -i "s|WorkingDirectory=.*|WorkingDirectory=$thisDirectory|" install/audit.service

Netstat

Find all your open/listening ports: sudo netstat -tulpn

Screen

Screen is a command to help you run sessions while gone. It's real easy to set up:

sudo [yum/apt] install -y screen

Enter a screen session: screen

Leave a screen session: ctrl + a, d

Rejoin screen session: screen -r

Nohup

So, instead of using screen, you can also just ignore the terminal disconnect signal:

nohup {yourCommand} > p.out 2> p.err < /dev/null &

Create A Group Folder

Say you want /docker to be totally open to everybody in the docker group--read, write, create new files, etc.

sudo mkdir /docker
sudo chgrp -R docker /docker;
sudo chmod -R g+rws /docker