Actions

Difference between revisions of "Linux"

From kemiko

Line 2: Line 2:
  
 
<pre>
 
<pre>
Some variables:
+
Some Notation:
 
FILE: a filename
 
FILE: a filename
PATH: a directory/file path
+
DIRECTORY:
 +
PATH: a directory/file location
 
LINE: a line's contents
 
LINE: a line's contents
COMMANDS: a/many commands like awk, cat, echo, grep, etc.  
+
COMMAND: a command like awk, cat, echo, grep, etc.  
 
LITERAL: a literal/static variable no REGEX
 
LITERAL: a literal/static variable no REGEX
 
REGEX: "REGular EXpression"...a pattern matching expression
 
REGEX: "REGular EXpression"...a pattern matching expression
Line 12: Line 13:
 
TIME: a time...format my vary
 
TIME: a time...format my vary
 
NUMBER: a numeric value
 
NUMBER: a numeric value
 +
SEPARATOR: a field separator
 +
VARIABLE: a variable
 +
/dev/null: a device file representing nothing
 
</pre>
 
</pre>
  
* find . -type f -exec grep -n "foo" {} /dev/null \;  # search regular files for "foo" inside...printing "path/filename:line:content"
+
* find . -type f -exec grep -n "LITERAL/REGEX" {} /dev/null \;  # search regular files for "LITERAL/REGEX" inside...printing "path/filename:line:content"
 
* find . -type f -exec ls -hlatr {} \; | sort -hk5,5  # long list all files under a directory, sort smallest to largest (human size)
 
* find . -type f -exec ls -hlatr {} \; | sort -hk5,5  # long list all files under a directory, sort smallest to largest (human size)
* rm -rf foo # remove a directory "foo" and all content
+
* rm -rf PATH # remove a "PATH" and all content
* awk -F'foo' '{print $number}'  # print the column (number) delimited by "foo"
+
* awk -F'SEPARATOR' '{print $NUMBER}'  # print the column "NUMBER" delimited by "SEPARATOR"
* locate foo # print the path/filename of file name matching "foo"
+
* locate LITERAL # print the PATH of file name matching "LITERAL"
* less -S foo # pager with no line wrap
+
* less -S FILE # page "FILE" with no line wrap
 
* du -hd1 | sort -h # disk usage (human size),one level deep and sum by directory...pipe to sort smallest to largest
 
* du -hd1 | sort -h # disk usage (human size),one level deep and sum by directory...pipe to sort smallest to largest
* wget foo # get a file from http/ftp
+
* wget PATH # get "PATH" from http/ftp
* scp foo username@hostname:/tmp # put "foo" to location
+
* scp PATH1 username@hostname:PATH2 # put "PATH1" to "PATH2"
* scp username@hostname:/tmp/foo . # get "foo" from location
+
* scp -r PATH1 username@hostname:PATH2  # same as above, but recursively gets directory and all files under it
* cat foo # display contents of file "foo"
+
* scp username@hostname:PATH1 PATH2 # get "PATH1" to "PATH2"
* vi foo # edit/view file "foo"
+
* scp username@hostname:PATH1 PATH2  # same as above, but recursively gets directory and all files under it
* echo $foo # display contents of variable "foo"
+
* cat FILE # display contents of "FILE"
* >foo || cp /dev/null foo # zeros out file "foo"
+
* vi FILE # edit/view "FILE"
* \foo || "foo"  # unalias command "foo"
+
* echo $VARIABLE # display contents of variable "VARIABLE"
* while [ 1 ]; do foo; sleep foo; done
+
* >FILE  # zeros out "FILE"
 +
* cp /dev/null FILE # zeros out "FILE"
 +
* \COMMAND  # unalias "COMMAND"
 +
* "COMMAND"  # unalias "COMMAND"
 +
* while [ 1 ]; do COMMANDS; sleep NUMBER; done # repeat COMMAND with NUMBER seconds between
 +
* cat FILE | while read LINE; do COMMAND; done  # read a file line by line doing a COMMAND until file's end

Revision as of 22:27, 14 November 2016

Favorite Commands:

Some Notation:
FILE: a filename
DIRECTORY:
PATH: a directory/file location
LINE: a line's contents
COMMAND: a command like awk, cat, echo, grep, etc. 
LITERAL: a literal/static variable no REGEX
REGEX: "REGular EXpression"...a pattern matching expression
DATE: a date...format my vary
TIME: a time...format my vary
NUMBER: a numeric value
SEPARATOR: a field separator
VARIABLE: a variable
/dev/null: a device file representing nothing
  • find . -type f -exec grep -n "LITERAL/REGEX" {} /dev/null \; # search regular files for "LITERAL/REGEX" inside...printing "path/filename:line:content"
  • find . -type f -exec ls -hlatr {} \; | sort -hk5,5 # long list all files under a directory, sort smallest to largest (human size)
  • rm -rf PATH # remove a "PATH" and all content
  • awk -F'SEPARATOR' '{print $NUMBER}' # print the column "NUMBER" delimited by "SEPARATOR"
  • locate LITERAL # print the PATH of file name matching "LITERAL"
  • less -S FILE # page "FILE" with no line wrap
  • du -hd1 | sort -h # disk usage (human size),one level deep and sum by directory...pipe to sort smallest to largest
  • wget PATH # get "PATH" from http/ftp
  • scp PATH1 username@hostname:PATH2 # put "PATH1" to "PATH2"
  • scp -r PATH1 username@hostname:PATH2 # same as above, but recursively gets directory and all files under it
  • scp username@hostname:PATH1 PATH2 # get "PATH1" to "PATH2"
  • scp username@hostname:PATH1 PATH2 # same as above, but recursively gets directory and all files under it
  • cat FILE # display contents of "FILE"
  • vi FILE # edit/view "FILE"
  • echo $VARIABLE # display contents of variable "VARIABLE"
  • >FILE # zeros out "FILE"
  • cp /dev/null FILE # zeros out "FILE"
  • \COMMAND # unalias "COMMAND"
  • "COMMAND" # unalias "COMMAND"
  • while [ 1 ]; do COMMANDS; sleep NUMBER; done # repeat COMMAND with NUMBER seconds between
  • cat FILE | while read LINE; do COMMAND; done # read a file line by line doing a COMMAND until file's end