Skip to content

Commit acf0835

Browse files
committed
unix fun post
1 parent ad7280d commit acf0835

25 files changed

+313
-0
lines changed

content/posts/unix-fun.md

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
---
2+
title: "Unix Fun"
3+
date: 2025-01-30T10:28:03-05:00
4+
draft: false
5+
tags: ["unix", "linux", "CLI", "command line"]
6+
author: "me"
7+
showToc: true
8+
TocOpen: false
9+
hidemeta: false
10+
comments: false
11+
description: "Some fun tasks to practice unix commands and nice one-liners"
12+
canonicalURL: ""
13+
disableHLJS: false
14+
disableShare: false
15+
hideSummary: false
16+
searchHidden: false
17+
ShowReadingTime: false
18+
ShowBreadCrumbs: true
19+
ShowPostNavLinks: true
20+
ShowWordCount: false
21+
ShowRssButtonInSectionTermList: true
22+
UseHugoToc: true
23+
cover:
24+
image: ""
25+
alt: ""
26+
caption: ""
27+
relative: false
28+
hidden: false
29+
editPost:
30+
URL: ""
31+
Text: "Suggest Changes"
32+
appendFilePath: true
33+
---
34+
# Fun Linux/Unix Tasks and Commands
35+
36+
Just a little context, this is a modified version of an assignment for my software security class so we are using the [Seed Labs VM](https://seedsecuritylabs.org/) so if you want to follow along, set that up on your machine.
37+
38+
# Task 1:
39+
40+
## Item 1: Enable ssh
41+
42+
ssh is already enabled on the base vm.
43+
44+
### Command:
45+
46+
`ssh seed@seedvm.local.lan`
47+
48+
This connects to the vm via ssh, command {use}@{host} and
49+
50+
`systemctl status sshd`
51+
52+
This asks the OS “what is the status of the sshd service?”
53+
54+
### Output:
55+
56+
![](../../unix-fun/task1.1.png#center)
57+
58+
![](../../unix-fun/task1.1(2).png#center)
59+
60+
## Item 2: Enable SFTP
61+
62+
sftp is already enabled on the base vm.
63+
64+
### Command:
65+
66+
`sftp seed@seedvm.local.lan`
67+
68+
this connects to the vm using sftp, so command {user}@{host} and
69+
70+
`ps aux | grep sftp`
71+
72+
lists all running processes and filters the output to show only those related to sftp, helping check if an SFTP process is running
73+
74+
### Output:
75+
76+
![](../../unix-fun/task1.2.png#center)
77+
78+
![](../../unix-fun/task1.1(2).png#center)
79+
80+
# Task 2:
81+
82+
## Item 1:download
83+
84+
Couldn’t use wget or curl, so had to download through my class canvas page 😓.
85+
86+
## Item 2: copy the tarballs into ~/Documents
87+
88+
### Command:
89+
90+
`stfp> put hw1.*.tar.gz /home/seed/Documents/`
91+
92+
Put is the command to move a file from local to remote and then the name of the local file, * to denote any hw1. file and then the location on the remote.
93+
94+
### `Output:`
95+
96+
![](../../unix-fun/task2.2.png#center)
97+
98+
## Item 3: decompress the tarballs
99+
100+
### Command:
101+
102+
`for f in *.gz; do tar -xvf “$f”; done`
103+
104+
Loop through files ending in .gz and run the command “tar -xvf {file}” until the loop finishes.
105+
106+
### Output:
107+
108+
![](../../unix-fun/task2.3.png#center)
109+
110+
![](../../unix-fun/task2.3(2).png#center)
111+
112+
# Task 3:
113+
114+
## Item 1: List the contents of the "hw1.1" directory using the "ls" command
115+
116+
### Command:
117+
118+
`ls -latrh`
119+
120+
ls, list command, -l is long listing, -a is show all files(show hidden), -tr is sort by time and then reverse, finally -h is human readable for the size of files.
121+
122+
### Output:
123+
124+
![](../../unix-fun/task3.1.png#center)
125+
![](../../unix-fun/task3.1(2).png#center)
126+
127+
## Item 2: Run the following command "cat /usr/share/dict/words | grep -i hello > /tmp/words.log"
128+
129+
### Explanation:
130+
131+
This command is using the cat command to display the contents of /usr/share/dict/words to stdout but the “|” redirects this output to the input for the grep command, the -i is to have grep ignore the casing of the letters in the file, “hello” is the string we are searching for with grep, the “>” means we are going to write this output to a file, in this case /tmp/words.log.
132+
133+
### Output:
134+
135+
![](../../unix-fun/task3.2.png#center)
136+
137+
## Item 3: Copy the file numbers.txt from the current directory to the java subdirectory
138+
139+
### Command:
140+
141+
`cp numbers.txt ./java/`
142+
143+
Cp command is copy and then SOURCE DEST, in this case numbers.txt is in the current directory so just put the file name. Then DEST is ./java/ to show . is current directory and java/ shows it is a directory and then nothing after the last / means keep the file named numbers.txt
144+
145+
### Output:
146+
147+
![](../../unix-fun/task3.3.png#center)
148+
149+
## Item 4: Rename the file Burrot.java to Borat.java
150+
151+
### Command:
152+
153+
`mv Burrot.java Borat.java`
154+
155+
mv command to “move” the file from Burrot.java to Borat.java, in this case renaming it.
156+
157+
### Output:
158+
159+
![](../../unix-fun/task3.4.png#center)
160+
161+
## Item 5: Delete the files diff.html and diff.css
162+
163+
### Command:
164+
165+
`rm diff.*`
166+
167+
Remove files with the start of “diff.” and the * the is a wildcard to remove any file type matching “diff.”
168+
169+
### Output:
170+
171+
![](../../unix-fun/task3.5.png#center)
172+
173+
## Item 6: List all web page files (files whose names end with the extension .html or .css) in the current directory.
174+
175+
### Command:
176+
177+
`ls -- *html *.css`
178+
179+
List the -- is a shorthand for name of file. Then *.html looks for any files html files and *.css looks for any css files.
180+
181+
### Output:
182+
183+
![](../../unix-fun/task3.6.png#center)
184+
185+
## Item 7: Copy all the text files (files whose names end with .txt) from the current folder to the website subdirectory
186+
187+
### Command:
188+
189+
`cp *.txt ./website/`
190+
191+
Copy any files with the ending .txt to the . current directory website directory.
192+
193+
### Output:
194+
195+
![](../../unix-fun/task3.7.png#center)
196+
197+
## Item 8: Display the contents of all files whose names begin with verse and end with the extension .txt
198+
199+
### Command:
200+
201+
`cat verse*.txt`
202+
203+
Cat to display the contents of files. Then verse is the start of the file and * to match anything after and then .txt to match the ending of the file.
204+
205+
### Output:
206+
207+
![](../../unix-fun/task3.8.png#center)
208+
209+
# Task 4:
210+
211+
## Item 1:
212+
213+
### Command:
214+
215+
`sort -u animals2.txt | head -n 16`
216+
217+
sort command, -u for uniqname removes duplicates, animals2.txt is the file put in an argument, piped to head -n 16 to show the first 16 items out the output.
218+
219+
### Output:
220+
221+
![](../../unix-fun/task4.1.png#center)
222+
223+
## Item 2: Combine the contents of files verse1.txt, verse2.txt, and verse3.txt into a new file lyrics.txt
224+
225+
### Command:
226+
227+
`cat verse*.txt > lyrics.txt`
228+
229+
cat all files that match verse(wildcard).txt and write that to lyrics.txt
230+
231+
### Output:
232+
233+
![](../../unix-fun/task4.2.png#center)
234+
235+
## Item 3: Display all lines from animals.txt that contain the word "growl" ignoring case, in reverse-ABC-sorted order and with no duplicates. Output the lines themselves only.
236+
237+
### Command:
238+
239+
`sort -ur animals.txt | grep -i growl`
240+
241+
sort -ur to sort animals by unique and in reverse order, pipe that output to grep -i to ignore case of target string “growl”
242+
243+
### Output:
244+
245+
![](../../unix-fun/task4.3.png#center)
246+
247+
# Task 5:
248+
249+
## Item 1: Set the file example1.txt in the current directory so that its group and other can write to the file.
250+
251+
### Command:
252+
253+
`chmod go+w example1.txt`
254+
255+
Change modification of g (group) and o (other) + adds w (write) permission to the example1.txt
256+
257+
### Output:
258+
259+
![](../../unix-fun/task5.1.png#center)
260+
261+
## Item 2: Set all files with extensions .dat and .doc to be read/writable (but not executable) by their owner, and to have no access from others.
262+
263+
### Command:
264+
265+
If you know the current permissions:
266+
267+
`chmod go-r *.dat *.doc`
268+
269+
Chmod g(roup) o(other) - (remove) r(ead permissions)
270+
271+
If you don’t know the current permissions:
272+
273+
`chmod u=rw,go= *.dat *.doc`
274+
275+
Chmod u(ser) set to r(ead)w(rite), g(roup)o(other) set to nothing on all dat and doc files.
276+
277+
### Output:
278+
279+
![](../../unix-fun/task5.2.png#center)
280+
![](../../unix-fun/task5.2(2).png#center)
281+
282+
## Item 3: How many users exist on this Linux system that use the Bash shell by default?
283+
284+
### Command:
285+
286+
`grep “/bin/bash” /etc/passwd | wc -l`
287+
288+
grep for string “/bin/bash” in the passwd file, pipe that output to wc (word count) and -l is for newline count.
289+
290+
### Output:
291+
292+
![](../../unix-fun/task5.3.png#center)
293+
294+
## Item 4: Create a file foo.txt using the “touch” command. Change the file's last-modified date to be January 4 of this year at 8:56am
295+
296+
### Command:
297+
298+
`touch -t 01040856 foo.txt`
299+
300+
touch -t to set time modified and then 01 is for January, 04 is for the 4th of January, 08 is for 8am, and 56 is for 8:56am, foo.txt is the name of the file.
301+
302+
### Output:
303+
304+
![](../../unix-fun/task5.4.png#center)
305+
306+
# Conclusion:
307+
308+
I very much enjoyed this assignment. I took an Intro to Linux class at my local community college while I was in high school and this took me right back there. I think having the ability to work quickly in the command line is a great skill to have. My recommendation is that people take a look at these two websites/talks/courses if they are interested in the same topics:
309+
310+
* [https://missing.csail.mit.edu/](https://missing.csail.mit.edu/)
311+
* [awk sed grep slides](https://bpb-us-e1.wpmucdn.com/sites.psu.edu/dist/4/24696/files/2024/07/psumac2024-Awk-sed-grep-Together-we-can-change-anything-compressed.pdf) and [awk sed grep talk video](https://youtu.be/axmDzoUov_8)
312+
313+
As you may be able to tell I’m very interested in the “poweruser” type of things so this was a nice exercise. I think so far these topics and skills is something that all computer science students should have within in their first or second year.

static/unix-fun/task1.1(2).png

839 KB
Loading

static/unix-fun/task1.1.png

501 KB
Loading

static/unix-fun/task1.2(2).png

315 KB
Loading

static/unix-fun/task1.2.png

733 KB
Loading

static/unix-fun/task2.2.png

448 KB
Loading

static/unix-fun/task2.3(2).png

926 KB
Loading

static/unix-fun/task2.3.png

889 KB
Loading

static/unix-fun/task3.1(2).png

827 KB
Loading

static/unix-fun/task3.1.png

900 KB
Loading

0 commit comments

Comments
 (0)