Skip to content

hardBSDk/commands_bible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 

Repository files navigation

Commands Bible

Operating System/Kernel

Show OS/kernel information

uname -r ; uname -a

Show memory information

free -h

Show OS/kernel log

dmesg

Show rc init active services (BSD)

cat /etc/rc.conf

Show all normal users on the system

ls /home

Show all your storage devices

sudo fdisk -l

Show all your configured mountpoints

cat /etc/fstab

Show information about your partitions/filesystems

df -h

Show the active modules on the kernel

ls /lib/modules/$(uname -r)

Show all available modules on the kernel

ls /lib/modules/$(uname -r)/kernel/drivers/

Show status of the modules on the kernel

lsmod

Load a module to the kernel (Linux)

sudo modprobe module-name

Load a module to the kernel (BSD)

kldload module-name

Remove a module from the kernel

sudo modprobe -r module-name

Remove a module from the kernel

sudo rmmod module-name

Unmount one filesystem

sudo umount /your/path

Unmount all filesystems except root filesystem

sudo umount -a

Restart the system (systemd)

sudo systemctl reboot

Show active swap partition/file

sudo swapon

Enable mounted swap (on /etc/fstab or swapfile)

sudo swapon -a

Disable swap

sudo swapoff -a

Show the available/active I/O schedulers for your disk (X is your disk letter)

cat /sys/block/sdX/queue/scheduler

Show all available I/O schedulers for all disks

grep "" /sys/block/*/queue/scheduler

Change your active disk I/O scheduler

echo scheduler_name > /sys/block/sdX/queue/scheduler

Hardware

Show CPU information

lscpu

Show your USB device tree (motherboard ports/bandwidth)

lsusb -t

Show your PCI device tree (same as above)

lspci -tv

Advanced memory information

cat /proc/meminfo

Advanced memory information (dmidecode)

sudo dmidecode -t memory

Show how fast your hard disk read the data (X is the letter of your disk, use fdisk -l to check)

hdparm -t /dev/sdX

Show all active network interfaces

ifconfig

Show all active wireless network interfaces

iwconfig

Show available CPU governors

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

Show current CPU governor

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Activate a CPU governor (most used are "powersave","performance" and "ondemand")

echo governor_name | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Graphics

Start X11 from terminal (the command on .xinitrc will run)

startx

Show active program on X11 init config file ("startx" read this file)

cat ~/.xinitrc

Show your OpenGL driver name/version

glxinfo | grep OpenGL

Show your Vulkan driver name/version

vulkaninfo | grep Vulkan

Show if you have direct rendering enabled for GPU-oriented software

glxinfo | grep "direct rendering"

Environment variable to make a program use a different Mesa3D driver

MESA_LOADER_DRIVER_OVERRIDE=driver_name program

Environment variable to force a program to use LLVMpipe (OpenGL CPU emulation)

LIBGL_ALWAYS_SOFTWARE=true

(if you want to force all programs of the system to use LLVMpipe add this export LIBGL_ALWAYS_SOFTWARE=true command to your .bashrc file on your user folder or your shell configuration file, it's useful when the OpenGL version of your GPU is too low because your GPU is very old, it will make all games run but you can get very bad FPS if the game is vertex intensive)

Networking

Show system DNS name

hostname

Show all network addresses of your system

hostname -I

Ping any website or IP to see if it's online or measure your connection latency

ping website-link or ip-address

Show website registration information

whois https://websitename.com

User

Ctrl+C | This keyboard shortcut cancel any command process

Clean your terminal content/output

clear

Run previous command

!!

Ask root password to switch user for root with echo

su -

Ask current user password to become root

sudo -i

Run as root per-command with root environment variables

doas command

Run any command with temporary root privileges and current user environment variables

sudo command

Run previous command as root temporarily

sudo !!

Exit root privileges or exit terminal session

exit

Current active user on terminal shell/$PATH

whoami

Environment variable for user folder

$HOME

Show your default terminal shell

echo $SHELL

Show your current terminal shell

echo $0

Show your installed terminal shells (active on $PATH)

cat /etc/shells

Change your default terminal shell permanently (common path is /usr/bin)

chsh -s /path/of/your/shell

Add an alias/abbreviation for a command on your terminal shell (add this command on your shell configuration file to be permanent, generally a file named .name-of-your-shell-rc on your user folder)

alias name='command'

Change the user password

passwd name-of-the-user

Show the commands history

history

Show the commands with the name specified in history

history name

Change the ownership of a file/folder/device/mounted partition (recursively)

sudo chown -R user_name:group-name directory-name

Or

chown username file-name

Programs

Show all system-wide common programs

ls /bin

Show all system programs

ls /sbin

Show the specified text on terminal

echo text

Show the directories in $PATH environment variable

echo $PATH

Show the dependencies (shared libraries) used by a program

ldd program_name

Add a new PATH to your terminal shell

export PATH=$PATH:/your/directory

Restore the terminal variables to their default values

reset

Count the time taken for a program to run the command

time command

name* | In some programs the * symbol apply an action to all files with that name

This operator will launch any executable file from the terminal

./

The "&" operator is used for multitasking on terminal (it don't start the program process as a child of the terminal, but independent from it, so you can close the terminal, similar of what "exec" command does, replacing the shell process by the called program)

program &

Replace the shell by the called program (similar to "&" or "exit")

exec program

Run a non-executable sh script

sh your-script-name

Run a non-executable Bash script

bash your-script-name

Kill all processes with the specified name

pkill process-name

Kill all instances of a running program

killall process-name

Kill all processes of an user

killall -u user-name

This operator store the output of a task on some file (example: task > file.txt)

>

This operator store the output of a task on some file but don't overwrite it's contents (example: task > file.txt)

>>

This operator apply a command above the output of other program (example: glxinfo | grep OpenGL, this command will search for "OpenGL" inside the output of "glxinfo") - this method is technically known as "Unix pipe"

|

Download any GitHub repository to the active directory

git clone https://github.com/name-of-the-user/name-of-the-repository.git

Download any remote Git repository

git clone https://website-name.com/name-of-the-repository.git

Download a Git repository to the specified directory

git clone https://website-name.com/name-of-the-repository.git /name/of/your/folder

Download any file (as the HTTP protocol headers are flexible, it can download the wrong file, so try to specify the exact file without header problems, generally an exposed extension of the file in the URL "https://website.com/nameofthefile.extension")

wget https://website-name.com/name-of-the-file

Resume an incomplete download

wget -c https://website-name.com/name-of-the-file

Download any file and try again from where it stopped if the connection failed (by default wget tries 20 times)

wget --tries=anynumber https://website-name.com/name-of-the-file

Download from multiple links of a file

wget -i file.txt

Download the entire website and convert it to work locally (offline)

wget --recursive --page-requisites --html-extension --convert-links --no-parent https://website-name.com

Download any file

curl -O https://website-name.com

Resume an incomplete download

wget -C - -O https://website-name.com/name-of-the-file

Download files from multiple websites at once

curl -O https://website-name.com -O https://website2-name.com

Example command for custom Wine Prefixes

WINEPREFIX=~/.yourprefixname ./wine

Run Wine Explorer from the specified Wine Prefix

WINEPREFIX=~/.yourprefixname ./wine explorer

Option to extract AppImage files

--appimage-extract

Download a torrent with webtorrent-cli and open VLC media player

webtorrent download "magnet:..." --vlc

Choose how many threads will be used for compilation

make -j1

Install a locally compiled program on the system

sudo make install

Show configuration files of all programs installed on the system

ls /etc

Show the user configuration files of programs

ls ~/.local

Show files stored by XDG-compliant programs (FreeDesktop standard)

ls ~/.config

Clean systemd journal logs older than x days ("--vacuum-time=1d" means older than 1 day)

sudo journalctl --vacuum-time=1d

Clean thumbnails cache

rm -rf ~/.cache/thumbnails/*

Package Management

This common argument remove unused dependencies on some package managers

autoremove

This common argument remove packages cache

autoclean

This symbol applies an action to all packagess with that name

package_name*

Fix a incomplete package install on Debian systems

dpkg --configure -a

Remove all packages on FreeBSD systems

pkg delete -a

Files/Folders

Show the current active directory

pwd

Change the active directory to the specified folder

cd /name/of/your/folder

Change to the previous directory with echo

cd -

Change to the parent directory/folder

cd ..

Change the active directory to your user folder

cd ~

Show normal folders/files of the directory

ls

Show all folders/files from a directory, including the hidden ones

ls -a

Show almost all files/folders, excluding the hidden . and .. Unix tree files

ls -A

Show the files/folders inside all the folders of the directory

ls *

Show all files/folders inside all the folders of the directory, inclusing hidden ones

ls -a *

Show advanced information about the files/folders of the directory

ls -l

Show the contents of any text file

cat /directory/file

Search for a text in the specified file format (recursively)

grep -nr "text" --include "*.format"

Search for a text in the specified file name (recursively)

grep -nr "text" --include "file-name.type"

Create a new folder on the active directory

mkdir name-of-the-folder

Copy a file to other folder and overwrite on destination

cp name-of-your-file /destination/folder

Copy a file to other folder, overwrite on destination and maintain the file permissions and timestamps

cp -p name-of-your-file /destination/folder

Show the files that are being copied (verbose mode)

cp -v name-of-your-file /destination/folder

Ask if you want to overwrite the file

cp -i name-of-your-file /destination/folder

Copy a file to other folder, maintain permissions/timestamps, show the file being copied, ask permission to overwrite and make a backup

cp -pvib name-of-your-file /destination/folder

Copy/overwrite/backup a file to other folder with backup

cp -b name-of-your-file /destination/folder

Copy multiple files to other folder and overwrite on destination

cp file1 file2 /destination/folder

Copy a folder to other folder and overwrite on destination

cp -r /name-of-your-folder /destination/folder

Copy only the things inside the folder and overwrite on destination

cp -r name-of-your-folder/. /destination/folder

Copy a folder to other folder, maintain permissions/timestamps, show the files being copied, ask permission to overwrite and make a backup

cp -rpvib name-of-your-folder /destination/folder

Copy multiple folders to other folder and overwrite on destination

cp -r folder1 folder2 /destination/folder

Move a file/folder to other folder and overwrite on destination

mv /name-of-your-folder /destination/folder

Or

mv name-of-your-file /destination/folder

Ask if you want to overwrite the folder

mv -i name-of-your-file /destination/folder

Move all files with the specified type to the destination folder

mv *.type /destination/folder

Move/rename a folder

mv /name-of-your-folder /new-folder-name

Remove/delete a file

rm name-of-the-file

Remove/delete any folder recursively without asking for permission (use with caution if you called the command with su/sudo/doas)

rm -rf /your/folder

Remove an empty directory

rmdir /your/folder

Example command to add text on any file

echo "text" >> /directory/file

.nameofthefile or .nameofthefolder | A dot before the name of a file/folder make it hidden

Search for files on the directory/subdirectories (run with "sudo" or "su" if these directories are under root permissions)

find . -type f -name file-name

Search for folders on the directory/subdirectories (run with "sudo" or "su" if the directories are under root permissions)

find . -type d -name folder-name

Show all folders/files/subfolders/subfiles in a tree

tree /name-of-the-folder