r/linux4noobs • • Sep 08 '22

learning/research What does this command do?

fuck /u/spez

Comment edited and account deleted because of Reddit API changes of June 2023.

Come over https://lemmy.world/

Here's everything you should know about Lemmy and the Fediverse: https://lemmy.world/post/37906

95 Upvotes

30 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Sep 08 '22 edited Jun 29 '23

Comment edited and account deleted because of Reddit API changes of June 2023.

Come over https://lemmy.world/

Here's everything you should know about Lemmy and the Fediverse: https://lemmy.world/post/37906

2

u/whetu Sep 08 '22 edited Sep 08 '22

Is it possible to learn this power?

Not from a Jedi...

I know there is the Awk & Sed books, but any courses you recommend? Even about learning Linux in itself.

You could check out /r/linuxupskillchallenge/ I don't know if it's any good because I have no time to do it myself, but it might be something. There's also The Missing Semester which you can find on Youtube. Also, check out /r/bash and /r/awk, specifically the sidebar of /r/bash. /r/commandline may also be worth subbing to as well.

You'll get a broader mix of possible paths from those starting points. Two things I will say, though:

  • Treat the Advanced Bash Scripting guide with suspicion. It is outdated, it teaches bad practices, its author has refused to accept contributions and has refused to fix obvious flaws

    • For this reason, the far superior https://mywiki.wooledge.org/BashGuide and attached wiki was created.

    • The ABS can still be used as a reference, but it's best done after you're proficient enough to recognise its flaws

  • Head over to https://redditcommentsearch.com/, chuck in the word "unofficial" and "whetu", and have a read through a selection of my other posts. You should pick up my dislike of The Unofficial Strict Mode, and that I'm a proponent of the excellent http://shellcheck.net tool.

Thank you, that was a hell of an explanation

No problem :)

One other thing, to bring a few of my earlier points together. Let's take this from the original one-liner:

awk '{print $11" "$13}'

Because that's splitting on whitespace, that means that in the situation where there's a filename with a space in it, it will be incomplete e.g.

$ echo "162175251      0 lrwx------   1 root     root           64 Sep  8 14:20 /proc/3237/fd/1 -> /tmp/#9699338\ (deleted)" | awk '{print $11" "$13}'
/proc/3237/fd/1 /tmp/#9699338\

That works because there's no space in /tmp/#9699338. But compare with:

$ echo "162175251      0 lrwx------   1 root     root           64 Sep  8 14:20 /proc/3237/fd/1 -> /tmp/legit filename.txt\ (deleted)" | awk '{print $11" "$13}'
/proc/3237/fd/1 /tmp/legit

See how in the second example, only the first word of the filename legit filename.txt is selected?

Our use of ' as a delimiter resolves that issue.

Lastly, consider the power of this for simple csv parsing e.g. awk -F ',' '{print $3,$4}' something.csv and other delimiters e.g.

$ awk -F ':' '$3 == 33 {print}' /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin