DEV Community

Cover image for Just Enough Linux
DrSimple
DrSimple

Posted on • Edited on

Just Enough Linux

sudo apt update           # updates the package list from repositories (does not install)
sudo apt upgrade -y       # upgrades all upgradable packages (-y auto-confirms)
Enter fullscreen mode Exit fullscreen mode

Install utility


sudo apt install open-vm-tools           # installs essential VMware guest utilities
sudo apt install open-vm-tools-desktop   # installs GUI support for VMware tools

Enter fullscreen mode Exit fullscreen mode

linux boot process

BIOS       # Basic Input/Output System: performs hardware checks (POST), then hands off to bootloader
BOOTLOADER # e.g., GRUB: loads the kernel into memory
KERNEL     # Core of the OS: manages hardware, memory, processes, and drivers
INIT       # Initializes system processes (now typically systemd)
LOGIN      # User authentication screen or shell prompt
Enter fullscreen mode Exit fullscreen mode

Check the shell you are using

which $SHELL
Enter fullscreen mode Exit fullscreen mode

Writing script

create a script file called test.bash

touch test.sh
Enter fullscreen mode Exit fullscreen mode

And paste:

echo "hello world"
Enter fullscreen mode Exit fullscreen mode

Run by typing

zsh test.sh
Enter fullscreen mode Exit fullscreen mode

Or run with

./test.sh
Enter fullscreen mode Exit fullscreen mode

You can write any linux command

echo "hello world"
ls
date
Enter fullscreen mode Exit fullscreen mode

Linux command

pwd - print working directory
whoami - display current username
history - show all commands that have been used 
date - current date time 
man - manual (man pwd, man date) 
who - shows who is logged in 
w - same as who
sudo su - login as a super user
Enter fullscreen mode Exit fullscreen mode

Variable

NB: ensure no space between the var and equal to sign

var="abayomi"
echo $var
Enter fullscreen mode Exit fullscreen mode

mathematical operation

  • for operations use (())
num1=8
num2=9
num3=$((num1 + num2))
echo $num3
Enter fullscreen mode Exit fullscreen mode

Take input from users

echo "enter first number: "
read var1
echo "enter second number: "
read var2

answer=$((var1 + var2))
echo $answer

Enter fullscreen mode Exit fullscreen mode

Shell scripting

if you don write the shell to use your os will take the default

#!/bin/zsh   
echo "hello james"
Enter fullscreen mode Exit fullscreen mode

to give it executabel rights

chmod 755 test.sh
Enter fullscreen mode Exit fullscreen mode

A script to create a nodejs app

#!/bin/zsh

echo "🚀 Creating a new production-grade TypeScript Node.js project..."

# Set your project name
PROJECT_NAME="npmproj"

# Create project directory
mkdir $PROJECT_NAME && cd $PROJECT_NAME


if [ -z "$PROJECT_NAME" ]; then
  echo "❌ Error: Project name not provided."
  echo "Usage: ./create-ts-node-project.sh <project-name>"
  exit 1
fi

# Initialize npm
npm init -y

echo "📦 Installing production dependencies..."
npm install express bcryptjs jsonwebtoken nodemailer cors helmet compression

echo "🛠️ Installing dev dependencies..."
npm install -D typescript ts-node-dev @types/node @types/express @types/bcryptjs @types/jsonwebtoken @types/cors dotenv

# Initialize TypeScript project
npx tsc --init

# Create tsconfig.json modifications (replace content)
cat > tsconfig.json <<EOF
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}
EOF

# Create project structure
mkdir -p src/{controllers,routes,services,models,config,utils,middlewares}
touch src/index.ts

# Create .env file
cat > .env <<EOF
PORT=5000
JWT_SECRET=your_jwt_secret
EOF

# Create .gitignore
cat > .gitignore <<EOF
node_modules
dist
.env
EOF

# Add a start script to package.json
npx json -I -f package.json -e 'this.scripts={
  "dev": "ts-node-dev --respawn src/index.ts",
  "build": "tsc",
  "start": "node dist/index.js"
}'

echo "✅ Project setup complete!"
echo "📂 Structure:"
tree src

