Tips for using Unix terminals

hey Jow Forums
so seeing how retards don't really know how to use a fucking linux terminal triggers me badly, so I'm gonna share some shortcuts/tricks for easy and fast usage of the terminal (for bash and busybox; dunno if all of these work with zsh, ksh, etc.)

- the X server has a secondary clipboard buffer: highlight the text from one program and then paste it somewhere else (the terminal, some textbox in your web browser) by pressing the middle mouse button (or both left and right buttons at the same time)

in the command line:
- ctrl+a makes the cursor jump to the start of the line, ctrl+e goes to the end
- ctrl+w cuts the word behind the cursor, alt+d ctrl+w cuts the word that is next to it. ctrl+u cuts everything before it, ctrl+k. and this one is important: use ctrl+y to paste what you just cut...
- press ctrl and the left/right arrow keys to jump from word to word
- cltr+r will search for commands previously used
- alt+dot multiple times will paste the last argument from the previous commands used
- you don't need to join a directory to know what's in it; simply type ls /path/to/directory. if you want to join "/path/to/directory" right after running that command, type alt+.
- you can temporarily change directory by either executing
pushd /path/to/directory; some_command -flags then popd,
or by writing, say
(cd /path/to/directory && some_command -flags)
- grep, sed, cut, etc. can receive a filename as argument; there is no need of typing cat some_file | grep some_regexp when grep some_regexp some_file will work just fine
- 'grep -a' is way faster than 'grep' when grepping text files
- instead of using 'cat' to see the contents of some file, use 'less'. it won't make your console "dirty", you can go back and forth in the text by pressing the prev/next page keys, and can even search stuff with regular expressions simply by pressing / (less doesn't work well in all terminals, though)

Attached: Bash_screenshot.png (562x765, 10K)

Other urls found in this thread:

frippery.org/busybox/
azlyrics.com/lyrics/nirvana/wheredidyousleeplastnight.html
unix.stackexchange.com/questions/223491/piping-a-password-located-in-a-file-to-the-ssh-command/223520#223520
tiswww.case.edu/php/chet/readline/rluserman.html
tldp.org/LDP/abs/html/string-manipulation.html
securitronlinux.com/debian-testing/returning-just-the-interface-name-with-linux/
twitter.com/SFWRedditGifs

thanks user

The only thing I didn't know was the alt+dot shortcut but good post OP

Thx

Based
Request for this to be pinned to the top of the board

not sure what's going on with the Jow Forums servers atm, but I couldn't post this before...

some more tips involving other programs:
- run
python3 -m http.server
or
python -m SimpleHTTPServer
to start a web server in the current directory. you can easily access files from other computers in the LAN this way
- want a lightweight unix-like command line in windows system console? use frippery.org/busybox/ (it supports a few stripped down commands) or install git for windows and use its version of cygwin


how does one remember all this shit? FUCKING USE IT

more useful stuff at
shell-fu.org
commandlinefu.com
hackaday.com/2017/07/21/linux-fu-better-bash-scripting/

you are welcome

>alt+d ctrl+w cuts the word that is next to it
* alt+d cuts the word that is next to it

make sure to practice these commands. seriously, almost every single one of these shortcuts and commands has been useful in my daily use of the terminal.

How do you clear a whole line?
I played around with it and I found out that ctrl + alt + backspace deletes a whole word

To add on to this:

If you put set -o vi in your .bashrc, you can toggle normal mode on with escape and use vi/vim shortcuts.

thanks OP

Didn't know these

>alt + dot
>ctrl + r

>python3 -m http.server

ctrl+c emptys the line and puts you onto a new line, does that work for you?

ctrl+e then ctrl+u, or simply ctrl+c

that's for advanced users, though, and you don't want people to get confused...

a few more things:
- want a short way to list/rename files? use brace expansion. an example (from the manpage):
mkdir /tmp/{old,new,dist,bugs}
will create /tmp/old /tmp/new /tmp/dist /tmp/bugs
and
mv /tmp/{bugs,features}.txt
will rename /tmp/bugs.txt to /tmp/features.txt
- bash itself supports regexp. some examples:
$ touch 1.c 2.c
$ ls ?.c
1.c 2.c
$ A=asd; echo ${A/a/b}
bsd
- want to learn more about bash? read the manpage... bash has LOTS of useful stuff
- and you can search for stuff in the manpages (like when using 'less'), too! type /, then type the string / regex you want to find and then press enter

now I'm going to sleep, so please keep bumping the thread.
later, Jow Forums

