Tuesday, July 1, 2014

shortcuts

Handy shortcuts
Anywhere in Command Line:
up(down)_key - scrolls through command history
history # shows all commands you have used recently

Auto Completion:
<something-incomplete> TAB - completes program_path/file_name
Taking control over the cursor (the pointer on the command line):
Ctrl+a # cursor to beginning of command line
Ctrl+e # cursor to end of command line
Ctrl-w # Cut last word
Ctrl+k # cut to the end of the line
Ctrl+y # paste content that was cut earlier (by Ctrl-w or Ctrl-k)

When specifying file names:
"." (dot) - refers to the present working directory
"~" (Tilda) or "~/" - refers to user's home directory
Unix Help
man <something> # general help (press the 'q' key to exit)
man wc # manual on program 'word count' wc
wc --help # short help on wc

soap -h # for less standard programs
Online help: Google
Universally available Linux commands, with detailed examples and explanations: http://www.linuxconfig.org/linux-commands

Finding Things
Finding files, directories and applications
find -name "*pattern*" # searches for *pattern* in and below current directory
find /usr/local -name "*blast*" # finds file names *blast* in specfied directory
find /usr/local -iname "*blast*" # same as above, but case insensitive
additional useful arguments: -user <user name>, -group <group name>, -ctime <number of days ago changed>
find ~ -type f -mtime -2 # finds all files you have modified in the last two days
locate <pattern> # finds files and dirs that are written into update file
which <application_name> # location of application
whereis <application_name> # searches for executeables in set of directories
dpkg -l | grep mypattern # find Debian packages and refine search with grep pattern

Finding things in files
grep pattern file # provides lines in 'file' where pattern 'appears',
# if pattern is shell function use single-quotes: '>'


grep -H pattern # -H prints out file name in front of pattern
grep 'pattern' file | wc # pipes lines with pattern into word count wc
# wc arguments: -c: show only bytes, -w: show only words,
# -l: show only lines; help on regular expressions:
# $ man 7 regex or man perlre


find /home/my_dir -name '*.txt' | xargs grep -c ^.* # counts line numbers on many
# files and records each count along with individual file
# name; find and xargs are used to circumvent the Linux
# wildcard limit to apply this function on thousands of files.

No comments:

Post a Comment