Loading…
OS · Linux commands · Program 30 · In the record
Linux commands such as mkdir,grep,sed,cal,cat,cd,xclock,oclock,>>(append),ls etc
1#!/bin/bash2# mkdir, cd, ls, cat, >, >> (append), grep, sed, cal, xclock, oclock3# Everything runs inside a throwaway folder, so nothing else is touched.4 5work=$(mktemp -d)6 7echo "== mkdir: create a directory =="8mkdir "$work/demo"9echo "Created demo/"10 11echo12echo "== cd: change directory =="13cd "$work/demo"14echo "Now in: $(basename "$PWD")"15 16echo17echo "== > (write) and >> (append) =="18echo "apple" > fruits.txt19echo "banana" >> fruits.txt20echo "cherry" >> fruits.txt21echo "mango" >> fruits.txt22echo "Wrote 1 line with > and appended 3 with >>"23 24echo25echo "== ls: list files =="26ls27 28echo29echo "== cat: show file contents =="30cat fruits.txt31 32echo33echo "== grep: search for lines containing 'an' =="34grep "an" fruits.txt35 36echo37echo "== sed: replace 'apple' with 'grape' =="38sed 's/apple/grape/' fruits.txt39 40echo41echo "== cal: calendar for July 2026 =="42cal 7 202643 44echo45echo "== xclock / oclock: graphical clocks (need X11) =="46for clock in xclock oclock47do48 if command -v $clock > /dev/null 2>&1 && [ -n "$DISPLAY" ]49 then50 echo "Starting $clock (close its window to continue)"51 $clock52 else53 echo "$clock: not available here (install x11-apps and run inside X11)"54 fi55done56 57cd /58rm -rf "$work"== mkdir: create a directory ==
Created demo/
== cd: change directory ==
Now in: demo
== > (write) and >> (append) ==
Wrote 1 line with > and appended 3 with >>
== ls: list files ==
fruits.txt
== cat: show file contents ==
apple
banana
cherry
mango
== grep: search for lines containing 'an' ==
banana
mango
== sed: replace 'apple' with 'grape' ==
grape
banana
cherry
mango
== cal: calendar for July 2026 ==
July 2026
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
== xclock / oclock: graphical clocks (need X11) ==
Starting xclock (close its window to continue)
[ an xclock window opens ]
+--------- xclock ---------+
| 12 |
| 11 | 1 |
| 10 | 2 |
| | |
| 9 o------- 3 |
| |
| 8 4 |
| 7 5 |
| 6 |
+--------------------------+
Starting oclock (close its window to continue)
[ an oclock window opens ]
.-""""""""-.
.' | '.
/ | \
; | ;
| o------ |
; ;
\ /
'. .'
'-........-'
(On a machine without X11 the script prints instead:)
xclock: not available here (install x11-apps and run inside X11)
oclock: not available here (install x11-apps and run inside X11)Run program 30 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.