Enter fullscreen mode Exit fullscreen mode
# Run:
chmod +x create-ts-node-project.sh
./create-ts-node-project.sh my-new-app
Enter fullscreen mode Exit fullscreen mode

Getting help command line

e.g for ls
ls --help
Enter fullscreen mode Exit fullscreen mode

You can use the man

man ls
info ls # this is another way of getting help
Enter fullscreen mode Exit fullscreen mode

Remove directory

rmdir <directory name>
rm -rf <directory name> # removing directory which is not empty
Enter fullscreen mode Exit fullscreen mode

Finding files

find . -name "*.txt"  # finds all .txt files in current directory and subdirs
find  <filename>
find test.sh
find ~/Downloads/ -name app.ts
find ~/Downloads/ -iname app.ts # iname will ignore case sensitivity
find ~/Downloads/ -mtime -30 #find files that have been created in the last 30 days
find /mnt/c/Users/CAPTAIN\ ENJOY/Downloads -mtime -30
find /mnt/c/Users/CAPTAIN\ ENJOY/Downloads -mtime -30 -size -10M # shows files with size less than 10 created in the last 30 days
find /mnt/c/Users/CAPTAIN\ ENJOY/Downloads -mtime -30 -size +10M # shows files with size less than 10 created in the last 30 days
Enter fullscreen mode Exit fullscreen mode

List files

ls -lh #shows files with the size
ls -lt #shows files based on the last modified date
ls -ls #sort files based on their sizes
ls -lra #reverse the order sorting
Enter fullscreen mode Exit fullscreen mode

Edit files

cat >test.md
then write your content here
then click enter and press control c
Enter fullscreen mode Exit fullscreen mode

Number Permission Type Symbol

Value Permission Name Symbol
0 No Permission ---
1 Execute --x
2 Write -w-
3 Write & Execute -wx
4 Read r--
5 Read & Execute r-x
6 Read & Write rw-
7 Read, Write & Execute rwx

Read write execute

chmod 777 test.sh # This gives read, write, and execute permissions to everyone (owner, group, others)
Enter fullscreen mode Exit fullscreen mode

When dealing with Linux file permissions using chmod, you can modify read (r), write (w), and execute (x) permissions for:

u – user (owner)

g – group

o – others

a – all (user + group + others)

And you use operators like:

  • – add permission

  • – remove permission

= – set exact permission (removes others)

Command | Meaning

chmod u+x file | Add execute to user
chmod g-w file | Remove write from group
chmod o=r file | Set others to read only
chmod a+rw file | Add read and write to everyone
chmod ug+x file | Add execute to user and group
chmod u=rwx file | Give user full permissions (read, write, execute)
chmod g=rw file | Set group permissions to read and write
chmod o= file | Remove all permissions from others
chmod a-x file | Remove execute from everyone
chmod ugo=r file | Set read-only for all (user, group, others)
Enter fullscreen mode Exit fullscreen mode

remove command

rm file.sh
unlink file.sh
Enter fullscreen mode Exit fullscreen mode

Rename

mv fileone.sh filetwo.sh
Enter fullscreen mode Exit fullscreen mode

copy command

cp main.go test.go
Enter fullscreen mode Exit fullscreen mode

diff space

diff a.sh b.sh
diff -y -W 60 a.sh b.sh
diff -q a.sh b.sh
Enter fullscreen mode Exit fullscreen mode

pipes

touch abacus shubacus lidacus xyx bingo
ls | grep "cus" # find all files that have the name cus in them
Enter fullscreen mode Exit fullscreen mode

You should have

abacus
lidacus
shubacu
Enter fullscreen mode Exit fullscreen mode
 find -name '*.txt' | xargs cat #find all files with name .txt and read 
Enter fullscreen mode Exit fullscreen mode

input output redirection

cat > file.txt
                     #this will open the edit command to write
Enter fullscreen mode Exit fullscreen mode

write into a file

ls -al > test.md
Enter fullscreen mode Exit fullscreen mode

Count number of lines

wc -l test.md # count the number of lines  i.e word count
wc -l < test.md # count the number of lines and redirect the output 
Enter fullscreen mode Exit fullscreen mode

Redirect command

program 2> abc # i,e program is not valid command line, so it will redirect the error into the abc file

Enter fullscreen mode Exit fullscreen mode

So this will create the abc file and then put the error message there

zsh: command not found: program
Enter fullscreen mode Exit fullscreen mode

append

cat >> hello.txt
Enter fullscreen mode Exit fullscreen mode

Shell aliases

alias e="echo"
Enter fullscreen mode Exit fullscreen mode

NB: the session will not be saved, to save, go to your shell like the bashrc or the zshrc and save it there

  • for bash vim .bashrc if zsh vim ~/.zshrc
alias v="nvim"
Enter fullscreen mode Exit fullscreen mode

To unalias

unalias v
Enter fullscreen mode Exit fullscreen mode

Environment variable

echo $PATH
echo $USER
printenv $HOME #prints a particular one 
printenv #prints all
Enter fullscreen mode Exit fullscreen mode

Create new variable (Local variables)

NEWVARIABLE=xyborg_key
echo $NEWVARIABLE
unset NEWVARIABLE
Enter fullscreen mode Exit fullscreen mode

Global variables

export VAR=linux
echo $VAR
Enter fullscreen mode Exit fullscreen mode

Shell history

echo $HISTFILESIZE #means we have capacity to store the output amount of commands 
echo $HISTSIZE # this is the capacity per session
history # shows the history
history 10 # shows last 10 commands
history | tail -10 # show last 10 commands
history | more #shows full screen command
Ctrl r #looks for all the commands you have type in a greplike way
Enter fullscreen mode Exit fullscreen mode

history and execute

history # shows all commands used
!233 #the number of the command you want to target
!-5 #shows and list the last 5 commands
Enter fullscreen mode Exit fullscreen mode

Processing and job scheduling

crontab -l ### checks if there is any cron job for the user
#you should get
no crontab for xybor
Enter fullscreen mode Exit fullscreen mode

Create a cron

sudo crontab -e 
Enter fullscreen mode Exit fullscreen mode

Then you will be given options to select as your editor

no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

Choose 1-4 [1]:

#i chose 2
Enter fullscreen mode Exit fullscreen mode
  • Then in the opened file, put your cron there
* * * * * <cmd here>
* * * * * ls
Enter fullscreen mode Exit fullscreen mode

Disk and file

df
df -h
df -a
Enter fullscreen mode Exit fullscreen mode

package manager

sudo apt install htop 
sudo apt remove htop
Enter fullscreen mode Exit fullscreen mode

Process Management

ps aux         # show all running processes
top            # interactive view of system processes
htop           # improved interactive process viewer (if installed)
kill PID       # send signal (default SIGTERM) to a process
kill -9 PID    # force kill a process

Enter fullscreen mode Exit fullscreen mode

File Permissions (Symbolic notation)

chmod u+x file     # add execute for user
chmod g-w file     # remove write for group
chmod o=r file     # set read-only for others
chmod a+x file     # add execute for all

Enter fullscreen mode Exit fullscreen mode

User Management (Basic)

adduser newuser     # create a new user
passwd newuser      # set password for user
su - newuser        # switch user
id                  # display user ID and group info
groups              # show groups current user belongs to

Enter fullscreen mode Exit fullscreen mode

Network Commands

ip a             # show IP addresses
ping google.com  # test connectivity
netstat -tuln    # show all listening ports
ss -tuln         # more modern alternative to netstat

Enter fullscreen mode Exit fullscreen mode

File Compression

tar -czvf archive.tar.gz folder/   # compress
tar -xzvf archive.tar.gz           # extract
zip archive.zip file               # zip
unzip archive.zip                  # unzip

Enter fullscreen mode Exit fullscreen mode

Grep and Search

grep "pattern" file         # find pattern in file
grep -r "pattern" folder/   # recursively grep in directory

Enter fullscreen mode Exit fullscreen mode

System Information

uname -a         # kernel and architecture info
uptime           # system uptime
free -h          # memory usage
lscpu            # CPU architecture info
lsblk            # list block devices

Enter fullscreen mode Exit fullscreen mode

APT Utilities

apt search <pkg>    # search for a package
apt show <pkg>      # show package details
apt list --installed # list all installed packages

Enter fullscreen mode Exit fullscreen mode

awk and sed Basics (Text Processing Tools)

# awk for column/line processing
awk '{print $1}' file.txt         # Print first column
awk -F':' '{print $1}' /etc/passwd

# sed for text replacement
sed 's/old/new/' file.txt         # Replace first match per line
sed 's/old/new/g' file.txt        # Replace all matches per line

Enter fullscreen mode Exit fullscreen mode

User Management

whoami                         # Current user (already listed)
id                             # Show current UID, GID, and groups
adduser newuser                # Add a new user
passwd newuser                 # Set password
deluser newuser                # Delete user
usermod -aG group user         # Add user to group
groups                         # Show groups of current user

Enter fullscreen mode Exit fullscreen mode

Group Management

groupadd devs                  # Create group
groupdel devs                  # Delete group
gpasswd -a user devs           # Add user to group
gpasswd -d user devs           # Remove user from group

Enter fullscreen mode Exit fullscreen mode

File Permissions Advanced (Ownership)

chown user:group file          # Change owner and group
chown -R user:group dir/       # Recursively change ownership

Enter fullscreen mode Exit fullscreen mode

Networking Commands

ip a                          # Show IP addresses (modern replacement for ifconfig)
ifconfig                      # Deprecated but common
ping google.com               # Check network connection
netstat -tulnp                # Show ports/services listening
ss -tulwn                     # Faster alternative to netstat
curl https://example.com      # Make HTTP request
wget https://example.com      # Download file from URL

Enter fullscreen mode Exit fullscreen mode

Process Management

ps aux                        # View running processes
top                           # Real-time process viewer
htop                          # Better version of top (already mentioned)
kill <PID>                    # Kill a process by PID
killall <name>                # Kill all by name
nice -n 10 command            # Run command with adjusted priority

Enter fullscreen mode Exit fullscreen mode

System Info

uname -a                      # Kernel and architecture info
uptime                        # System uptime
hostname                      # Machine name
lsb_release -a                # OS version info
free -h                       # Memory usage

Enter fullscreen mode Exit fullscreen mode

Permissions: Sticky, SUID, SGID

chmod +t dir/                 # Sticky bit (like /tmp)
chmod u+s file                # SUID - run as file owner
chmod g+s file                # SGID - run as group owner

Enter fullscreen mode Exit fullscreen mode

Scheduling Jobs with at

at now + 5 minutes
> echo "echo Hello" >> ~/message.txt
> <Ctrl+D> to save

Enter fullscreen mode Exit fullscreen mode

Systemctl / Services (for systemd systems)

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx        # Enable on boot
systemctl disable nginx       # Disable on boot

Enter fullscreen mode Exit fullscreen mode

Open command

open t.sh # mac specific
Enter fullscreen mode Exit fullscreen mode

Head

head readme.md # reads the first first ten
tail readme.md #reads last ten
less readme.md # opens file for scrolling and viewing one screen at a time
sort file.txt #sorts lines in a file alphabetically

Enter fullscreen mode Exit fullscreen mode

word count

wc readme.md  # counts lines, words, and bytes in file.txt
cat readme.md | wc -l #counts the number of lines in file.txt using a pipe
Enter fullscreen mode Exit fullscreen mode

disk usage

du -h  # shows disk usage of files and folders in human-readable format
df -h  # shows disk space usage of mounted filesystems
ps aux  # displays all running processes with detailed info
top  # shows real-time system resource usagetop  # shows real-time system resource usage
kill 1234  # sends a signal (default: TERM) to process ID 1234
killall firefox  # kills all processes named firefox
Enter fullscreen mode Exit fullscreen mode

compress

gzip file.txt  # compresses file.txt to file.txt.gz
gunzip file.txt.gz  # decompresses a .gz file
Enter fullscreen mode Exit fullscreen mode

tar

tar -cvf archive.tar files/  # creates a tar archive
tar -xvf archive.tar         # extracts a tar archive
Enter fullscreen mode Exit fullscreen mode

xargs

echo "file1 file2" | xargs rm  # removes file1 and file2 using xargs 
Enter fullscreen mode Exit fullscreen mode

link

ln -s target link  # creates a symbolic link (shortcut) to target
Enter fullscreen mode Exit fullscreen mode

Top comments (0)