Page Content

Tutorials

Unix Operating System Commands For Interview With Examples

This guide explains UNIX commands with real-life examples, Unix Operating System Commands covering file management, system monitoring, permissions, pipes, SSH access, and interview essentials. It also includes a clear UNIX vs Linux comparison, Installation process.

UNIX examples

Practical examples categorized by use case:

File Searching and Discovery

Finding a specific file or piece of information in a sea of data.

  • Scenario: You need to find all PDF files in your “Documents” folder.
    • Command: find ~/Documents -name "*.pdf"
  • Scenario: You want to find every line in a file that contains the word “Error” regardless of capitalization.
    • Command: grep -i "error" server.log
  • Scenario: You want to see the top 10 largest files in a directory.
    • Command: du -ah | sort -rh | head -n 10

Monitoring System Health

Checking if your computer is “breathing” correctly.

  • Scenario: Checking how much RAM is being used right now.
    • Command: free -m (on Linux) or top (on all Unix).
  • Scenario: Finding a “frozen” application to close it.
    • Command: ps -ef | grep "Chrome" (This gives you the Process ID or PID).
  • Scenario: Checking if a website or server is reachable.
    • Command: ping google.com

Permission Management

UNIX uses a numeric or symbolic system to control who can touch what.

  • Scenario: Making a script “executable” so you can run it as a program.
    • Command: chmod +x myscript.sh
  • Scenario: Restricting a file so only you can read it, and no one else can even see it.
    • Command: chmod 600 private_notes.txt

Also read about Unix Operating System: Features, Benefits, Drawbacks & Types

The “Magic” of Pipes (|)

Piping allows the output of one command to become the input for another.

  • Scenario: You have a long list of names in a file. you want to sort them alphabetically, remove duplicates, and save the result to a new file.
    • Command: cat names.txt | sort | uniq > clean_names.txt
  • Scenario: You want to count how many files are in your current folder.
    • Command: ls -l | wc -l

Remote Access (SSH)

Unix is the king of remote management.

  • Scenario: Logging into a server located in a different country to run commands.
    • Command: ssh username@192.168.1.10

Common Symbols

SymbolMeaningExample
>Overwrite a file with outputls > files.txt
>>Append output to the end of a filedate >> log.txt
**``**Send output to another command
*Wildcard (matches everything)rm *.tmp (removes all .tmp files)
..The parent directory (one level up)cd ..

Unix Operating System Commands

Unix Operating System Commands
Unix Operating System Commands

UNIX commands are short, case-sensitive, and designed to be combined.

CommandPurposeExample
lsList files in the current directoryls -l (lists with details)
cdChange directorycd /home/user/Documents
pwdPrint Working Directory (Where am I?)pwd
mkdirCreate a new foldermkdir MyProject
rmRemove/Delete a filerm old_file.txt
cpCopy a file or foldercp file.txt backup.txt
mvMove or Rename a filemv old.txt new.txt
grepSearch for text within a filegrep "error" log.txt
chmodChange file permissionschmod 755 script.sh
manManual (Help for any command)man grep

Also read about Linux File System Structure Explained: Root And Directories

Unix commands with examples

Every command follows a specific structure:

Example: ls -a /etc

  • ls: The action (list).
  • -a: The option (show all files, including hidden ones).
  • /etc: The argument (look in the “etc” folder).

Installation Process

Although each system is slightly different, installing a UNIX-based operating system (such as Ubuntu) generally goes like this:

Step 1: Create Bootable Media

Use a program like Rufus or Etcher to “burn” the ISO file (image file) onto a USB flash drive after downloading it.

Step 2: Boot from USB

After restarting your computer, use F2, F12, or Del to access the BIOS/UEFI menu. To make the USB drive start first, change the boot order.

Step 3: Disk partitioning

The most important step is this one. You have to choose:

  • Erase Disk: Installs UNIX and removes everything.
  • Dual Boot: Installs both Windows and UNIX so you can select one at startup.

Step 4: Configuring the User

Create your primary user account and set your Root (Administrator) password. These passwords are essential to UNIX security.

Step 5: Following the Installation

After you’re done, disconnect the USB and restart. Open the terminal and run an update command: sudo apt update && sudo apt upgrade (for Ubuntu/Debian).

Unix operating system commands for interview

File and Directory Commands

