homework linux 3
๐ grep Tasks
Search for the word
Linuxinfile.txt.Search case-insensitively for
ubuntu.Count how many lines contain
error.Show only the matching part using
-o.Show line numbers with matches.
Search recursively in a folder.
Invert match to find lines without
hello.Use regex to match lines starting with "A".
Match exact whole word
root.Combine with
ps aux | grep ssh.
๐๏ธ rm Tasks
Delete a file
temp.txt.Delete multiple files
rm a.txt b.txt.Delete all
.logfiles in a directory.Use
rm -ito confirm before deletion.Delete a folder and its contents recursively.
Delete hidden files in current directory.
Delete files older than 2 days using
findandrm.Prevent
rmfrom deleting a file withchattr +i.Try
rm -vto see whatโs being removed.Use
rm -ron a test directorytestdir/.
โก๏ธ Redirection > Tasks
Write output of
datetotoday.txt.Redirect
whoamito a file.Overwrite
test.txtwithecho.Redirect
ls -lto a new file.Redirect error from
cat nofiletoerr.txt.Redirect command output into
/dev/null.Save disk usage to
disk.txt.Run
uptimeand save output.Redirect list of users from
/etc/passwd.Check if file was overwritten.
โ Append >> Tasks
Append current time to
log.txt.Append
uname -atosysinfo.txt.Add a new line to an existing file.
Save the result of multiple commands into one file.
Combine with
echoto create a multiline file.Append ping results to
pinglog.txt.Append errors of a failed command.
Add student names to a list file.
Append system uptime daily (cron job idea).
Log current directory to
path.log.
๐ฅ๐ค stdin, stdout, stderr Tasks
Use
catwithout file to enter text from stdin.Redirect stdout of
lstoout.txt.Redirect stderr from
cat wrongtoerror.txt.Use
2>&1to combine error and output.Pipe stdin from
echoto another command.Write a command that reads from a file as stdin.
Filter only errors using
2>redirection.Send output to screen and file using
tee.Use
|to pass stdout as stdin togrep.Demonstrate
stdinwithreadin a script.
๐ก sort Tasks
Sort a list of names in a file.
Sort numbers in ascending order.
Sort with
-rfor reverse.Sort and remove duplicates.
Sort by numeric value
-n.Sort by a specific column in a CSV file.
Sort ignoring case.
Sort file and save result.
Combine with
uniqto show unique sorted lines.Sort the result of
ps aux.
๐ uniq Tasks
Remove duplicate lines from
names.txt.Count unique lines using
-c.Show only repeated lines using
-d.Show only unique lines using
-u.Sort a file then apply
uniq.Chain with
sort | uniq -c.Show how many times each IP appears in
access.log.Detect duplicates in student list.
Use
uniqon sorted numeric values.Count unique error messages in a log file.
๐ find Tasks
Find all
.txtfiles.Find files modified in last 1 day.
Find files bigger than 5MB.
Find empty files.
Find files with
-nameand delete them.Find all hidden files.
Find files with 777 permissions.
Find files owned by a user.
Find and archive results.
Find directories only.
โ๏ธ cut Tasks
Extract first column of a CSV.
Cut usernames from
/etc/passwd.Extract the second field by delimiter
:from a file.Cut first 10 characters from each line.
Extract filename from full path.
Combine with
ls -l | cutto get file sizes.Show domains from email list.
Cut and save result to
cut.txt.Extract year from date
YYYY-MM-DD.Use
cutwithdf -hto display only used percent.
๐ง awk Tasks
Print the first column from
/etc/passwd.Print 1st and 3rd column from a CSV.
Sum all numbers in second column.
Print lines where second field > 100.
Count lines with more than 3 fields.
Replace "admin" with "user" in a file.
Format output:
awk '{print "Name: "$1}'.Calculate average from a column.
Use condition
ifinawk.Chain
grep | awkto format filtered output.
