11 ms·
Linux Terminal Tools [pdf]
- MR4D 5y ago103 pages of Linux commandline goodness! Nice overall reference, especially the parts on regex and awk. Table of Contents (for those who hate PDFs): Part 1: Overview and Logistics • Part 2: Basics • Part 3: Streams, pipe and redirection • Part 4: Classic Tools: find, grep, awk, sed • Part 5: Session Management: tmux • Part 6: ssh: config and tunneling • Part 7: Secure Communication with GnuPG • Part 8: Bash Tools • Part 9: Program Development Tools • Part 10: Miscellaneous Utilities • Summary • Practice and Exercises (if time permits else Offline)
- anotha1 5y ago> use ctrl-y to paste back the deleted TIL
- TheCowboy 5y agoEmacs yank. If you're familiar with Emacs or Vi then you might already know some shortcuts. https://unix.stackexchange.com/questions/85390/what-is-meant-by-a-shell-is-in-vi-mode-or-emacs-mode https://unix.stackexchange.com/questions/85390/what-is-meant...
- dundarious 5y agoThis function will fail when given an argument with a space, which would be quite frustrating for a beginner, which is presumably the target audience for such a document: > mcd() { mkdir -p $1; cd $1 } It should be more like: > mcd() { mkdir -p "$1"; cd "$1"; } The trailing ";" is also required in bash for oneline blocks like this. Same goes for most of the other functions on page 70. "$@", etc. Just trying to make the learning experience less frustrating, not trying to tear down the effort :)
- ketanmaheshwari 5y agoAh thank you! I will fix it.
- deleted 5y ago[deleted]
- sandreas 5y agofunction mkcd() { mkdir -p "$@" && cd "$1"; } supports multiple dirs and cd to the first one mkcd a b c
- enriquto 5y agoa beginner would not likely quote the argument, so the point is moot... besides, what kind of savage wants a directory name with spaces?
- hpcjoe 5y ago(looks at all his directories which are written as phrases and ...) [raises hand] This type of savage?
- dundarious 5y agoTrue, they'd have to learn how to use arguments with spaces in the shell -- but this won't necessarily happen near the time they add mcd to their .bashrc, which may lead to frustration with customization, and stifle the desire to learn. Something to be avoided when it is simple and easy to do so.
- yjftsjthsd-h 5y ago> a beginner would not likely quote the argument, so the point is moot... But a beginner could still tab-complete file names and get them automatically backslashed.
- deleted 5y ago[deleted]
- je42 5y agoit probably makes sense to use "&&" instead of ";": if mkdir -p fails cd is still being executed.
- pjungwir 5y agoIf we're being picky then you probably also want `mkdir -p -- "$1"` in case they want to create a directory named `-m`, `-v`, etc. Surprisingly `--` isn't mentioned in the mkdir manpage on my system, but it works. E.g. `mkdir -- -p` does what you'd want.
- a1369209993 5y agoStrictly speaking you want `mkdir -p "./$1"`, although the failure modes of `--`-ing arguments aren't as immediately demonstratable as those of not deflagging them at all.
- dundarious 5y agoYou definitely don't want to universally add the "./" prefix because it breaks on absolute paths. The only solution is for users to add the "./" prefix themselves when the path begins with "-", because many BSD userspaces don't support "--" as a marker to stop option parsing. Maybe that doesn't matter for a document with Linux in the title, but given the popularity of macOS for doing Linux development, I would still err on the side of supporting the BSDs for such things. Never mind that support for "--" outside GNU is very spotty, even on Linux. There is no point, in my opinion, in trying to be smart in small shell helper functions. It should just do a simple, relatively foolproof series of commands, and usually, bail early on error. But the intersection of `mkdir -p` failures and `cd` successes is tiny, so I didn't even bother muddying the waters by suggesting another alteration to use `&&`.
- fiddlerwoaroof 5y agoI still do this reflexively but zsh doesn’t word-split variable expansions, so the first version would work as expected. Little things like this have made me prefer using zsh whenever feasible: and, in the age of dockerized everything, there’s few good reasons left to use bash.
- SavantIdiot 5y agoShould include CTRL-Q and CTRL-S, as I've encountered students who accidentally hit CTRL-S instead of CTRL-X and then stare at a hung terminal wonder WTF just happened.
- johnvaluk 5y agoIt's a learning moment for users who press Ctrl-s to save their work due to muscle memory from other environments. That's when they get a crash course in Ctrl-q and screen/tmux.
- SavantIdiot 5y agoCTRL-S in a terminal command-line? That doesn't seem likely as you're never in a "save-mode thought" on the CLI. Funny, I used to have ctrl-s muscle memory, then 10 years of primarily developing on mac got me used to cmd-s since mac keyboards are so annoying. now when i switch between mac/win/linux it's just a constant mess of pressing the wrong special key combos. Almost as bad switching between scripting languages and forgetting if a function starts with func, proc, sub, def, etc... (yes, I know you can swap special keys on mac: i tried it and it creates way more headaches than it solves.)
- ansible 5y agoI'm of the opinion that those should just be disabled these days. Aside from the occasional AMD motherboard that has a very slow scrolling non-text-mode framebuffer, Ctrl-Q and Ctrl-S aren't so useful with the GUI terminal programs or console terminals nowdays.
- gpvos 5y agoI still use them. E.g., for build processes that scroll by just a little too fast.
- deleted 5y ago[deleted]
- yazantapuz 5y agoVery useful! The deletion commands are very handy (i only knew ^U).
- cerved 5y agopdf :(
- ketanmaheshwari 5y agoWould you rather have it in HTML or any other formats? I could perhaps convert to HTML using Pandoc.
- sandreas 5y agoI suggest markdown as base... can easily be converted to PDF, HTML and others.
- leephillips 5y agoThere is nothing wrong with the nicely formatted PDF file that you provided. Don’t listen to these savages.
- r0f1 5y agoNice presentation. I have made my own list, if anyone is interested: https://github.com/r0f1/linuxhelp https://github.com/r0f1/linuxhelp
- periheli0n 5y agoThis! Super helpful. Thanks! I have worked with the command line for 20+ years, still I’ve learnt a ton. Now if this could be compiled on one or two pages in small print, it would make an excellent cheat sheet!
- dafty4 5y agoNeeds to add `apropos`.
- nojito 5y agoLinux shells are so unbelievably painful. I switched over to powershell and the quality of life improvements have been amazing.
- wooptoo 5y agoPerhaps you haven't tried fish shell? https://fishshell.com/ https://fishshell.com/
- johnklos 5y agoIt's a shame that a whole generation of people who want to be IT literate think that this is "Linux". This is Unix. Would we name a map book "A Toyota Roadmap", as if we don't know that there are other cars, and that a map applies to cars, not just to Toyotas specifically? Sure, a map would be different for push scooters (Windows), but a map would be the same for cars and small trucks. It seems petty, but it becomes difficult to make a distinction between what's generally Unix and what's actually specifically Linux when we just call everything Linux.
- ketanmaheshwari 5y agoI think by that analogy the title should have been "Computer Operating Systems Terminal Tools". The tools presented in the slides have been tested on a Linux System, which motivated the title name.
- generalizations 5y agoThat would be incorrect: it's too general. These tools don't apply to Windows; yet some do apply to MacOS, due to its BSD/UNIX (not Linux) roots.
- naikrovek 5y agothere are many ways in which these do apply on Windows, these days. please work on separating the semantics of someone's statement from the pragmatics. don't bother with the "how they phrased it" bit, and instead try to focus on the "what are they trying to say" part more. you may be, like I did all too often in my youth, over-emphasizing English correctness, missing the message being communicated entirely. maybe you're not doing that! maybe you are. only you can know for sure. if you are, then try to work on that. it will help you communicate and it will help others communicate with you. we all grow as people over time, and no one is flawless, and that's fine. just try to be better every day.
- generalizations 5y ago
- snug 5y agoThe secret that I never see brought up on any of the linux command line tools is "esc + ." - It's by far one of the most valuable tricks I've learned, it will insert the last thing from the last command ls /foo/bar/this_is_the_file.txt cat "esc + ." which expands to cat /foo/bar/this_is_the_file.txt
- pinkrobotics 5y agowow, thank you! I did not know this. It will be very useful!
- leephillips 5y agoI’ve used !$ forever to substitute the last word from the previous command, but I never knew about this.
- naikrovek 5y agook this is going to sound stupid, but I don't care. learning time, for me. do you type the literal characters "esc + ." or do you press CTRL+[ then period, or do you push the escape key, then period, or do you push escape and period at the same time? I'm not at a terminal to try any of this and find out for myself.
- snug 5y agoI press and hold escape first then period
- naikrovek 5y agoESC isn't a control code like CTRL or SHIFT or ALT - so holding it while you press another key is weird, to me. But pressing and releasing ESC and then pressing and releasing period works excellently. Thank you.
- snug 5y agoAhh nice, yeah, that works, I always just assumed I needed to hit ESC first, but didn't know they didn't need to be held at the same time
- ammar_x 5y agoI found the navigation shortcuts useful: ctrl-a, ctrl-e, etc.
- gpvos 5y agoGood list. But when you write about xargs, you should absolutely warn that it has problems working with filenames with spaces in them, and the -0 option to fix that.