Thursday, July 18, 2019

Linux Terminal Tips and Tricks



https://askubuntu.com/questions/385901/how-to-see-more-lines-in-the-terminal
If you are using the standard Terminal program on a Desktop version of Ubuntu...
  1. Choose Edit -> Profile Preferences from the terminal windows global menu.
  2. Choose the Scrolling tab
  3. Set Scrollback to the desired number of lines (or check the Unlimited box).
Then you can use the scrollbar at the side of the terminal to scroll back through the lengthy command output.

https://unix.stackexchange.com/questions/60382/how-to-scroll-in-a-terminal-using-keyboard
I use the default terminal in Ubuntu 14 (bash) and to scroll by page it is Shift + PageUp or Shift + PageDown to go up/down a whole page.
Ctrl + Shift + Up or Ctrl + Shift + Down to go up/down by line.

sudo apt-get install lxterminal

change shortcuts:
go to previous/next tab: ctrl+,/.
move to previous/next: ctrl+shift+,/.
find/search: ctrl+f

Up arrow and Down arrow for history without autocompletion
Alt-P and Alt-N for autocompletion from history

Ctrl-K to cut text from cursor until end of line. Ctrl-Y to paste it.
it uses an internal shell clipboard.
https://ss64.com/bash/syntax-keyboard.html
  Ctrl + xx  Toggle between the start of line and current cursor position
  Alt + l   Lower the case of every character from the cursor to the end of the current word.
  Alt + c   Capitalize the character under the cursor and move to the end of the word.
 Ctrl + s   Stop output to the screen (for long running verbose commands)
            Then use PgUp/PgDn for navigation
 Ctrl + q   Allow output to the screen (if previously stopped using command above)
 Ctrl + D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
 Ctrl + Z   Send the signal SIGTSTP to the current task, which suspends it.
            To return to it later enter fg 'process name' (foreground).
http://www.aboutlinux.info/2005/08/bash-shell-shortcuts.html
Ctrl + b - Move back a char 
Ctrl + f - Move forward a char 

Ctrl + r - Search the history backwards 

Ctrl + R - Search the history backwards with multi occurrence 

Ctrl + u - Delete backward from cursor 

Ctrl + xx - Move between EOL and current cursor position 

Ctrl + x @ - Show possible hostname completions 

Ctrl + z - Suspend/ Stop the command 



Alt + n - Search the history forwards non-incremental 

Alt + p - Search the history backwards non-incremental 

https://www.slant.co/versus/2442/2453/~gnome-terminal_vs_lxterminal
https://opensource.com/life/17/10/top-terminal-emulators

https://askubuntu.com/questions/19916/how-to-show-gnome-terminal-menubar/19917
How to show gnome-terminal menubar?
Right click anywhere inside the terminal, and you'll get a similar pop up menu that lets you reenable it.
You can also make it via terminal command line:
gnome-terminal  --show-menubar
If you read the man gnome-terminal you can find this:
  --show-menubar
                 Turn  on  the menu bar for the last-specified window; applies
                 to only one window; can be specified once for each window you
                 create from the command line.

https://unix.stackexchange.com/questions/245421/ctrlc-copy-or-interrupt
https://askubuntu.com/questions/53688/making-ctrlc-copy-text-in-gnome-terminal
Ctrl + C is typically used for interrupting a program. But instead of using Ctrl + Shift + C to copy, which I do much more frequently than interrupting a process, I change the setting to have Ctrl +

C to copy and Ctrl + Shift + C to interrupt.
You can do this in GNOME Terminal by going to "Edit" -> "Keyboard Shortcuts..." and map the "Copy" action to Ctrl + C and "Paste" to Ctrl + V. The interrupt command will automatically be remapped to Ctrl + Shift + C.

Apart from what @Dan said, there's another option for copy-pasting text in Linux which I'm finding much faster and easier to use, since there's no need to swich from mouse (which you're using to make the selection) to keyboard:
  • selecting text with mouse copies it to clipboard
  • middle-click pastes it.
This feature is especially useful in terminal, for example when assembling a command from bits of text which are already on screen.
This works in all applications, so it's possible to copy-paste text from a web page to terminal etc.
The clipboard buffer used for middle-click copy-paste is separate from the one used for Ctrl-C/Ctrl-V, which makes possible to have two different bits of text copied at the same time.

https://askubuntu.com/questions/823883/ctrl-v-ctrl-c-in-terminal
Copy:  Ctrl+Shift+C
Paste: Ctrl+Shift+V
You may also find usage for:
Copy:  Shift+Home
Paste: Shift+Insert

ou can edit these shortcuts in Edit > Key combinations (translated from my spanish version of the Terminal), and set the legendary Ctrl+C and Ctrl+V
https://stackoverflow.com/questions/9679776/how-do-i-clear-delete-the-current-line-in-terminal
You can use Ctrl+U to clear up to the beginning.
You can use Ctrl+W to delete just a word.
You can also use Ctrl+C to cancel.
If you want to keep the history, you can use Alt+Shift+# to make it a comment.

To delete the whole line no matter where the cursor is, you can use the kill-whole-line command, but it is unbound by default. It can be bound to, for example, Ctrl+Alt+K by inserting
"\e\C-k": kill-whole-line
into your Readline init file (conventionally ~/.inputrc).

In order to clean the whole line (2 different ways):
  • Home , Ctrl+K
  • End , Ctrl+U
https://hackernoon.com/10-basic-tips-on-working-fast-in-unix-or-linux-terminal-5746ae42d277
8) Using pushd, popd, cd -, ~ to Move Across a Directory



Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts