Skip to content

Instantly share code, notes, and snippets.

@basperheim
Last active November 9, 2023 07:38
Show Gist options
  • Save basperheim/a4b7c7b34a0c8759c2de3740696aa1de to your computer and use it in GitHub Desktop.
Save basperheim/a4b7c7b34a0c8759c2de3740696aa1de to your computer and use it in GitHub Desktop.
Common Linux Commands

UNIX Commands Cheat Sheet

A cheat sheet for Linux commands, and how to install some packages and drivers.

Docker commands

Stop containers:

docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
docker stop $(docker ps -a -q)

Remove containers:

docker rm $(docker ps -a -q)

Remove images:

docker rmi $(docker images -a -q)

Prune stuff:

docker volume prune
docker image prune
docker network prune
docker system prune -a

Remove networks:

docker network rm $(docker network ls)

Stop, build, and restart production containers:

docker-compose -f docker-compose-production.yml down
docker-compose -f docker-compose-production.yml up --build
docker-compose -f docker-compose-production.yml start

Docker logs

Use the docker logs CONT_ID command to get logs for a container.

Pipe grep to docker logs to search the logs for a string match:

docker logs CONT_ID 2>&1 | grep "SEARCH FOR THIS"

Basic UNIX, Linux, and macOS terminal commands

Find out your user name:

whoami

Get full path to current directory

pwd

List files in current directory

ls

List all files AND their respective attributes

ls -l@

Hidden files start with a period ("."). List all files and hidden files

ls -a

Clear terminal screen

clear

Go back one directory level

cd ..

Delete a file

sudo rm /path/to/file/some-file.txt

Delete a directory AND ALL ITS CONTENTS

Be careful with this command:

sudo rm -rf /path/to/directory

Remove a directory

rmdir /path/to/some/dir

Create a new file

touch /path/to/some/directory/new-file.py
# OR this for new file in 'pwd':
touch new-file.txt

Locate a file (Linux only)

locate some-file-name

MOVE a file or folder using "mv"

sudo mv /path/to/file/some-file.txt /new/path/location

ALSO use "mv" to RENAME a file

sudo mv old-file-name.txt new-file-name.txt

View the "manual" for any command

man {SOME_COMMAND}
# for example: man history
# Press CTRL+Z to exit

Enter Python Interpreter

python3
# ..or for Python v2.x
python
# Press CTRL+Z to exit

Search the command history

Pipe the grep command to history to find a string match of a previously executed command:

history | grep {SOME_KEYWORD}

Kill a running process

ps aux | grep -i apt
sudo kill -9 <process id>

Unzip TAR Archives

tar xzf file.tar.gz
tar xjf file.tar.bz2
tar xzvf file.tar.gz

Use the stat command to show numerical permissions

stat -f '%A %N' path/to/dir

Adjust CPU frequency on Linux

