Showing posts with label job control. Show all posts
Showing posts with label job control. Show all posts

Sunday, September 24, 2006

Linux Command Line Odds and Ends

Here are some useful Odds and Ends... most are related to command line stuff, some not; whatever, enjoy. Most of these came from either scouring the web, or Learning the Bash Shell or Learning Red Hat Enterprise Linux and Fedora.

Job Control
  • kill %<PID> kill a process
  • kill -QUIT %<PID> kill a process, a bit stronger
  • kill -KILL %<PID> unconditionally kill a process
  • fg bring a background job into the foreground
  • jobs list jobs running
  • ps process information

File permissions (owner, group, others)
  • 0 ---
  • 1 --x
  • 2 -w-
  • 3 -wx
  • 4 r--
  • 5 r-x
  • 6 rw-
  • 7 rwx

Globbing
  • * matches zero or more characters
  • ? matches any one character
  • [abc...] matches any of the characters specified
  • [a-z] matches any character in the specified range
  • [!abc...] matches any character other than those specified
  • [!a-z] matches any character not in the specified range
  • ~ home directory of current user
  • ~userid home directory of a user
  • ~+ current working directory
  • ~- previous working directory

Quotes
  • 'xxx' interprereted literally, variables not substituted
  • "xxx" interprereted literally, variables ARE substituted
  • `xxx` output of xxx command replaces it


Command line special characters
  • # comment
  • ; command seperator
  • & run in background
  • \ command continued on next line
  • | pipe

Input/Output Redirectors
  • prog > file stdout to file
  • prog 2> file stderr to file
  • prog >> file concatenates stdout to file
  • prog 2>> file concatenates stderr to file
  • prog > file 2>&1 stdout and stderr to file
  • prog >> file 2>&1 concatenates stdout and stderr to file
  • prog < file stdin from file
  • prog << text reads stdin until a line matching text is found, then EOF posted ("here document")
  • prog | prog2 pipe stdout
  • prog 2>&1 | prog2 pipe stdout and stderr

Command Line Movement
  • Ctrl+Shift+N open new console window
  • Crtl+Alt+F[1-7] go to virtual console 1-6 or X(7)
  • Ctrl+Alt+Backspace stop X and go to console
  • Alt+B Back one word
  • Alt+F Forward one word
  • Ctrl+A Beginning of line
  • Ctrl+E End of line
  • Alt+D Delete word |------------->X
  • Ctrl+D Delete char
  • Ctrl+K Delete |------------->X
  • Ctrl+U Delete X<-----------|
  • Ctrl+L Clear screen
  • Ctrl+Y UNDO
  • ESC+. Insert last word of previous command
  • TAB Possible completions

IRC
  • /server join a server
  • /join join a channel
  • /quit quit the server
  • /close close the current screen
  • /part leave the current channel
  • /partall leave all channels
  • /msg msg a user with a new window
  • /notice msg a user without a new window
  • /query force a window open to msg a user
  • /chat DCC with a user
  • /dns dns lookup for a user
  • /ping ping a user
  • /me *** does something
  • /whois query whois for a user

Ctrl Keys
  • Ctrl+C intr: stop current command
  • Ctrl+D eof: end of input
  • Ctrl+\ quit: stop current command (if Ctrl+C doesn't work)
  • Ctrl+S stop: halt output to screen
  • Ctrl+Q resume output to screen
  • Ctrl+Z suspend current command (works well with bg, fg and jobs)

Escape Sequences
  • \a alert (bell)
  • \b backspace
  • \c omit final newline
  • \E escape character
  • \f formfeed
  • \n newline
  • \r return
  • \t tab
  • \v vertical tab
  • \xxx ASCII in octal
  • \\ backslash
Tar: tarball options
  • -c create
  • -r append
  • -t list contents
  • -x extract
  • -a append files
  • -v verbose
  • -z zip/unzip
  • -f use filename
  • Oft-used:
    • tar -cf foo.tar foo; gzip foo.tar
    • gunzip bar.tar.gz; tar -xvf bar.tar