casey Profile picture
8 Sep, 18 tweets, 4 min read
Wanna up your Linux game?

This will be an evolving 🧵 of commands I learn about today and the resources used ⬇️
1. awk

awk is used for text manipulation within the command line.

A common use is specifying what kind of information you want to pull from a file or command output.
Example:

The who command returns currently logged in users of the system, as well as other information. What if we only wanted to see the users, without extra information? We could use awk like this, knowing the user is the first parameter in who output:

who | awk '{print $1}'
Want more than one parameter?
Specify using commas: awk '{print $1,$2}'

Want to specify how to separate the outputted parameters?
Use OFS, or Output Field Separators: awk 'OFS="/" {print $1,$2}'
(this would separate $1 and $2 with a /)
Those are some basics for getting started with awk, and there are additional ways to get more specific through functions, pattern matching, and more.

I started here:
howtogeek.com/562941/how-to-…
2. sed

sed, which stands for stream editor, is used for file manipulation straight from the command line without having to actually open the file.

Quick actions on the file, like word or character replacements, can be done without having to use vim, emacs, nano, etc.
Example:

Replace ab with ba in letters.txt:
sed 's/ab/ba' letters.txt

What if we want to replace the pattern only on line 4?
sed '4 s/ab/ba' letters.txt

What if we want to replace starting from a certain occurrence, say the second one, on a line?
sed 's/ab/ba/2g' letters.txt
Let's cover printing real quick as well:

What if we want to see replaced lines? Add /p. /p will print duplicates of replaced lines and single instances of non-replaced lines, so use the -n flag to remove duplicates and non-replaced lines.

sed -n 's/ab/ba/p' letters.txt
Those are some sed basics. You can learn more here about fancier and more specific replacement strategies, as well how to insert to or delete from a file:
geeksforgeeks.org/sed-command-in…
Correction to above example (thank you @BasementTrix!):

Make sure to include the trailing delimiter (slash) after the pattern replacement.

i.e. sed 's/ab/ba/'
@BasementTrix 3. grep

grep, which stands for globally search for regular expressions and print out, searches for specified character patterns.

grep is a valuable search tool.
If you're familiar with the find command, you may wonder how find and grep differ. While grep searches for regular expressions in files and processes, find will search through files and directories using other filters, e.g. size.

Good explanation here:
stackoverflow.com/questions/4316…
Example: let's search for 'ac' in things.txt

grep ac things.txt

Example output could look like:
mac
tictac
accountant

Want to search for something with multiple strings? Add single quotes around them like so:

grep 'two strings' things.txt
grep is case sensitive. Want to ignore case sensitivity? Use the -i flag.

grep -i ac things.txt

Want to match the pattern only at the start of words? Use ^[pattern]

grep ^ac things.txt

Want to match the pattern only at the end of words? Use [pattern]$

grep ac$ things.txt
Want to match an exact word, not words containing the word/pattern? Use -w

grep -w ant things.txt

(this would return the word ant, but not antsy)

Want to search through multiple directories? Use -r

grep -r ant .

(this would search every directory under your current location)
egrep is extended grep. It's the shorthand version of using the -E flag; egrep = grep -E

It adds some extra grep functionalities.

One major use is searching for multiple options using |

Examples:
egrep -w 'firstword | secondword' file.txt
egrep '^(a | b)' file.txt
grep has a lot of power, so definitely check out more of what you can do with it. Here's where I started:
cyberciti.biz/faq/howto-use-…
This is it for today, let me know if this was useful and I could do more in the future.

Happy Linux’ing!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with casey

casey Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @varcharr

7 Sep
Interview advice for people getting into tech 🧵 ⬇️
1. Know main points about the company.

When interviewing all around, this can be hard. But know the main things. Does it make a product? Know what the product is and does. Does the company have a specialty expertise? Know what it is. This is a simple first hurdle to prepare for.
2. Know how to sell yourself.

Interviews often start with “tell me about yourself”. Know your strengths. Know your accomplishments. Know your passions. Know what you’re interested in (multiple things is okay, esp when you’re earlier career!). Be able to be concise & to expand.
Read 13 tweets
7 Sep
Potentially unpopular opinion:

Patching is not a sustainable security solution.
There are two groups impacted here:

1. Infrastructures/orgs/companies/etc

2. Individual users
What’s the solution?

Something that doesn’t rely on a reactive response to finding susceptibilities. It’s not realistic for users, and it’s a race for groups against their adversaries.
Read 6 tweets
28 Aug
This.

As an earlier career woman in tech, being told titles don’t matter by men already at the top of the ladder feels so dismissive.

Especially when other conversations revolve around how they “know I’m technical and want others to know it too”.

That’s what titles are for.
In fact, I’ve been told that being a technical lead too early (despite being qualified and requested for the position) would make others question if I actually had the technical chops.

That being a TECHNICAL lead would make people question my TECHNICAL abilities.
Male colleagues with my same experience had become technical leads no problem.

If a woman is a technical lead and you assume she’s just leading because she doesn’t have the technical abilities, and you don’t think the same of dudes, that is a YOU problem. Not a me problem.
Read 4 tweets
27 Aug
Let's talk data privacy guilt.

Are we doing enough to protect our data? Are we responsible for our data being collected and used? Is it bad to depend on big tech?

🧵⬇️
Everyone has some amount of awareness, on a scale of little to lots, about how our data is collected and used by the technology we use.

Yes, even the least tech-savvy people. They know that passwords can be stored, they like the ads they see, and map apps require location.
Then there's the other side, with tech and infosec professionals. We talk about data privacy and security and protect data for a living. What are we doing in our personal lives? Are we implementing what we know? Are we able to teach others how to protect their data?
Read 12 tweets
26 Aug
Things not (normally) taught in computer science curriculums that should be included, a 🧵 ⬇️
1. Secure coding

Not just taking off points when students submit code with security flaws, but proactively teaching why certain practices will provide said flaws. Help them recognize insecure coding practices. Understanding security is a critical aspect of sw engineering.
2. Documentation

Comments may be required in code for beginning level classes but they’re even more important in later classes where code gets complicated and single characters can change code’s ability. This is esp important when students may just be taking shots at solutions.
Read 8 tweets
25 Aug
Greatest Hits, the Infosec Remix:

Pinging on a Prayer
Monster Bash
Highway to Shell
We Didn’t Start the Dumpster Fire
Bring Vi to Life
I write /bins not tragedies
Thanks for the Memory
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(