11:00 - 17:00

Mon - Fri

Unix Commands Documentation

Command Options Remarks Example
ln - Hard Link. Two files can have the same inode number, permissions, and timestamp. Both files should be on the same file system. Changes made to one file are automatically available in the other. The count of hard links is shown in `ls`. ln origfile linkedfile
ln -s Soft Link. It can be across two file systems. It's also used to link directories. It's just a directory entry containing the pathname. It has "l" in the permission field. The inode of both files is different. ln -s orgfile linkedfile
find -name Search based on filename. find searchpath -name "file search criteria"
ls -a List file contents including hidden files. ls -a
ls -F Lists file contents, marks executable as *, directory as /, and soft link as @. ls -F
chmod - To grant rights to a file. Read permission=4, Write permission=2, and Execute permission=1. Even with 777 rights, only the owner can delete the file while others can edit it. chmod 756 gives all permission to the user, read and write access to the group, and read and execute permissions to other users
umask - Default permissions for file are 666 and directories 777. Of this, umask is subtracted to get default permissions. If umask is 022 then default permission for file will be 644 and directory will be 755.
cp -p Copies file and preserves a file's attributes. cp -p sourcefile destinationfile
grep -i Case-insensitive search. grep -i "search_term" filename
grep -r Recursive search through directories. grep -r "search_term" directory
tar -cvf Create a tarball archive. tar -cvf archive.tar directory
tar -xvf Extract a tarball archive. tar -xvf archive.tar
ps -aux Display information about all processes. ps -aux
kill -9 Force kill a process. kill -9 PID
df -h Display disk space usage in human-readable format. df -h
du -sh Display directory size in human-readable format. du -sh directory
echo -e Enable interpretation of backslash escapes. echo -e "Line1\nLine2"
history - Display command history. history
man - Display the manual for a command. man ls
sudo - Execute a command with superuser privileges. sudo command
wget -O Download files from the web. wget -O filename URL
curl -O Transfer data from or to a server. curl -O URL
nano - Text editor for command line. nano filename
vim - Advanced text editor. vim filename
top - Display real-time system processes. top
uptime - Show how long the system has been running. uptime
date - Display or set the system date and time. date

๐Ÿ“˜ UNIX Commands - Study & Download

๐Ÿ“„ Basic UNIX Commands

ln (Link)

ln origfile linkedfile: Hard Link โ€“ same inode, changes reflect in both files.

ln -s origfile linkedfile: Soft Link โ€“ can link across file systems, different inodes.

find

find path -name 'pattern': Search by name.

-type [f|d|l]: Search by file type.

-perm mode: Search by permission (e.g., 666 or 400).

-inum number: Search by inode.

-samefile file: Find all hard links.

-links +2: Files with link count > 2.

-user user: Files owned by user.

-size +x: Size-based search.

-mtime/-ctime/-atime [+/-n]: Time-based search (modified/created/accessed).

-follow: Follow symlinks.

-exec: Execute command (e.g., -exec rm {} \;).

-ok: Like -exec but with prompt.

-print: Print matches.

-ls: Detailed file list.

Logical Ops: -a (AND), -o (OR), ! (NOT).

ls

-a: Show hidden files.

-F: Mark file types.

-R: Recursive list.

-d: List dir names, not contents.

-l: Long format.

-n: Show UID/GID.

-t: Sort by modified time.

-ltr: Sort by time, oldest first.

-u: Sort by last access.

-i: Show inode number.

chmod

Grants file rights (r=4, w=2, x=1).

chmod 756 file: User=all, Group=rw, Others=rx.

-R: Recursive.

umask

Default perms: 666 (files), 777 (dirs).

umask 022 โ†’ Files=644, Dirs=755.

cp

-p: Preserve attributes.

cp -p src dest

chown

chown user file

-R: Recursive.

chgrp

chgrp group file

-R: Recursive.

-f: Force.

-h: Change symlink, not target.

touch

Create dummy file.

-m: Update modified time.

-a: Update access time.

echo

echo *: List current dir.

echo \*: Print *.

Escape: \n, \t, \c, \g (bell).

Wildcards

[a-z], [!x-z]: Pattern match.

Escape Characters

\n: New line

\t: Tab

\c: Suppress newline

\007 or \g: Bell

more

View file page-by-page.

/search: Search within file.

wc

-l: Lines

-w: Words

-c: Characters

pr

Prepare files for printing.

-l n: Set page length.

echo $$

Show current shell PID.

cmp

Compare files, show first diff.

-l: Byte by byte.

diff

Show differences to sync two files.

comm

Compare 2 sorted files.

-1: Suppress column 1.

-2: Suppress column 2.

-3: Suppress column 3.

head

head -n 10 file: Show top 10 lines.

tail

tail -n 10 file: Show last 10 lines.

tail -f file: Follow file changes.

tail +100 file: From line 100.

cut

-c: Character positions.

-d and -f: Delimited fields.

Example: cut -d: -f2-4 file

paste

Merge lines of files.

-d: Set delimiter.

sort

Sort file lines.

-r: Reverse.

-n: Numeric.

-k: Sort by column.

uniq

Remove duplicates.

-c: Count occurrences.

tr

Translate or delete.

tr 'a-z' 'A-Z' < file: Uppercase.

-d, -s: Delete, squeeze.

tee

Write output to file and stdout.

command | tee file

xargs

Convert input to arguments.

Example: find . -name '*.txt' | xargs wc -l

๐Ÿง  Advanced UNIX Commands

Below is a detailed and practical list of advanced Unix/Linux commands commonly used in critical production support environments, such as during release & deployment, remote access, file transfers, container operations, and cloud infrastructure tasks. Each command includes:

โœ… Purpose

๐Ÿ’ก Why it's used in production

๐Ÿ”ง Syntax & example

๐Ÿ” 1. Remote Server Access & Management

โœ… ssh โ€“ Secure Shell (Remote Login)
Purpose: Securely log into a remote Linux/Unix server.

Why in production: Daily use for accessing prod servers for troubleshooting, log checks, hotfixes.

Syntax:

ssh user@hostname_or_ip

Example:

ssh [email protected]
๐Ÿ”’ Use ~/.ssh/config for easier access with aliases.

๐Ÿ“ฆ 2. File Transfer Between Servers

โœ… scp โ€“ Secure 
Purpose:  files securely between local and remote servers.

Why in production: Moving builds, logs, configs, database dumps during deployment or troubleshooting.

Syntax:

scp source_file user@remote_host:/target/path/

Example:

scp app.tar.gz [email protected]:/opt/releases/

๐Ÿ› ๏ธ 3. Deployment and Build Utilities

โœ… rsync โ€“ Efficient File Sync
Purpose: Incrementally sync files/directories across servers.

Why in production: Faster and safer than scp for deployment of large projects.

Syntax:

rsync -avz /local/dir/ user@remote:/remote/dir/

Example:

rsync -avz ./build/ [email protected]:/var/www/html/

๐Ÿงฐ 4. Docker Operations (Containerized Deployments)

โœ… docker ps, docker exec, docker logs, docker cp
Purpose: Manage Docker containers on prod/staging servers.

Why in production: Common for microservices-based apps.

Examples:

List running containers:

docker ps
Check logs for a container:

docker logs container_id
Enter a containerโ€™s shell (e.g., to debug):

docker exec -it container_id /bin/
 a file into a container:

docker cp config.yml container_id:/app/config/

โ˜๏ธ 5. Cloud Operations (AWS CLI + Unix)

โœ… aws s3 cp, aws ec2 describe-instances, aws logs tail
Purpose: Automate cloud-based file handling, instance management.

Why in production: S3 for backups/artifacts, EC2 for server automation, CloudWatch for logs.

Examples:

 to S3:

aws s3 cp logs.tar.gz s3://myprod-logs/ --region us-east-1
List running EC2 instances:

aws ec2 describe-instances --query "Reservations[*].Instances[*].[InstanceId,State.Name,Tags]" --output table
Stream CloudWatch logs:

aws logs tail /aws/lambda/myFunction --follow

๐Ÿงฎ 6. Process and Resource Management

โœ… top, htop, ps, kill
Purpose: Check CPU, memory, and terminate rogue processes.

Why in production: Monitor performance, troubleshoot high load, kill stuck processes.

Examples:

Check running processes:

ps aux | grep java
Kill a process:

kill -9 PID
Real-time monitoring:

top
# or more user-friendly:
htop

๐Ÿ“ 7. Log Management

โœ… tail, grep, awk, less, zcat
Purpose: Analyze logs in real time or retrospectively.

Why in production: Debugging critical issues like downtime, errors, etc.

Examples:

Tail logs live:

tail -f /var/log/nginx/error.log
Search errors:

grep "ERROR" /var/log/app.log
Extract field with awk:


awk '{print $5}' /var/log/app.log
View compressed logs:

zcat app.log.gz | grep timeout

๐Ÿงช 8. Network & Connectivity

โœ… netstat, ss, telnet, curl, ping, dig
Purpose: Verify network connectivity, check open ports.

Why in production: Diagnose latency, DNS issues, port access.

Examples:

Check open ports:

netstat -tuln
Ping a service:

ping google.com
Test HTTP endpoint:

curl -I https://yourapp.com/health
Check DNS resolution:

dig api.yourdomain.com

๐Ÿงพ 9. Scheduled Jobs

โœ… crontab, at, systemctl
Purpose: Automate tasks (e.g., log rotation, backups).

Why in production: Automate recurring deployments, log archival, or checks.

Examples:

 crontab:

crontab -e
List current jobs:

crontab -l
Schedule one-time job (after 10 mins):


echo " /scripts/restart.sh" | at now + 10 minutes

๐Ÿ“‹ 10. Backup & Archival

โœ… tar, gzip, find
Purpose: Backup files and clean up old logs/artifacts.

Why in production: Storage management, retention compliance.

Examples:

Create backup:

tar -czvf backup_$(date +%F).tar.gz /var/www/html/

Delete logs older than 15 days:

find /var/log/myapp/ -name "*.log" -mtime +15 -exec rm {} \;

โœจ Pro Tip: Combine Tools in One-liners

tail -f app.log | grep "Exception"

ssh user@prod-server 'docker logs myapp_container | tail -n 50'

find /logs/ -type f -name "*.log" -mtime +7 | xargs tar -czf old_logs.tar.gz

๐Ÿ“ฅ Downloadable Study Materials: