Ravindra BagaleCourses & study guides English

Shell Scripting Complete 10: Redirection, Pipes, tee, Here-docs आणि Process Substitution

प्रत्येक Linux command ला तीन दारं असतात: input (stdin), normal output (stdout) आणि error output (stderr). Redirection प्रत्येक दार कुठे उघडतं ते ठरवतो. या chapter मधे files लिहायला > आणि >>, errors साठी 2> आणि &>, वाचायला <, commands जोडायला pipes |, save आणि show साठी tee, पूर्ण files लिहायला किंवा अनेक lines पाठवायला here-docs <

या chapter मध्ये तुम्ही काय शिकाल

  • stdin, stdout आणि stderr (0, 1, 2) समजा
  • > आणि >> ने लिहा आणि जोडा
  • 2> आणि 2>&1 ने errors वेगळे किंवा एकत्र
  • Pipes बनवा आणि tee वापरा
  • Here-docs ने files लिहा
  • <( ) ने outputs compare

1. रोजचं उदाहरण: building मधले पाण्याचे pipes

हे का लागतं?

कोथरूडच्या society मधे पाणी tank मधून येतं (input), kitchen tap ला जातं (normal output), आणि सांडपाणी वेगळ्या drain मधे जातं (errors). Plumber tap चं पाणी bucket मधे वळवू शकतो, दोन pipes जोडू शकतो, किंवा T-joint लावून पाणी एकाच वेळी दोन ठिकाणी पाठवू शकतो. Redirection आणि pipes म्हणजे data साठी plumbing.

हे काय आहे?

Tank = stdin (0). Tap = stdout (1). Drain = stderr (2). Bucket = > ने file. Pipes जोडणं = |. T-joint = tee. एकदम अनेक litres आणणारा tanker = here-doc.

कसं करायचं (step by step)

प्रत्येक stream कुठे जातो?Command 0,1,2 terminal वर घेऊन सुरू> किंवा >> 1 ला file मधे2> 2 ला file मधे2>&1 म्हणजे 2 तिथे जिथे 1 1 ला पुढच्या command च्या 0 ला जोडतोtee file आणि screen दोन्हीकडे copy
क्रम महत्त्वाचा: > file 2>&1, 2>&1 > file नाही.

2. लिहा आणि जोडा: > आणि >>

हे का लागतं?

Reports, logs आणि generated configs screen वर नाही, files मधे हवेत.

हे काय आहे?

cmd > file stdout file मधे लिहितो आणि जुना content बदलतो. cmd >> file शेवटी जोडतो. एकटं > file (किंवा : > file) file delete न करता रिकामी करतो, program ने उघडलेल्या log files साठी छान. set -o noclobber चुकून > overwrite थांबवतो; >| force करतो.

प्रकारकाय करतो
> foverwrite
>> fappend
: > ffile रिकामी
< ff मधून input
>| fnoclobber असूनही overwrite

कसं करायचं (step by step)

  1. List save.
ls /etc > etc-list.txt; wc -l etc-list.txt

Output:

212 etc-list.txt

याचा अर्थ: Screen वर काही नाही.

  1. Line जोडा.
date >> run.log; date >> run.log; wc -l run.log

Output:

2 run.log

याचा अर्थ: दोन lines.

  1. Log रिकामा.
: > /var/log/app/app.log; ls -l /var/log/app/app.log

Output:

-rw-r--r-- 1 app app 0 Oct 25 10:12 /var/log/app/app.log

याचा अर्थ: Size 0, file राहिली.

  1. Files protect.
set -o noclobber; echo hi > etc-list.txt

Output:

bash: etc-list.txt: cannot overwrite existing file

याचा अर्थ: Safety on.

  1. File मधून read.
wc -l < etc-list.txt

Output:

212

याचा अर्थ: File name नाही.

3. Errors: 2>, &> आणि 2>&1

हे का लागतं?

Cron jobs मधे errors log मधे हवेत, आणि noisy warnings report पासून दूर.

हे काय आहे?

2> file फक्त errors file मधे. 2>/dev/null errors फेकतो. cmd > out.log 2>&1 दोन्ही एकाच file मधे: आधी 1 हलवा, मग 2 ला 1 कडे. &> file दोन्हीसाठी bash short form. |& दोन्ही पुढच्या command ला pipe. लागणारे errors लपवू नका; फक्त माहित noise लपवा.

कसं करायचं (step by step)

  1. फक्त errors.
find / -name '*.pem' 2> find-errors.txt | head -2

Output:

/etc/pki/tls/cert.pem
/workspace/key.pem