>cuts everything before it, ctrl+k.
* ctrl+k cuts everything AFTER it
FTFM

>cd /path/to/directory && some_command -flags
then `cd -` to return back
>instead of using 'cat'
and when you need it, instead of `cat filename` you can do `< filename`

s/manpage/infopage/g
fucking hate info personally, but you cant expect to learn everything about bash from the manpage.

Anyways, Jow Forums thought my first post was hacking them, so Ill try again:
!! is replaced with the previous command
!$ is replaced with the last arg of the previous command
Try googling "job control bash".

The alias creates shortcuts for common commands
e.g. instead of having to type sudo apt, you can
alias apt='sudo apt'
Bonus points if you paste this in your .bashrc file.
Extra bonus points if you paste this in your /etc/bash.bashrc for systemwide aliases.

Attached: 1526765290612.png (930x534, 25K)

>Line editing shortcuts, pushd/popd
Not portable, applies to basically only bash and zsh. Stop talking about "Unix" terminals when you're pretty much only talking GNU, which is as far from UNIX as a *NIX-like gets.
>grep -a
Probably applies to every grep that does a binary file check, but isn't guaranteed to exist.
Also worth to recommend ag or rg at this point if you need really fast grepping.
>use 'less'. it won't make your console "dirty"
Not guaranteed behavior. For example, on OpenBSD, less(1) doesn't clear the screen when exiting. Still good advice to paginate stuff instead of using cat(1) + scrolling since you can search with less(1).

Pro tip: learn to use emacs and then apply knowledge to the bash. Thank me later.

Have you tried most? best pager imo

Same here.
Thanks a lot OP

Attached: d01751e88355716ea54ce69d97259859.jpg (720x960, 54K)

portability is a meme.

How do I pipe a file with a password into an ssh login bash script. I know its dumb but I want to figure out what I need to do

>unix terminals
>os used 50 years ago
>linux terminals
>kernel terminals
>terminal
>a piece of hardware
Please learn proper terminology.

> python -m SimpleHTTPServer
This will work on all distros except Arch, the distro that is BROKEN OUT OF THE BOX

>archfags will defend this

>arch doesn't ship a deprecated interpreter by default
>arch's fault somehow

gonna be satisfying watching the buttwranglement when EL 8 is released without python 2. fucking python 2 is finally dead.

can anyone help me with curl? Azlyrics seems to block requests, is there a way around it?

example:
curl azlyrics.com/lyrics/nirvana/wheredidyousleeplastnight.html

301 Moved Permanently

301 Moved Permanently
nginx

probably their robots.txt
I admit it I'm larping and I use wget I have no idea what I'm talking about but give it a try

Tried using wget, couldn't download either, setting a common user-agent helped. I used
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36" azlyrics.com/lyrics/nirvana/wheredidyousleeplastnight.html
and it downloaded the website with no complaints.

nice, thank you

The equivalent for curl would be curl -LA *user-agent* *url*, the -L is for following redirects.

I came here to post this Vi mode on Bash

If you dont know at least the basic Vi motions then you simply fail with computers and should stay away from Bash and Linux for your own safety

Attached: 1464134161048.gif (400x200, 3.94M)

It's also called emacs mode, compared to the vi mode, that a few people suggest in here, because a lot of these bindings are the same for Emacs, too.

Try Alt-f to do Ctrl-left, Alt-b for Ctrl-right, Alt-n for Ctrl-down, Alt-p for Ctrl-up.
(Just go and read the quick tutorial on Emacs, ffs)
Ctrl-/ is undo BUT it's very... lazy? I'm not sure if/how you can redo stuff. (Maybe I should have another look at the tutorial, too?)
With Ctrl-Space you can "set mark" and select stuff, like you do with your mouse. Not sure if they're saved on the primary or what, though, haven't tested it.

> Alt-n for Ctrl-down, Alt-p for Ctrl-up
I'm a retard. Ctrl-n and Ctrl-p.

fine, you fucking faggots:
Unix-like terminal emulators, mostly the ones used in GNU/Linux

another thing, related to :
want to learn to use vim? install and run vimtutor.
to quit vimtutor, type
ESC : q

also, instead of saving and quitting vim with :wq , use :x


>you cant expect to learn everything about bash from the manpage.
well, when I read the manpage, I usually get info about features from other places (mostly websites) and then look at the correponding section in the manpage.
you are kinda right, though. the manpage is gigantic, and a big ass mess

unix.stackexchange.com/questions/223491/piping-a-password-located-in-a-file-to-the-ssh-command/223520#223520

