bash
19 Nov 2011 #linuxSome bash hotkeys:
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + R Let’s you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. "fg" restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Some notes about reverse history search. It’ll iterative show last command for your search query. For next item press Ctrl-R again. To search forward press Ctrl-S. (On some terminals this bind to freeze, press Ctrl-Q to defreeze)
More about history navigation.
Using screen:
- Run
screen
to start session. Press Ctrl-a d, or disconnect ssh to detach.
Runscreen -r
to reattach. I usually usescreen -x
- this will try to reattach, or create new session if no sessions exist. - Some hotkeys:
C-a c Create a new window
C-a ? Show key bindings
C-a 0 .. 9 Switch to window number 0 ... 9
C-a A Allow the user to enter a name for the current window
C-a C Clear the screen
C-a h Write a hardcopy of the current window to the file "hardcopy.n".
C-a H Begins/ends logging of the current window to the file "screenlog.n".
C-a k Kill current window
C-a M Toggles monitoring of the current win (will notify about changes in window)
C-a [space] Switch to the next window
C-a [backsp] Switch to the previous window
C-a [Esc] Enter copy/scrollback mode
C-a d Detach screen from this terminal
C-a D D Detach and logout
C-a C-\ Kill all windows and terminate screen
- Ok, lets imagine you watching log in screen’s window. Needed part was clipped by top of window. When you scroll window content in tutty - you see old stuff lie here before running screen. To scroll screen’s window content you need to go to copy mode by Ctrl-a Esc and there will be PgUp & PgDn keys available for scrolling.
And more useful - / for forward search, and ? - for reverse. - I often use tutty from mRemote, so titlebar is hidden. I need duplicate screen’s window list on screen. This is my customized
screenrc
file:# Bind F11 and F12 (NOT F1 and F2) to previous and next screen window bindkey -k F1 prev bindkey -k F2 next # From Stephen Shirley # Don't block command output if the terminal stops responding # (like if the ssh connection times out for example). nonblock on startup_message off #nethack on caption always caption string "%-w %{= BW}%n %t%{-} %+w |%h"
Some commands:
grep -v ^# /etc/sysctl.conf
Show file without commented lines (starting with #)
find /etc -mmin -3
Files modified for last 3 minutes
egrep -i 'err|warn' /var/log/messages
Last errors in log
tail -f /var/log/messages
Watch for file changes and show them
netstat -tulpn
Show opened ports
find / -iname ip_queue.o
which asterisk
Find file, find program dirs
du -hs
Folder size
tcpdump -i eth2 -nn 'tcp dst port 25'
Show outgoing smtp connections