याचा अर्थ: Permission errors file मधे.

  1. Noise लपवा.
find / -name sshd_config 2>/dev/null

Output:

/etc/ssh/sshd_config

याचा अर्थ: Clean output.

  1. दोन्ही log मधे.
./backup.sh > backup.log 2>&1; tail -2 backup.log

Output:

tar: /data/x: Cannot open: Permission denied
backup done

याचा अर्थ: Errors आणि output एकत्र.

  1. Short form.
./backup.sh &>> backup.log

याचा अर्थ: दोन्ही append.

  1. वेगळ्या files.
./import.sh > ok.log 2> err.log

याचा अर्थ: err.log size check सोपं.

4. Pipes | आणि tee

हे का लागतं?

जोडलेली छोटी tools मोठे प्रश्न सोडवतात: सगळ्यात जास्त कोणता IP आला, कोणता product सगळ्यात जास्त विकला.

हे काय आहे?

a | b, a चा stdout b च्या stdin मधे. हवे तितके जोडा. tee file, file मधे लिहितो आणि data पुढे पाठवतो, म्हणून मधली step save करून पण बघू शकता. tee -a append. Root-owned file लिहायला sudo tee, कारण sudo echo x > file मधे > ला root rights मिळत नाहीत.

कसं करायचं (step by step)

  1. Top IPs.
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -3

Output:

  540 49.36.12.8
  311 103.21.4.9
   97 66.249.66.1

याचा अर्थ: पाच tools, एक उत्तर.

  1. Save आणि show.
df -h | tee disk-report.txt

Output:

Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 8.1G 12G 41% /

याचा अर्थ: दिसलं आणि save झालं.

  1. Root file.
echo '10.0.1.5 db1' | sudo tee -a /etc/hosts

Output:

10.0.1.5 db1

याचा अर्थ: sudo echo > fail होतो तिथे चालतं.

  1. Pipe मधे lines मोजा.
journalctl -u nginx --since today | grep -c error

Output:

4

याचा अर्थ: आजचे errors.

5. Here-docs: <

हे का लागतं?

Config file, SQL script किंवा email body echo ने line by line लिहिणं ugly आणि चुकीचं होतं.

हे काय आहे?

cmd <

प्रकारपरिणाम
<$vars expand
<<'EOF'expansion नाही
<<-EOFसुरुवातीचे tabs काढा
<<<एक string input

कसं करायचं (step by step)

  1. Config लिहा.
app=shop; cat > /tmp/app.conf <<EOF
name=$app
port=8080
EOF
cat /tmp/app.conf

Output:

name=shop
port=8080

याचा अर्थ: $app expand झालं.

  1. $ text म्हणून.
cat > /tmp/hello.sh <<'EOF'
echo "Hello $USER"
EOF
cat /tmp/hello.sh

Output:

echo "Hello $USER"

याचा अर्थ: Quoted word, expansion नाही.

  1. एकदम SQL.
psql -h db1 -U app shop <<'SQL'
SELECT city, count(*) FROM orders GROUP BY city;
SQL

Output:

  city  | count
 Pune   |  1200

याचा अर्थ: psql ला अनेक lines.

  1. Here-doc ने root file.
sudo tee /etc/motd > /dev/null <<'EOF'
Authorized users only. Managed by ops team.
EOF

याचा अर्थ: tee root म्हणून लिहितो.

6. Here-strings <<<

हे का लागतं?

कधी variable मधे एक value असते आणि command ला ती stdin वर हवी.

हे काय आहे?

cmd <<< "$v" string आणि newline cmd ला देतो. echo "$v" | cmd टाळतो आणि pipe च्या उलट read current shell मधे चालतो, म्हणून त्याने set केलेले variables नंतर राहतात.

कसं करायचं (step by step)

  1. CSV line split.
IFS=, read -r id city amt <<< '101,Pune,499'; echo "$city $amt"

Output:

Pune 499

याचा अर्थ: Variables set राहतात.

  1. Words मोजा.
wc -w <<< 'build test deploy'

Output:

3

याचा अर्थ: echo नको.

  1. bc input.
bc <<< 'scale=2; 22/7'

Output:

3.14

याचा अर्थ: छोटं maths.

7. Process substitution <( ) आणि >( )

हे का लागतं?

diff आणि comm ला दोन files हव्यात, पण तुमच्याकडे दोन command outputs आहेत, उदा. दोन servers वरचे packages.

हे काय आहे?

<(cmd) cmd चालवतो आणि त्याचं output वाचणारं /dev/fd/63 सारखं file name देतो. File हवी असलेल्या कोणत्याही command ला देता येतं. >(cmd) उलटं: तुम्ही लिहिलेलं cmd मधे जातं. while read ... done < <(cmd) pipe च्या subshell problem शिवाय output वर loop करतो, म्हणून counters टिकतात.

कसं करायचं (step by step)

  1. दोन servers diff.
diff <(ssh web1 'rpm -qa | sort') <(ssh web2 'rpm -qa | sort')

Output:

< nginx-1.24.0-1
> nginx-1.22.1-1

याचा अर्थ: Version drift सापडला.

  1. हे काय?
echo <(true)

Output:

/dev/fd/63

याचा अर्थ: एक file name.

  1. Loop counter ठेवतो.
n=0; while read -r u; do ((n++)); done < <(cut -d: -f1 /etc/passwd); echo $n

Output:

34

याचा अर्थ: Pipe ने n 0 राहिला असता.

  1. दोन ठिकाणी लिहा.
./export.sh | tee >(gzip > export.gz) | wc -l

Output:

5000

याचा अर्थ: एकदम count आणि compress.

8. File descriptors आणि exec

हे का लागतं?

Long scripts ना प्रत्येक line ला > log न जोडता सगळं output log करायचं असतं.

हे काय आहे?

exec > file script च्या उरलेल्या stdout ला redirect करतो. exec > >(tee -a run.log) 2>&1 सगळं log करतो आणि दाखवतो पण. exec 3> file नवा descriptor 3 उघडतो; >&3 ने लिहा आणि exec 3>&- ने बंद. /dev/null black hole; /dev/stderr म्हणजे fd 2 चं नाव.

कसं करायचं (step by step)

  1. पूर्ण script log.
exec > >(tee -a /var/log/nightly.log) 2>&1
echo 'nightly start'

Output:

nightly start

याचा अर्थ: पुढची प्रत्येक line log.

  1. Extra descriptor.
exec 3>> audit.log; echo 'user asha ran deploy' >&3; exec 3>&-; cat audit.log

Output:

user asha ran deploy

याचा अर्थ: Audit वेगळा.

  1. fd मधून read.
exec 4< servers.txt; read -r first <&4; echo $first

Output:

web1

याचा अर्थ: एक line read.

9. अनेक industries मधली खरी उदाहरणं

हे का लागतं?

तेच Linux skill प्रत्येक प्रकारच्या company मध्ये लागतं. वेगवेगळ्या ठिकाणी पाहिलं की लक्षात राहतं.

हे काय आहे?

प्रत्येक row म्हणजे एक काल्पनिक team. कोण हे वापरतं आणि कसं ते दाखवते.

कसं करायचं (step by step)

Team आणि शहरते कसं वापरतातCommand
Rohan, banking, MumbaiEOD batch साठी वेगळा error log./eod.sh > eod.log 2> eod.err
Emma, media, BerlinAccess log मधून top referrersawk '{print $11}' a.log | sort | uniq -c | sort -rn
Kenji, robotics, TokyoHere-doc ने device configcat > dev.conf <<EOF
Fatima, government, Riyadhदोन servers च्या user lists comparecomm -3 <(sort a) <(sort b)
Lucas, SaaS, Sao Pauloपूर्ण deploy script logexec > >(tee -a deploy.log) 2>&1
Pooja, pharma, HyderabadRoot-owned hosts मधे appendecho "$ip db" | sudo tee -a /etc/hosts

10. नेहमीच्या errors आणि त्यांचे fixes

हे का लागतं?

हे errors सगळ्यांना येतात. कारण माहीत असलं की तास वाचतात.

हे काय आहे?

आधी नेमका message वाचा. मग खालच्या row शी जुळवा.

कसं करायचं (step by step)

दिसणारा errorका होतंFix कसा करायचा
Permission denied with sudo echo x > file> तुमच्या नावाने चालतो, root नाहीsudo tee वापरा.
echo x | sudo tee file
Errors still on screen after 2>&1 > fचुकीचा क्रमआधी > f.
cmd > f 2>&1
File became emptyवाचत असलेल्या file वर >Temp मधे लिहून move.
sort f > f.tmp && mv f.tmp f
warning: here-document delimited by end-of-fileClosing word नाही किंवा indentEOF line च्या सुरुवातीला एकटा.
EOF
Variables empty after while loopPipe loop subshell मधे चालवतो< <(cmd) वापरा.
done < <(cmd)
cannot overwrite existing filenoclobber on>| किंवा set +o noclobber.
echo x >| f
syntax error near unexpected token `('sh मधे process substitutionbash ने चालवा.
bash script.sh
$VAR printed literally in file<<'EOF' वापरलंExpand साठी unquoted EOF.
cat <<EOF
Disk full from a logRotate न केलेला >>रिकामा किंवा rotate.
: > big.log

11. Troubleshooting step by step

हे का लागतं?

Output चुकीच्या जागी जात असेल तर प्रत्येक stream वेगळा test करा.

हे काय आहे?

वरून खाली जा. ज्या step ला problem दिसतो तिथे थांबा.

कसं करायचं (step by step)

  1. फक्त stdout.
cmd 2>/dev/null
  1. फक्त stderr.
cmd > /dev/null
  1. Open fds.
ls -l /proc/$$/fd
  1. क्रम तपासा.
cmd > f 2>&1
  1. Pipe statuses.
echo "${PIPESTATUS[@]}"
  1. Lint.
shellcheck s.sh

12. Lab 1: tee सह log report pipeline

हे का लागतं?

छोटा access log बनवा, pipe ने top IPs आणि status codes शोधा, आणि report बघत save करा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Here-doc ने log.
cat > ~/access.log <<'EOF'
49.36.12.8 - - [25/Oct/2026] "GET / HTTP/1.1" 200
49.36.12.8 - - [25/Oct/2026] "GET /cart HTTP/1.1" 500
103.21.4.9 - - [25/Oct/2026] "GET / HTTP/1.1" 200
49.36.12.8 - - [25/Oct/2026] "GET /pay HTTP/1.1" 200
EOF
  1. Top IPs.
awk '{print $1}' ~/access.log | sort | uniq -c | sort -rn

Output:

      3 49.36.12.8
      1 103.21.4.9
  1. Status codes save.
awk '{print $NF}' ~/access.log | sort | uniq -c | tee ~/status.txt

Output:

      3 200
      1 500
  1. Errors file मधे.
grep ' 500$' ~/access.log > ~/errors.txt; wc -l < ~/errors.txt

Output:

1
  1. Clean up.
rm ~/access.log ~/status.txt ~/errors.txt

13. Lab 2: Process substitution ने दोन configs compare

हे का लागतं?

Here-docs ने दोन configs लिहा, मग <( ) ने temp files शिवाय sorted आणि comments शिवाय compare करा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Config A.
cat > ~/a.conf <<'EOF'
# prod
port=80
workers=4
EOF
  1. Config B.
cat > ~/b.conf <<'EOF'
workers=8
port=80
# staging
EOF
  1. Plain diff noisy.
diff ~/a.conf ~/b.conf | wc -l

Output:

8
  1. Clean compare.
diff <(grep -v '^#' ~/a.conf | sort) <(grep -v '^#' ~/b.conf | sort)

Output:

2c2
< workers=4
---
> workers=8
  1. Clean up.
rm ~/a.conf ~/b.conf

Ravindra Bagale's Tip

Remember the three doors 0, 1 and 2. Write > file 2>&1 in that order, use tee when you need to save and see, use <<'EOF' when writing scripts or configs into files, and use < <(cmd) when a loop must keep its variables.

14. नेहमी विचारले जाणारे प्रश्न

प्र. /dev/null काय?

Data फेकणारी file.

प्र. > vs >>?

बदलणं vs जोडणं.

प्र. sh मधे &>?

नाही, > f 2>&1.

प्र. Here-doc indent?

Tabs सह <<-.

प्र. sudo सह tee का?

Redirect तुमच्या नावाने.

प्र. <( ) खरी file?

/dev/fd/N म्हणून दिसणारा pipe.

प्र. दोन्ही streams pipe?

|& वापरा.

प्र. > ने file in place edit?

नाही; temp file मग mv.

15. मुलाखत प्रश्न आणि उत्तरं

Beginner level

प्र. fd 2 काय?

stderr.

प्र. File मधे append?

>>.

प्र. Errors लपवा?

2>/dev/null.

प्र. Commands जोडा?

Pipe |.

Mid level level

प्र. दोन्ही streams एका file मधे?

> f 2>&1.

प्र. Save आणि show?

tee.

प्र. Here-doc मधे $ expand थांबवा?

शब्द quote करा.

प्र. दोन command outputs diff?

diff <(a) <(b).

Senior level

प्र. 2>&1 > f का fail?

2 ला 1 चा जुना target मिळतो.

प्र. Pipe आणि subshell?

प्रत्येक भाग subshell मधे; vars हरवतात.

प्र. पूर्ण script log?

exec > >(tee -a log) 2>&1.

प्र. Safe in-place edit?

Temp file आणि atomic mv.

घरी करून बघा

  1. Here-doc ने shopping list file बनवा, मग sort आणि tee मधून sorted copy.
  2. दोन folders मधल्या files ची list diff <( ) <( ) ने compare करा.

सराव Tasks

या scenario बद्दल

London Legal LLP हा लंडन मधला कायदा सेवा व्यवसाय आहे. Oliver Hughes त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे GBP मध्ये मोजले जातात आणि AWS resources eu-west-2 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 21

सोपं Save आणि दाखवा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: Oliver Hughes London Legal LLP मधे df -h चालवतो. Output दाखवा आणि disk.txt मधे save करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं tee ने append

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: uptime output दाखवा आणि health.log ला append करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Errors टाका

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: /etc खाली hosts नावाच्या files दुसऱ्या filesystems मधे न जाता शोधा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Lines मोजा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: app.log मधे ERROR असलेल्या lines मोजा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Numbers sort

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: sizes.txt numerically sort करा, मोठे आधी.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Users मोजा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: /etc/passwd च्या lines मोजा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Case बदला

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: tr ने names.txt upper case करून print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Unique lines

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: एका sort option ने list.txt च्या unique lines sorted print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं पहिल्या 10

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: access.log च्या पहिल्या 10 lines दाखवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Top values

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: ips.txt मधून counts सह 3 सगळ्यात repeated lines print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Here-string

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: Here-string ने 5+7 text bc ला पाठवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Lines वाचा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: servers.txt line by line h मधे वाचा आणि प्रत्येक echo करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम xargs

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: xargs ने old.txt मधल्या files delete करा, list रिकामी असेल तर काही नाही.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Column total

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: awk ने bills.txt च्या second column ची बेरीज print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम ps च्या पहिल्या lines

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: ps sorted ने सगळ्यात जास्त memory वापरणारे 5 processes दाखवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Compressed वाचा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: Disk वर unzip न करता app.log.gz मधल्या ERROR lines मोजा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम दुसरा field

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: awk ने data.txt च्या प्रत्येक line चा second column print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Process substitution

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: Temp files शिवाय a.txt आणि b.txt चे sorted contents diff ने compare करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड फक्त पहिल्यात

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: comm आणि sorted inputs ने फक्त old.txt मधल्या lines print करा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Root म्हणून लिहा

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: tee वापरून root म्हणून /proc/sys/net/ipv4/ip_forward मधे 1 लिहा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Command वर loop

का: BIZ pipelines अनेक commands मधे output फिरवतात.

काय करायचं: Pipe subshell शिवाय ls output च्या lines वर f ने loop करा आणि echo.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

थोडक्यात सांगायचं तर

  1. 0 in, 1 out, 2 errors.
  2. > replace, >> append.
  3. दोन्हीसाठी > f 2>&1 किंवा &> f.
  4. | जोडतो, tee save आणि show.
  5. <<'EOF' files जशाच्या तशा.
  6. <( ) file सारखं.

उजळणी, तुलना आणि मुलाखत cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

0, 1, 2 streams. 0 stdin, 1 stdout, 2 stderr. Output save. दोन्ही एका file मधे. दाखवा आणि save.
उजळणी card: 0, 1, 2 streams · PNG download करा · Card page उघडा
Here-doc आणि here-string. अनेक lines command ला. एक string आत. Command file सारखी. Expansion थांबवायला EOF quote.
उजळणी card: Here-doc आणि here-string · PNG download करा · Card page उघडा
pipe vs <( ). Output stdin ला. / Output file name सारखा.
तुलना: pipe vs <( ) · PNG download करा · Card page उघडा
<<EOF vs <<<. अनेक lines. / एक string.
तुलना: <<EOF vs <<< · PNG download करा · Card page उघडा
2>&1 चा order का महत्त्वाचा?. Redirects डावीकडून उजवीकडे. 2>&1 आत्ता 1 कुठे ते copy. बरोबर.
मुलाखत card: 2>&1 चा order का महत्त्वाचा? · PNG download करा · Card page उघडा
Pipe loop नंतर variable रिकामा?. Pipe loop subshell मधे चालवतो. < <( ) ने feed. किंवा shopt -s lastpipe.
मुलाखत card: Pipe loop नंतर variable रिकामा? · PNG download करा · Card page उघडा
sudo echo > file fail?. Redirect तुमचा shell करतो. Root म्हणून tee. Append: tee -a.
मुलाखत card: sudo echo > file fail? · PNG download करा · Card page उघडा
<<EOF vs <<'EOF'?. Unquoted $vars expand. Quoted text जसाच्या तसा. <<- leading tabs काढतो.
मुलाखत card: <<EOF vs <<'EOF'? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.