Basic commends:
SSH Server :
π§ 1. Install SSH Server
Run this on Ubuntu (not Windows):
sudo apt update
sudo apt install openssh-server
π 2. Start the SSH service
sudo systemctl start ssh
3. Enable SSH to start on boot
sudo systemctl enable ssh
4. Check SSH status
sudo systemctl status ssh
Make sure it says: active (running)
Extra: Check if Port 22 is Open
sudo ufw allow ssh
sudo ufw enable
Then verify:
sudo ufw status
ssh ranjith@192.168.0.102
π whoami
β Shows the current logged-in username
π Example: whoami β srtechops
π pwd
β Prints the current working directory path
π Example: /home/srtechops
π mkdir β Make Directory
β Creates folders (one or more)
π Example: mkdir sample β Creates a folder named "sample"
mkdir devops aws azure β Creates multiple folders
rmdir β Remove Empty Directory
β Deletes empty folders only
π Example: rmdir sample
rmdir devops aws azure
π ls β List Files and Directories
β Shows items inside the current directory
π Example: ls
ls -l β Long format
ls -a β Shows hidden files
ls -lt β Sort by modified time
ls -ltr β Time-based + reverse
ls -F β Shows file type
ls aws/ β Lists items in aws folder
π File Commands
π touch
β Creates a blank file
π touch file.txt
ποΈ rm β Remove Files/Folders
β Deletes files/folders
π Examples:
rm file.txt β Deletes file
rm -r aws/ β Removes folder + content
rm -rf aws/ β Force delete
rm *.txt β Deletes all .txt files
rm f* β Deletes files starting with f
π cat β Read & Write Files
β Read/write files (no editing lines)
π Examples:
cat file.txt β Show content
cat > file.txt β Overwrite content (Ctrl + D to save)
cat >> file.txt β Append content
cat -n file.txt β Show lines numbered
tac file.txt β Show file in reverse
βοΈ CLI Text Editors
π nano β Easy text editor
nano sample.txt
Save: Ctrl + O
Exit: Ctrl + X
π§ vi or vim β Advanced text editor
Open: vi file.txt
Type i β Insert mode
Esc β Exit insert mode
:wq! β Save and quit
:q! β Quit without saving
π£ echo β Print in Terminal
π echo "welcome to devops class"
β To save output:
echo "welcome" >> sample.txt β Auto creates file
π History & Search
π history β Shows command history
π Examples:
history
history -d 55 β Delete entry 55
history -c β Clear history
history >> file.txt β Save to file
π grep β Search in text
π Examples:
grep "git" file.txt
grep -i "g" β Case-insensitive
grep -i -c "g" β Count matches
grep -i -n "g" β Show line numbers
grep -i -v "g" β Show lines without match
π Combine with history:
history | grep -i "ls"
history | grep -c "ls"
π οΈ sed β Stream editor
π Examples:
Replace for display only: sed "s/c/c++/" file.txt
Replace & save: sed -i "s/py/python/" file.txt
Case-insensitive: sed -i "s/py/python/I"
Delete last line: sed -i '$d' file.txt
Delete line 2: sed -i '2d' file.txt
Delete lines from 6 to end: sed -i '6,$d' file.txt
π File/Folder Movement & Copy
π mv β Move or Rename
π Examples:
mv js java β Rename
mv file folder/ β Move
mv .hidden visible β Unhide
mv file folder/newname β Move + rename
π cp β Copy files/folders
π Examples:
cp a.txt b.txt β Copy file
cp a.txt folder/ β Copy into folder
cp -r folder1/ folder2/ β Copy folder
πΌ File View Commands
πΌ head β First few lines
head file.txt β First 10 lines
head -n 5 file.txt
π½ tail β Last few lines
tail file.txt β Last 10 lines
tail -n 2 file.txt
tail -f file.txt β Live log view
ποΈ Compression
ποΈ zip β Compress files
π Examples:
zip name.zip *.txt
zip -sf name.zip β Show content
zip -d name.zip file β Remove file
zip -e secure.zip *.txt β Password zip
unzip name.zip β Extract
π tar β Archive tool
π Examples:
tar -cf file.tar *.txt β No compression
tar -czvf file.tar.gz *.txt β With compression
tar -tvf file.tar β Show detailed content
tar -xvf file.tar β Extract
π Network Tools
π wget β Download file
π Example: wget https://example.com/file.zip
π ssh β Remote login
π Example:
ssh user@ip
ssh srtechops@gmail.com
π Password protected login
π GPG β Encrypt/Decrypt
π Encrypt: gpg -c file.tar
π Decrypt: gpg -d file.tar.gpg > file.tar
π€ USER MANAGEMENT
$ - Normal user - access file and directories
- Admin root User or Root user - access to All
(install, uninstall apps and update)
su root
password: root123
su - root
adduser :
useradd ranjith
automatically create user account group and home
set password:
passwd ranjith123
cat /etc/passwd - show all users
cat /etc/group - show all groups
su - ranjith - swith home directory
user rename :
usermod -l ranjith ranjithkumar - l new log
group rename :
groupmod -n ranjithkumar ranjith
renane home dir :
mv ranjith ranjithkumar
Delete user :
userdel ranjithkumar
group automatically deleted
Delete home dir :
rm -rf ranjithkumar
userdel ranjithkumar -- remove
π€ USER MANAGEMENT
π‘ User Types
$ β Normal user (limited access)
# β Root user (full access: install, delete, update)
π Switch to Root
su root
# OR
su - root
β Create User
useradd ranjith # Add user only (no home)
adduser ranjith # Recommended β creates home + group + prompts password
π Set Password
passwd ranjith
π View All Users and Groups
cat /etc/passwd # List all users
cat /etc/group # List all groups
π Switch User
su - ranjith # Switch to user and home
βοΈ RENAME USER / GROUP / HOME
π§ Rename User
usermod -l newname oldname
# Example:
usermod -l ranjith ranjithkumar
π₯ Rename Group
groupmod -n newgroup oldgroup
π Rename Home Directory
mv /home/oldname /home/newname
usermod -d /home/newname -m newname
ποΈ DELETE USER / HOME / GROUP
β Delete User Only
userdel ranjith
β Delete Home Directory
rm -rf /home/ranjith
π₯ Delete User with Home Directory
userdel --remove ranjith
π‘ Group is NOT deleted automatically unless it's a private user group and unused.
π File Permissions
Permission types:
r = read (4)
w = write (2)
x = execute (1)
π οΈ Change with chmod:
Examples:
chmod u+x file β Add execute
chmod g-r file β Remove read
chmod o-rwx file β Remove all from others
chmod 777 file β Full access
chmod 600 file β Owner only
π₯ Change Ownership:
Owner: chown harini file.txt
Group: chown :dev file.txt
Both: chown harini:dev file.txt
Directory: chown -R user:group folder/
π File Info & Search
π Find OS: cat /etc/os-release
π Find binary: whereis git
π Search: find -name f1.txt
π Find empty files: find -type f -empty
ποΈ Delete empty dirs: find -type d -empty -delete
π File Linking
π Hard Link: ln file.txt hard.txt
π Soft Link: ln -s file.txt soft.txt
Kill:
π Process Management
π Top Processes: top
Normal: kill 2693
Force: kill -9 2693
π What is crontab?
crontab stands for "cron table". It's a file where you define tasks to run automatically at a set time or date.
π Cron = scheduler
π Crontab = list of scheduled tasks
π§ Basic Crontab Command
crontab -e Edit your crontab file
crontab -l List current cron jobs
crontab -r Remove all cron jobs
crontab -u username -l View cron for another user (root only)
Crontab Syntax
* * * * * command_to_run
| | | | |
| | | | βββββ Day of the week (0 - 6) [Sun=0]
| | | ββββββββ Month (1 - 12)
| | βββββββββββ Day of the month (1 - 31)
| ββββββββββββββ Hour (0 - 23)
βββββββββββββββββ Minute (0 - 59)
π
Common Examples
Time Crontab Syntax Description
Every minute * * * * * Runs every minute
Every hour 0 * * * * Runs at minute 0 of every hour
Daily at 5am 0 5 * * * Runs at 5:00 AM every day
Every Monday at 3pm 0 15 * * 1 Runs at 3:00 PM on Mondays
On Jan 1st at midnight 0 0 1 1 * New Year execution
π Run a Script with Crontab
Suppose you have a script at /home/user/backup.sh
Make it executable:
chmod +x /home/user/backup.sh
Now schedule it (e.g., every day at 2 AM):
0 2 * * * /home/user/backup.sh
β
Tips
Always give full paths (e.g., /usr/bin/python3, /home/user/script.sh)
Use >> /path/to/logfile.log 2>&1 to log output and errors
Edit crontab using crontab -e
π§ͺ Test Crontab
Try a quick job:
* * * * * echo "Hello from cron!" >> /home/user/cronlog.txt
This appends "Hello from cron!" to the file every minute.
β
1. Shutdown Immediately
sudo poweroff
sudo shutdown now
β
2. Shutdown After 1 Minute
sudo shutdown
(Default is 1-minute delay)
β
3. Shutdown at a Specific Time
sudo shutdown 22:00
(This shuts down at 10:00 PM)
β
4. Restart Instead of Shutdown
sudo reboot
β
Cancel Scheduled Shutdown
sudo shutdown -c
Top comments (0)