sudo apt install aptitude
sudo aptitude install cpufrequtils
sudo cpufreq-set -f 2000
indicator-cpufreq
for x in /sys/devices/system/cpu/*/cpufreq/; do echo 800000 | sudo tee $x/scaling_min_freq; done
cpufreq-info
sudo cpufreq-set -f `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`

Install Snap Package Manager

sudo apt update
sudo apt upgrade -y
sudo apt install snapd
sudo apt purge snapd
sudo apt install snapd
snap find "program name"
sudo snap install {PROGRAM}

Install PHP 7.3

https://thishosting.rocks/install-php-on-ubuntu/

Install Lua 5.3 on Linux Debian

mkdir lua_build
cd lua_build
wget http://www.lua.org/ftp/lua-5.3.4.tar.gz
sudo tar -zxf lua-5.3.4.tar.gz
cd lua-5.3.4
sudo make linux test
sudo make install

Install the LÖVE 2D Game Engine for Lua

Love 2D Website

sudo add-apt-repository ppa:bartbes/love-stable
sudo apt-get update

or

sudo apt install love

Python and Lua Links:

Install GO Language v1.12

https://golang.org/dl/

sudo wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz
sudo tar -xvf go1.12.1.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=/path/to/project
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Create Bootable Linux USB ON Linux

Ask Ubuntu - Create a live USB

Startup Disk Creator Method

sudo apt-get install usb-creator-gtk

UNETBOOTIN Method

sudo add-apt-repository ppa:gezakovacs/ppa
sudo apt-get update
sudo apt-get install unetbootin

Restart Apache Server localhost

/etc/init.d/apache2 restart
# or
sudo /etc/init.d/apache2 restart

Disable Touchpad

xinput set-prop <id> "Device Enabled" 0

Install Aptitude:

sudo apt install aptitude
sudo aptitude install cpufrequtils

Install Firefox

sudo apt-get install firefox

Install Chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

Configure Pantheron/Gnome Desktop Settings

gsettings set org.pantheon.files.preferences single-click false
gsettings set org.gnome.desktop.interface text-scaling-factor 1.2
gsettings set org.pantheon.terminal.settings unsafe-paste-alert false
gsettings set org.gnome.desktop.notifications show-banners false

Fix Bad Installation of Skype

Uninstall Skype:

sudo service bluetooth restartSKYPE
sudo apt remove skype
sudo apt remove skypeforlinux.

Install cURL Library

sudo apt install apt-transport-https curl

Reinstall Skype

curl https://repo.skype.com/data/SKYPE-GPG-KEY | sudo apt-key add -
echo "deb [arch=amd64] https://repo.skype.com/deb stable main" | sudo tee /etc/apt/sources.list.d/skype-stable.list.
sudo apt update
sudo apt install skypeforlinux

Ask Ubuntu - Fix Bluetooth Issues

sudo service bluetooth restart
<cite>"I've edited the `/etc/bluetooth/audio.conf` file: `sudo -H gedit /etc/bluetooth/audio.conf` and add this line in the end of it: Disable=Headset. Users on Ubuntu 17.04 and above may not have `audio.conf`, but can instead use `main.conf`."</cite>

__PEEK:__
```bash
sudo add-apt-repository ppa:alexlarsson/flatpak
sudo apt update
sudo apt install flatpak
flatpak install --user https://flathub.org/repo/appstream/com.uploadedlobster.peek.flatpakref
flatpak run com.uploadedlobster.peek
flatpak update --user com.uploadedlobster.peek
https://github.com/phw/peek

Unlock read-only USB or SD card

Ask Ubuntu - SDB Read Write

sudo hdparm -r0 /dev/

FAT32 Format using Terminal

Use fdisk to find all drives:

sudo fdisk -l

Or use df to show volumes:

df

The drive will be: /dev/sdb{X}

sudo umount /dev/sdb{X}

Un-mount the drive:

sudo mkfs.vfat -n 'LINUX_BOOT' -I /dev/sdb{X}
# ..or
sudo mkfs.vfat -I /dev/sdb{X}

Format the drive as FAT32:

ls -1 /dev > ~/before.txt
ls -1 /dev > ~/after.txt
diff ~/before.txt ~/after.txt

Install ExFat package in Debian Linux

sudo apt install exfat-fuse exfat-utils

Slow down CPU speed using aptitude

for x in /sys/devices/system/cpu/*/cpufreq/; do echo 1200000 | sudo tee $x/scaling_max_freq; done
sudo apt install aptitude
sudo aptitude install cpufrequtils

Install the Atom IDE in Debian Linux

Atom IDE Menu Font Not-Visible

wget -O atom-amd64.deb https://atom.io/download/deb

INSTALL ATOM IDE ON LINUX MINT

sudo add-apt-repository ppa:webupd8team/atom
sudo apt update
sudo apt install atom

INSTALL ZOOM

wget -c https://zoom.us/client/latest/zoom_amd64.deb
sudo apt-get install libxcb-xtest0
sudo dpkg -i zoom_amd64.deb

Install Chromium

sudo apt install chromium-browser

Install Linux Wireless Drivers for Macbook Pro

Hardware Support

"BROADCOM 4360 comes with two different chips: 14E4:4360 NOT SUPPORTED and 14E4:43A0 SUPPORTED"

Check for hardware support:

lspci -vnn | grep -i net

Install Linux wireless drivers on a Macbook

sudo apt-get update
sudo apt-get install linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,') broadcom-sta-dkms

OR:

sudo apt-get install --print-uris linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,') broadcom-sta-dkms
sudo modprobe -r b44 b43 b43legacy ssb brcmsmac
modprobe wl

YouTube video explanation

Enable SSH Debian

sed -i '/PasswordAuthentication yes/s/^#//g' /etc/ssh/sshd_config
sed -i '/PermitRootLogin prohibit-password/s/^#//g' /etc/ssh/sshd_config
sed -i '/PermitRootLogin prohibit-password/s/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config

Install MacBook Fan Control

sudo nano /etc/mbpfan.conf

Fix a corruped volume

sudo fsck /dev/sdc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment