9 ms·
Linux Command One-Liners
- j0057 6y agoUsing conditional includes in your global gitconfig based on the path is a much less error prone way of having different identities for different projects. https://www.motowilliams.com/conditional-includes-for-git-config https://www.motowilliams.com/conditional-includes-for-git-co...
- wruza 6y ago>_ This part will likely confuse people who are not familiar with shell and will create a bunch of thousands "_" files worldwide. Quick explanation: >_ echo hello or equivalently: echo hello >_ when executed in a shell creates a file named "_" with contents of "hello". Author seems to use ">_" as a terminal icon, but many will copy it as part of a command. That is, if I'm not missing anything clever here. Upd: copy button doesn't copy the >_ part, so the "icon" theory seems to be correct.
- 0xf8 6y agoalso it’s called a shell prompt for what it’s worth.
- kps 6y agoA ‘trick’ for fancy prompts containing information is to give them the form, : all the stuff; As long as ‘all the stuff’ is parseable as shell words (which you can ensure by quoting with printf '%q' if there's doubt), then you can copy and paste entire lines. The trivial copyable prompt would be :;
- chrisweekly 6y agoThank you for this!! TIL. Immediately adopting. Now wishing everyone else knew this too.
- kps 6y agoI read about this long ago, possibly in the Blit era, possibly in ;login: (other order, other reasons). It's old lore, but not widely known, so I try to mention in when the subject of prompts comes up.
- Arnavion 6y agoNote that this isn't guaranteed to be a no-op for arbitrary "all the stuff". Specifically it won't work for commands involving pipes, or commands involving command substitution / process substitution. That is: : bar "$(foo)" : bar <(foo) : < <(foo) bar : bar | foo will all still execute `foo`
- kps 6y agoThat's why I mentioned quoting.
- loudmax 6y agoAgreed, including the ">_" prompt in the command line isn't really helpful. The copy icon works, it's extra unnecessary cognitive overhead. Also, ">_" is an unusual prompt, I don't know what distro ships with that by default.
- LukeShu 6y ago">" is the prompt on MS-DOS, and "_" is the cursor. Somehow this has resulted in ">" or ">_" being the terminal "icon" even in unixy parts of the world; looking at the generic "utilities-terminal" icon: the default theme for Gnome 3 ("Adwaita") uses ">_" in the icon, the default theme for KDE ("Breeze") uses ">", and the runner-up ("Oxygen", which also comes bundled with KDE), also uses ">_".
- scarmig 6y agoAlso, the SSH app on Chromebooks.
- marcosdumay 6y agoThat's unfortunate, because on Linux the shells tend to use ">" for a continuation prompt, where you can not enter complete commands.
- tasuki 6y agoYes, I wonder what benefit there is to include `>_` as the prompt. The obvious drawback is confusing some poor souls. Also it's ugly, who would want to use `>_` as their prompt?
- roosgit 6y agoIt could have at least a less prominent color. And it could be added with a `::before` pseudo-element so you can't select it (just for decoration). Might be also annoying for screen readers without `aria-hidden`.
- bluedino 6y agoAm I some sort of weirdo because I don't recall seeing >_ used before as a prompt?
- prionassembly 6y ago_ is the blinking cursor. Prompt is just >
- bluedino 6y agoBut it doesn't blink.... > is kind of and odd prompt as well.
- tomcooks 6y agothe author should hide that "> _" by including it as a CSS :before or :after content, which by definition is not selectable.
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here. I did a quick fix and replaced ">_" with "$". I will dig into CSS :before during the next update. Thanks for the idea.
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here. You are 100% right. That was quite dump. I think I got the idea from the SSH icon I used in the basics page. Replaced ">_" with "$". Looks much better and I also updated some of the design and content on the site. Update is live.
- timdaub 6y agoGreat idea! Already found some useful oneliners. Actually I do a similar thing by collecting useful commands in a git repository: https://github.com/TimDaub/commands https://github.com/TimDaub/commands
- pw6hv 6y agoNitpick but the icon for GIT is actually that of Github. These should be used instead: https://git-scm.com/downloads/logos https://git-scm.com/downloads/logos
- pw6hv 6y agoThe comment above referred to the URL before they changed it to command-fu. The previous URL was: https://linuxcommandlibrary.com/basic/oneliners.html https://linuxcommandlibrary.com/basic/oneliners.html
- spiderfarmer 6y agoThe oneliners are very useful, but the design of this website is awful. The content deserves better.
- lgeorget 6y agoYeah, I hate being that kind of guy but seriously... oneliners displayed over 5 lines because the columns are very small, commands in dark red on black...
- drran 6y agoTry this interface: https://www.commandlinefu.com/commands/browse https://www.commandlinefu.com/commands/browse
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here. Reasonable feedback. The design isn't great and can only get better from here one. I pushed some quick design updates with a new standard font, decreased the font size for the headline, slightly bigger columns and some other fixes and improvements
- gpmcadam 6y agoSee also: https://www.commandlinefu.com/commands/browse/sort-by-votes https://www.commandlinefu.com/commands/browse/sort-by-votes
- hyper_reality 6y agoNice list, here are suggestions for improving a few of the commands: Generate Random Passwords >_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6 This produces a 6-character password which only has 35 bits of entropy. It also doesn't print a newline, causing the password to be on the same line as the next prompt. Better to use something like: >_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12 && echo Or the "pwgen" utility which can do this for you. Find the process that is using a certain port e.g. port 3000 >_ lsof -P | grep ':30000' This command will be extremely slow on large systems with a lot of open files. It is essentially listing every open file (the -P flag just inhibits port mappings from e.g. "port 22" to "SSH") and then grepping the output. Much better to run: >_ lsof -i :30000 Which is not only shorter, but much faster as it directly gets info about that port. Add your public SSH key to a server in one command >_ cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys' This is what the "ssh-copy-id" utility, which is part of the openssh-client package, does already. Harder, Faster, Stronger SSH clients >_ ssh -4 -C -c blowfish-cbc All three of those points are debatable with that command. Just use the defaults.
- deleted 6y ago[deleted]
- rovr138 6y ago>_ find . -empty -type d -exec rmdir {} + alternative >_ find . -empty -type d -delete
- chasil 6y agoPlease don't use -exec. Use -print0 and xargs -0 instead, as it's much safer, and correctly passes newlines and other problem characters. Even BSD adopted this idiom. GNU find says this very specifically: "There are unavoidable security problems surrounding the -exec action..."
- rovr138 6y agoI'm pretty sure it's a bit faster too. Or for some reason I moved to it.
- raptortech 6y ago+1 for content -1 for formatting. Can we at least get a monospace font here?
- skinnyasianboi 6y agoThanks for the feedback. sans-serif is the new standard font. Looks better you were right.
- Foivos 6y ago>_ cat <file> > /dev/null It mentions that this command loads the file to RAM for faster usage. I do not understand how this works. How do you access the "RAM version" of the file. Also, I thought that /dev/null was just an "abyss" you would send unwanted outputs.
- rovr138 6y agoBecause you read the file, until the ram doesn't get purged, the file will be cached there (assuming it all fits)
- augusto-moura 6y agoMaybe is relying on the linux caching the file in memory? Then if you read it again is already in memory. If so I don't think it is particularly useful, given that using the file anyway already puts it into the cache for later use And yes, /dev/null is a abyss and everything written in it is discarded
- butterthebuddha 6y agoSee https://tldp.org/LDP/sag/html/buffer-cache.html https://tldp.org/LDP/sag/html/buffer-cache.html.
- dspillett 6y agoYou can't specifically access the cached version, but the OS will (assuming the file isn't too large) remember the blocks read from disk in the cache for a while (until the memory is needed by something else) so that next time the file is ready those blocks do not need to be read from disk. This can make a huge difference on traditional drives. /dev/null is the abyss, but the cat command will read all the blocks comprising the file from the filesystem before sending them to that abyss. You can see the effect like so: dspillett@swann2:/tmp$ time cat a.bigish.file > /dev/null real 0m3.830s user 0m0.000s sys 0m0.468s dspillett@swann2:/tmp$ time cat a.bigish.file > /dev/null real 0m0.165s user 0m0.004s sys 0m0.164s dspillett@swann2:/tmp$ time cat a.bigish.file > /dev/null real 0m0.148s user 0m0.000s sys 0m0.144s (if "a.bigish.file" has only just been created, it will likely already be in RAM, run sync; echo 3 > /proc/sys/vm/drop_caches as root or other privileged user to clear the not-currently-active cache & buffers, or chose an older file) (note though that this clears all cache machine-wide, not just cached information from your current session)
- X86IpodInsame 6y agoWired
- cestith 6y agoI'm unsure what the "sort dotted quads" one-liner is really supposed to buy you. Yes, you can define multiple keys and all that. But an IPv4 address in dotted notation is literally indistinguishable from a multi-part semantic version number. sort -V
- asicsp 6y agoHere's some more lists (better formatted) * http://www.compciv.org/unix-tools/ http://www.compciv.org/unix-tools/ * https://www.commandlinefu.com/commands/browse/sort-by-votes https://www.commandlinefu.com/commands/browse/sort-by-votes * https://linoxide.com/linux-how-to/linux-commands-brief-outline-examples/ https://linoxide.com/linux-how-to/linux-commands-brief-outli... * https://github.com/learnbyexample/Command-line-text-processing https://github.com/learnbyexample/Command-line-text-processi... --> this is my own repo on text processing commands like grep/sed/awk/sort/pr/paste/etc Bonus: * https://github.com/jlevy/the-art-of-command-line https://github.com/jlevy/the-art-of-command-line * https://stackoverflow.com/questions/68372/what-is-your-single-most-favorite-command-line-trick-using-bash https://stackoverflow.com/questions/68372/what-is-your-singl...
- nikisweeting 6y agoAlso https://docs.monadical.com/s/system-monitoring-tools https://docs.monadical.com/s/system-monitoring-tools
- tug0fwar 6y ago> Get your external IP address > > >_ curl ip.appspot.com IMHO, entries like this are misleading for a beginner (a bad apple in the basket)
- pbhjpbhj 6y agoWhy misleading? I use `curl icanhazip.com` pretty regularly. Are you considering security issues of echoing the content to the console, or is something else the matter?
- mkovach 6y agoThere is an easy way to display re-display a lines with a time stamp. While I enjoy seeing people awk, the command is a bit terse. Instead I recommend something like: tail -f /some/file | perl -nle 'print scalar(localtime),":",$_' and it a bit easier to type IMHO.
- reacweb 6y agoI fully agree: each time a command in awk or sed or bash becomes complex, it is the right time to switch to perl. Perl does not have all the limitations of (awk, sed, bash) while having concise syntax.
- tchelow 6y agoIts always good to have a cheat sheet
- tomkat0789 6y agoThese are neat, but is there an explanation for how/why these actually work? (Joke alert!) What sort of n00b just copies and runs random shell commands from the internet without understanding them? (End 'joke)
- danso 6y agoI still primarily rely on StackOverflow for most of my shell one-liner needs, but I've found it extremely helpful to make a list/spreadsheet of the commands I repeatedly find myself having to google: https://github.com/dannguyen/bashfoo#toc https://github.com/dannguyen/bashfoo#toc
- pbhjpbhj 6y agoI save all my history and have a little script to grep it for commands I've used. There was a thread on here about a shell add-on that would recommend one-liners, but I can't recall it ... anyone have any ideas? Also I'd like a more robust version of my saved commands history (after 10 years or so it's getting to be like I want to make it a bit slicker), maybe backed by sqlite or something. Any suggestions?
- BenjiWiebe 6y agoDo you know about ctrl-R? At the prompt in bash, it lets you search your previous commands and edit and run them right there. Combined with a large HISTSIZE it's really useful.
- pbhjpbhj 6y agoYes, thank you. Also starting to type a command and using up-arrow to scroll through (I assume) endings of that command line that are in history. That's great too. But I often don't do, say,a do-release-upgrade (I use Kubuntu but prefer command line upgrade) within the time the command stays in history.
- hosteur 6y agoThis seems to be a rip off of https://www.commandlinefu.com/ https://www.commandlinefu.com/ In fact, I just checked a few commands and descriptions on this site, and they are identical in formulation of both the command and the description. Also, one of the first commands on this site is: New Maintainer for CommandLineFu >_ mail tech@commandlinefu.com Why would it even mention this other site's name here unless it was a complete copy/paste of the commands from the other site?
- asicsp 6y agoOh wow, can we get the link changed to https://www.commandlinefu.com/ https://www.commandlinefu.com/ instead?
- SPBS 6y agohttps://www.commandlinefu.com/commands/view/25015/display-information-about-the-cpu https://www.commandlinefu.com/commands/view/25015/display-in... Wow it looks like every thread is full of spam comments, really unfortunate.
- goe1zorbey 6y agoSEO playing dirty. They have injected random content and a link. Most probably, they are profiting the reputation of commandlinefu.com, trying increase the google score of their sites.
- Aperocky 6y agotbh both sites UI is extremely user unfriendly. I'd rather search google.
- Yajirobe 6y agowhich one came first?
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here Yes I used the https://www.commandlinefu.com/site/api https://www.commandlinefu.com/site/api to get the data. I should have mentioned it on the site. And I will add in in the next update. https://linuxcommandlibrary.com/basics.html https://linuxcommandlibrary.com/basics.html has also lots of other info/tips to offer not just the one liners so it's not just a rip off of the particular website :)
- gpanders 6y agoI wrote a shell script [1] that allows me to write my own mini-man pages to capture things exactly like this. Whenever I have to do something non-trivial on the command line that I will 1) likely need to do again at some point and 2) don’t do often enough to commit it to memory, I simply create a new little note. They are viewable in the terminal just like normal man pages so the notes are trivial to read once written. It’s worked extremely well for me! [1]: https://git.sr.ht/~gpanders/ual https://git.sr.ht/~gpanders/ual
- tobib 6y agoNice, this is exactly what I needed. I had my one liners in Notable to look them up but this is way more seamless AND it integrates great with Notable at the same time with the UAL folder in the Notable notes directory and a slightly more complex UAL "edit" to add the Notable metadata.
- ape4 6y agoThere seems to multiple `rename` commands - messy. https://wiki.linuxquestions.org/wiki/Rename https://wiki.linuxquestions.org/wiki/Rename
- aruggirello 6y agoBTW: > Remove all spaces from all files in current folder should really be "from all file names".
- clktmr 6y agoIt would be nice to have these available as snippets on the command line with fuzzy search.
- NoSalt 6y agoI LOVE stuff like this. Thanks!
- tartoran 6y agoThese are great but, ideally one shouldn't have to leave the command line to get a cheatsheet, it would be great to get a TUI and scroll through bash snippets right from the command line. Is there such tool?
- humanistbot 6y agoI'd link to this site sorted by votes, rather than sorted by new: https://www.commandlinefu.com/commands/browse/sort-by-votes https://www.commandlinefu.com/commands/browse/sort-by-votes
- skinnyasianboi 6y agoAuthor of linuxcommandlibrary.com here. Thanks! That's how it actually was in the past. Makes a huge difference. Fixed it.
- mraza007 6y agoI love the site, I was looking for something similar a while ago and I guess I found it today. As I spend most of my time in command line this website can really teach me new ways
- chairmanwow1 6y agoI think we should change the link to sort by votes all-time [1]. It's just fun to go through and see some of this stuff. The longer I use the terminal, the more of its power I come to respect. There's so many tools, so many parameters for each tool. It takes a really long time to build up muscle memory of what things you can do and remembering how to do them in that perfect situation. Recently I've been trying to take at least 20 minutes a day to try and do things the tricky way by stringing these commands together. It's fun and the productivity wins of being able to string together several of these things in a pinch is fantastic. Although it's definitely more fun than useful at this point~ [1] https://www.commandlinefu.com/commands/browse/sort-by-votes https://www.commandlinefu.com/commands/browse/sort-by-votes
- 0x4164 6y agohttps://pastebin.com/raw/PbFCZc6K https://pastebin.com/raw/PbFCZc6K
- bla3 6y agoDoes anyone have the original link this was submitted as? I looked at it earlier today and thought I should look at it again later but now it points to much less interesting commands.
- skinnyasianboi 6y agoThere you go :) https://linuxcommandlibrary.com/basic/oneliners.html https://linuxcommandlibrary.com/basic/oneliners.html
- ogre_codes 6y agoProbably my favorite MacOS one liner (which is slightly different on Linux) is recursive search and replace) find . -name "*.tsx" -exec sed -i "" -e "s/SomeVariable/ReplacementVariable/g" {} + Use this so much with refactoring. Also... wish HN supported at least a bit of markdown.
- rovr138 6y ago2 spaces is a code block - https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc
- ogre_codes 6y agoThanks It's like the bad-old days where every site had it's own markup though
- iblaine 6y agoMy most obscure cool one liner... 1. Pointing your webserver to your current directory. Simplifies copying files to your local box. The simple python 3.x way... python -m http.server 8001 And the original way I used to do it... function sfiles() { x=`ipconfig getifaddr en0`;echo $x:8001;ruby -run -ehttpd . -p8001; } And please use this with *extreme* caution because any files you've got access to on your remote box will have no authentication when they're exposed via HTTP. My most frequently used one liner... 2. Regex searching files in directories. grep -inR <keyword> * The Silver Searcher, aka ag, is better but not natively installed so...