CommandPurposeExample
lsList files and foldersls -l
pwdShow current directorypwd
cdChange directorycd /home/user
mkdirCreate directorymkdir test
rmdirDelete empty directoryrmdir test
cpCopy filescp file1 file2
mvMove/rename filesmv old.txt new.txt
rmDelete filesrm file.txt
touchCreate empty filetouch demo.txt
treeShow directory structuretree /home

Also read about What Is A Shell Script In Linux? How It Works And Examples

File Viewing Commands

CommandPurpose
catDisplay file content
lessScrollable file view
morePage-by-page view
headFirst 10 lines
tailLast 10 lines
wcWord/line count

Example:

bash

-n 20 log.txt

File Permissions & Ownership

CommandPurpose
chmodChange permissions
chownChange owner
chgrpChange group

Example:

bash

chmod 755 script.sh

User & Process Management

CommandPurpose
whoLogged-in users
whoamiCurrent user
psRunning processes
topLive system processes
killStop process
niceSet priority

Example:

bash

kill -9 1234

Disk & System Information

CommandPurpose
dfDisk usage
duFolder size
freeMemory usage
uptimeSystem running time
unameSystem info
hostnameMachine name

Example:

bash

df -h

Also read about What Is Btrfs File System In Linux? And Btrfs Vs Ext4 Vs XFS

Networking Commands

CommandPurpose
pingCheck connectivity
ifconfigNetwork config
netstatNetwork status
sshRemote login
scpCopy via network

Example:

bash

ssh user@192.168.1.1

Search & Text Processing

CommandPurpose
grepSearch text
findSearch files
sortSort data
uniqRemove duplicates
cutExtract columns
awkText processing
sedStream editor

Example:

bash

grep "error" log.txt

Compression & Archiving

CommandPurpose
tarArchive files
gzipCompress
gunzipDecompress
zipZip files
unzipExtract zip

Example:

bash

tar -cvf backup.tar folder/

Package & Software Commands

CommandPurpose
pkgaddInstall software
pkgrmRemove software
pkginfoPackage info

Important Interview Concepts

Pipes and Redirection

bash

ls | grep txt

Input/Output

bash

command > output.txt
command < input.txt

Background Jobs

bash

command &

Most Asked Unix Interview Questions

Q1. Difference between rm and rmdir?

  • rm deletes files
  • rmdir deletes empty directories only

Q2. What is a pipe?

It sends output of one command to another.

Q3. What does chmod 777 mean?

Full permission to everyone (read, write, execute)

Q4. What is cron?

Scheduler for automatic tasks.

Also read about What Is Linux Kernel? Why It Is Important And Its Components

Top 10 Commands

  1. ls
  2. cd
  3. pwd
  4. ps
  5. top
  6. grep
  7. find
  8. chmod
  9. tar
  10. kill

UNIX vs Linux

FeatureUNIXLinux
DefinitionA family of proprietary operating systems originally developed at Bell LabsAn open-source UNIX-like operating system created by Linus Torvalds
Source CodeMostly closed source and controlled by vendorsCompletely open source and freely available
CostUsually paid and requires licensesFree to use, modify, and distribute
OwnershipOwned by companies like Oracle (Solaris), IBM (AIX), HP (HP-UX)Community-driven with contributions from individuals and companies
DevelopmentDeveloped and maintained by specific vendorsDeveloped by a global open-source community
CustomizationLimited customization optionsHighly customizable
Hardware SupportRuns on specific certified hardwareRuns on almost any hardware
SecurityVery secure and stableVery secure with frequent updates
StabilityExtremely stable, used in enterprise systemsVery stable, widely used in servers
User InterfaceTraditionally command-line focusedBoth command-line and graphical desktops
PopularityLess common todayMost popular server OS worldwide
Learning CurveSteeper, requires professional trainingEasier, large learning resources
Software AvailabilityLimited to vendor-supported softwareHuge software repositories
ExamplesSolaris, AIX, HP-UX, macOSUbuntu, Debian, Fedora, Red Hat, Linux Mint
CertificationOfficially certified UNIX systemsNot officially UNIX, but UNIX-like
UpdatesControlled by vendorFrequent community updates
Cloud UsageLimitedDominates cloud and container platforms
Community SupportSmaller, vendor-basedMassive global community
Hemavathi
Hemavathihttps://govindhtech.com/
Myself Hemavathi graduated in 2018, working as Content writer at Govindtech Solutions. Passionate at Tech News & latest technologies. Desire to improve skills in Tech writing.
Index