nice
honestly, I prefer vim as my main editor, though not as a mode in my terminal..

"cd" to go to home dir
~ is your home dir, example: cp /path/file ~
single dot . is the current dir
shift-insert to paste
use nano as an editor if you don't know how to exit vi/vim (and dont want to learn)

>BSDfag comes in and is a fag
color me surprised

> 'grep -a' is way faster than 'grep' when grepping text files
What other type of file would you grep...?

And I've never, ever heard of anyone referring to cd as 'join'. But I'll assume you're just not speaking English natively - since you seem to think there's such a thing as 'prev/next page' keys.
And 'cd -' is the usual way I would do you thing. It's the same as 'cd $OLDPWD'.

Anyway, one thing that Linux weenies do that pisses me off is
>cmd1
>oops! *ctrl-Z*
>fg; cmd2
Like... you can just type 'cmd2' at cmd1 and if it doesn't read from the terminal, what you typed will still be around for the shell to read in when it finishes wait(2)ing on cmd1.
Although I'll grant that Linux-style software design offers no predictability about that sort of thing. ffmpeg, for example, reads from the terminal even though you wouldn't guess it does.

Linux programmers/users are really bad Unix programmers/users.

>- bash itself supports regexp. some examples:
Those aren't regular expressions, they are shell globs. bash *does* support using regular expressions as shell globs, but I never remembered the way of doing it.

>fucking hate info personally,
use `info ... | $PAGER`

>Bonus points if you paste this in your .bashrc file.
I still haven't recovered from using an HDD until mid-2016: I hate the whole concept of shell 'rc' files. Just use the shell profile (.bash_profile for bash) and export -f the functions, and leave the .rc file for things that actually NEED to be in the .rc file.

I'll fall for a part of this bait.

Anything that you run and just hangs there doing nothing, expects an input from stdio. So you should redirect/pipe an input to it, or use a flag, more likely.

>grep *a file*
will never read from the terminal under any circumstance (except the obvious, very artificial, grep /dev/tty), this is true for literally any Unix-style command except ones that derive from ed.

OP here
man, sorry for not knowing the history and every technical detail of Unix systems, and each and every single concept regarding terminal emulators. I've learned most of this stuff by myself, and mostly care about practical stuff, not only about concepts and specially about their names
and, yes, english is not my first language
anyway, thanks for letting people know

>> 'grep -a' is way faster than 'grep' when grepping text files
>What other type of file would you grep...?
you know you can grep binaries, right? and that's the default mode. from the GNU grep manpage:
> File and Directory Selection
> -a, --text
> Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

> --binary-files=TYPE
> If a file's data or metadata indicate that the file contains binary data, assume that the file is of type TYPE. Non-text bytes indicate binary data; these are either output bytes that are improperly encoded for the current locale, or null input bytes when the -z option is not given.

> By default, TYPE is binary, and when grep discovers that a file is binary it suppresses any further output, and instead outputs either a one-line message saying that a binary file matches, or no message if there is no match.
[...]

> Warning: The -a option might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands. On the other hand, when reading files whose text encodings are unknown, it can be helpful to use -a or to set LC_ALL='C' in the environment, in order to find more matches even if the matches are unsafe for direct display.

>Those aren't regular expressions, they are shell globs.
how is the second example not a regexp?

bumpo

this looks kind of dangerous, keep in mind that programs on your computer use these commands and you are giving everything root access

Use a .bash_aliases file

It's not. He's only changing his environment.

use escape . to repeat last typed filename, path, url or whatever.

No it's not. You still need to enter your password

Noted. Thank you

Wow, this is the noob thread.

Bash provides line editing via readline. Everything that uses readline has the same line editing interface and can be configured the same way. Read The Fucking Manual tiswww.case.edu/php/chet/readline/rluserman.html

zsh implements its own line editing, ZLE. It's similar to but completely different from readline.

You should add that to inputrc instead.

None of those are regexps

tldp.org/LDP/abs/html/string-manipulation.html

Everyone in this thread needs to RTFM.

I'm not going to read a 2k page dry, boring manual, fuck you.

Replace all your GUI apps with command line apps and migrate to the terminal. The only way to get good is lots of practice.

Wow, you're a faggot. Did you know bash also allows vim-like and emacs-like line editing? Everyone has to start somewhere. Go be useless somewhere else.

Go do your homework assignment, Jamal. And pull up your pants.

>Did you know bash also allows vim-like and emacs-like line editing?
It's in the manual, literally search emacs and vi in the manual.

>Everyone has to start somewhere.
For most of us, that's the manual. For the rest, that's first grade English class.

I'm aware of 95% of what bash has to offer. I've bought a few books on bash. I use bash on a daily basis. I've moved on to programming. My point was, everyone here is trying to learn and better their understand. Stop being an arrogant cunt.

aaaaannnnddddd you've got yourself an unhardened, unsecured opendirectory...

You'll more than likely forget to terminate the command which means those files are mine.

If you must share at least do some chmod on the folder to make sure

intext:"pics of OP is a poofta's mum" (bmp|gif|jpg|png|psd|tif|tiff) -inurl:(jsp|pl|php|html|aspx|htm|cf|shtml) intitle:"index.of./"

doesn't get used on it.

Attached: sally-bowrey-1117842.jpg (1920x1080, 158K)

>Use a .bash_aliases file
I would assume this has the same problem I mentioned in , i.e. the shell instance opens and reads the file every time you instantiate a terminal, creating a noticable delay. Just use .bash_profile.

He said LAN. Who would expose a directory to the world?

the fuck you on about retard? obviously if you need to share something sensitive, you'd just use scp/sftp/rsync/whatever.

You'd be surprised.

So... OP does like the taste of other men's semen.

Attached: sally-bowrey-1117840.jpg (1920x1080, 153K)

>poorfag can't afford nvme
k

Dude, you have no idea what you're doing or talking about. Just concede.

This was a real problem until very recently. Plainly visible delays before the prompt appearing were a real thing. People wank over Linux but it's not a good operating system.

It was a problem back in the 90's. The relevance today is with SBCs.

OP here
I didn't think making this thread would attract elitists and arrogant retards who think they are superior beings because of their knowledge of bash, unix and other stuff.
I use these tools a lot, but mostly the basic stuff, and most of the time I don't even need advanced shit. also, bash sucks, but for basic things, it's awesome.

then there are people like , who don't even read or understand the point of some of the stuff I wrote.

the whole point of this thread was to teach people some useful stuff for daily use, and help them/guide them to find their own ways of doing things. instead, some of the replies here come from elite know-it-alls that can't even add more positive content to this thread (which makes me wonder if they have spent most of their lives reading manpages just so they can brag about obscure shit in forums like this one... instead of using them as tools)

>having to practice to use your overly complicated computer OS
ISHYGDDT

>I didn't think making this thread would attract elitists and arrogant retards who think they are superior beings because of their knowledge of bash, unix and other stuff.
forgot to mention: I should have guessed it. this is Jow Forums after all.

>overly complicated computer OS
what are you doing here? you don't belong here, you have to go back

The biggest mistake made by unix is to allow spaces in file names, which means every little thing in a shell command has to be quoted. I wish someone would redesign the unix shell from scratch and we would use a more modern shell as bash syntax is funky and not in a good way.

>oh noes, I have to learn something, why cant everything be an idiot UI like a smartphone
said every MS and Apple exec for the last 10 years

It's also hilarious how elitist unixtoddlers wank over their os when soon their beloved shovelwareOS will be replaced by lisp machines. They are circle jerking over a deprecated 80's multics abortion.

You seem a bit salty at finding that there are people in the world who are better at things, smarter, stronger, faster than you.

Something tells me this is a recurring issue for you and that despite your superiority complex you're going to have to get used to it.

But hey, thanks ever so much for sharing your vast and unbound-less knowledge with us OP. It truly marks you as one of the paragons of computer users in the world.

Attached: sally-bowrey-1117622.jpg (1920x1080, 148K)

know idea about what? how dumb you are? python's shitty web server does not allow for path traversal exploits and serves its current working directory. it's perfectly fine and safe for the basic shit you'd need to use it for.

fuck off you fucking retard. it's not much different than apache/nginx with autoindex on.

>an avatarfag unix-weenie takes pride in his time wasted by memorizing crypting coroutines of a horribly designed OS
I guess it helps your fragile ego, eh sweaty.

Okay, make it public facing, and see how fast it gets owned.

mate, simply judging by your comments ITT and the pics you post, it's clear that you aren't as smart as you believe, and you also waste a lot of time doing retarded, useless shit

this. if you are going to claim the python webserver is insecure, show us some vulns or shut the fuck up. and again, I, the OP, said it was for sharing INSIDE THE LAN
if you are retarded enough to share your whole $HOME or even /, then that's your problem, and your retardation.

but what if he doesn't want to put it out in the public you fucking autist

why the fuck would I do that? I have an vhost called dropzone with an autoindexed root where i can host shit i need to serve publicly over https. even then, given it's just a basic implementation of the primitive http server in python stdlib, if it's insecure the python retards need to fix their shit.

No.

jason@Yog-Sothoth » ~ » $ alias apt='sudo apt'
jason@Yog-Sothoth » ~ » $ apt
1) All commands run with root privileges are always dangerous.
2) Never run commands on an environment you are not willing to destroy, or able to restore.
3) Do not become root until you know what you are going to do.
4) Be sure of your command and what is going to be affected by it.
[sudo] password for jason:

OP is heading towards meltdown stage guize.

Go easy on him.

Rather than adhom maybe you should just admit that giving advice like

>yeah, go ahead and just make a webserver in some random directory

is fucking stupid advice and maybe take a moment to read some of the advice given to you.

Or you know, continue thinking you're the font of all knowledge on this and carry on regardless.

Attached: sally-bowrey-1117630.jpg (1920x1080, 134K)

>muh python, it's safe like nginx!!!
>so, make it public facing
>whyyy?!?
My point is you don't know what talking about. Stop talking out your collective fat assess, faggots.

>if it's insecure the python retards need to fix their shit.
The epitome of shifting the blame and a poor workman blaming his tools.

given python is written in an interpreted language with GC and all, i'd imagine it's likely more secure out of the gate since you don't have to worry about some fucking memory exploit.

jesus fucking christ. why don't you use it and see for yourself. it's literally basic bitch to the max and doesn't let you do a whole lot unless you toggle the "cgi" feature and have /cgi-bin with executables.

holy fuck. get out of here. this is some serious trolling

Kinda similar trick is to use $_
as in...
cat /some/long/path/to/a/file
vim $_
>will open in vim the same file you just cat'd.
or curly braces as in
cp /path/to/a/config{,.bak}
>will produce config.bak backup in same directory.

don't waste your time and just ignore the trolls, m8. if they like being retarded and/or assuming other people are as retarded as they are, let them believe that.

btw, I didn't mention some obvious shortcuts, like autocompletion and stuff, because, well, those are the first thing people do (or should) discover when using the terminal...

very quality posts user

These are really basic but whatever.

head previews a file.

Do an operation on every file that matches something in the current folder;
find . -name '*.zip' --exec unzip {}
for example. *.zip and unzip can differ ofcourse. The dot specifies the current folder.

Forgot to type sudo? "sudo !!" executes the previous command with sudo privileges.

ok

in the spirit of goodness. I'd strongly recommend becoming familiar with case/esac.

it's super useful for matching strings using the same globs (*,?,[],[!] and [[:classname:]]) you'd use on files on variables. for instance

case $posnumvar in ''|*[!0-9]*) printf 'not a positive number\n' ;; esac
for simplistic input validation. case is pretty useful and generally feels less verbose than if's and test ( the bracket [ command). you can use extglobs in bash using the grammatically special double bracket [[ ]] grammar blocks. and single equal sign e.g.

[[ asd = ?(a)@(sd|sc) ]]

>for simplistic input validation. case is pretty useful and generally feels less verbose than if's and test ( the bracket [ command). you can use extglobs in bash using the grammatically special double bracket [[ ]] grammar blocks. and single equal sign e.g.
>[[ asd = ?(a)@(sd|sc) ]]
FTFY

sudo !!
see man history "Event Designators"
!cat = run most recent command that began with cat
!?foo = most recent command that contained *foo*
fc -l 50 60 = list history lines 50 to 60
!56 = run history line 56 again

Attached: CopyQ.TT3863.png (370x315, 19K)

fc is not that useful if you have scrollback

fc -e gedit 27
>open history line 27 in gedit, edit and save/close gedit, it runs in you're terminal.

>python3 -m http.server
been using this little alias to get your local ip quickly as your set it up
alias httpserver="ip addr show | grep inet | grep eno1 && python3 -m http.server 8024"
obv replace eno1 with your wired/wireless adapter and use whatever port you prefer

>ip addr show | grep inet | grep eno1
ip addr show dev eno1 | grep -o 'inet [^/]*'
(IPv4 only. for IPv4+IPv6 use 'inet[^/]*' instead)

well this looks and works hell of a lot better than my shit, ty

securitronlinux.com/debian-testing/returning-just-the-interface-name-with-linux/

Why don't you take 20 minutes, and learn how to do it programmatically in C?

Jesus. /nug
sudo ifconfig

>writing code instead of leveraging tried and tested tools