Actions

Difference between revisions of "Linux"

From kemiko

(Adding commands.)
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
<strong>Favorite Commands:</strong>
+
[[Linux Commands]]
* find . -type f -exec grep -n "foo" {} /dev/null \; # search regular files for "foo" 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 foo  # remove a directory "foo" and all content
+
 
* awk -F'foo' '{print $number}' # print the column (number) delimited by "foo"
+
<strong>Favorite Commands (Debian/Ubuntu):</strong>
* locate foo  # print the path/filename of file name matching "foo"
+
 
* less -S foo # pager with no line wrap
+
 
* du -h -d1 | sort -h # disk usage (human size)...group/sum one level deep and sort smallest to largest
+
Some Notation:
* wget foo  # get a file from http/ftp
+
<br>
* scp foo username@hostname:/tmp  # put "foo" to location
+
" #": everything following this to the end of the line is a comment...you can also paste it...the shell will ignore it
* scp username@hostname:/tmp/foo . # get "foo" from location
+
<br>
* cat foo  # display contents of file "foo"
+
FILE: filename
* vi foo  # edit/view file "foo"
+
<br>
* echo $foo  # display contents of variable "foo"
+
DIR: directory
* >foo # zeros out file "foo"
+
<br>
* \foo # unalias command "foo"
+
PATH: directory/[file] location
 +
<br>
 +
LINE: line's contents
 +
<br>
 +
CMD: command like awk, cat, echo, grep, etc.
 +
<br>
 +
LIT: literal/static variable no REGEX
 +
<br>
 +
REGEX: "REGular EXpression"...a pattern matching expression
 +
<br>
 +
DATE: date...format may vary
 +
<br>
 +
TIME: time...format may vary
 +
<br>
 +
NUM: numeric value
 +
<br>
 +
SEP: field separator
 +
<br>
 +
VAR: variable
 +
<br>
 +
URL: Uniform Resource Locator
 +
<br>
 +
/dev/null: a device file representing nothing
 +
<br>
 +
read: shell builtin that read's stdin
 +
<br>
 +
&#42;: wildcard
 +
<br>
 +
 
 +
 
 +
<ul>
 +
<li>
 +
  type CMD&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># cool builtin that tells you what you are looking at...</font>
 +
  </li>
 +
  <ul>
 +
  <li>
 +
    alias
 +
  </li>
 +
  <li>
 +
    builtin
 +
  </li>
 +
  <li>
 +
    command
 +
  </li>
 +
  <li>
 +
    etc.
 +
  </li>
 +
  </ul>
 +
</li>
 +
<li>
 +
  uname -a&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># lists basic system information</font>
 +
</li>
 +
<li>
 +
  uptime&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># print time since system boot</font>
 +
</li>
 +
<li>
 +
  top&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># traditional performance monitor</font>
 +
</li>
 +
<li>
 +
  htop&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># improved performance monitor</font>
 +
</li>
 +
<li>
 +
  mytop&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># a top like tool for MySQL</font>
 +
</li>
 +
<li>
 +
  itop&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># a top like tool I programmed for Informix 9.40.FC7</font>
 +
</li>
 +
<li>
 +
  du -hd1 | sort -h&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># disk usage (human size), one level deep and sum by directory...pipe to sort smallest to largest</font>
 +
</li>
 +
<li>
 +
  find . -type f -exec grep -in "LIT/REGEX" {} /dev/null \;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># case insensitive search regular files for "LIT/REGEX" inside file...printing "path/filename:line:content"</font>
 +
</li>
 +
<li>
 +
  find . -type f -exec ls -hlatr {} \; | sort -hk5,5&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># long list all files under a directory, sort smallest to largest (human size)</font>
 +
</li>
 +
<li>
 +
  find . -maxdepth 1 -type f&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># list only regular files in current directory</font>
 +
</li>
 +
<li>
 +
  rm -rf PATH&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># remove a "PATH" and all content</font>
 +
</li>
 +
<li>
 +
  awk -F'SEP' '{print $NUM}'&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># print the column "NUM" delimited by "SEP"</font>
 +
</li>
 +
<li>
 +
  locate LIT&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># print the PATH of file name matching "*LIT*"</font>
 +
</li>
 +
<li>
 +
  less -S FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># page "FILE" with no line wrap</font>
 +
</li>
 +
<li>
 +
  wget URL&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># get "URL" from http/ftp</font>
 +
</li>
 +
<li>
 +
  scp PATH1 username@hostname:PATH2&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># put "PATH1" to "PATH2"</font>
 +
</li>
 +
<li>
 +
  scp -r PATH1 username@hostname:PATH2&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># same as above, but recursively puts directory and all files under it</font>
 +
</li>
 +
  <li>
 +
  scp username@hostname:PATH1 PATH2&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># get "PATH1" to "PATH2"</font>
 +
</li>
 +
<li>
 +
  scp -r username@hostname:PATH1 PATH2&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># same as above, but recursively gets directory and all files under it</font>
 +
</li>
 +
<li>
 +
  cat FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># display contents of "FILE"</font>
 +
</li>
 +
<li>
 +
  vi FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># edit/view "FILE"</font>
 +
</li>
 +
<li>
 +
  echo $VAR&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># display contents of variable "VAR"</font>
 +
</li>
 +
<li>
 +
  >FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># zeros out "FILE" keeping current attributes</font>
 +
</li>
 +
  <li>
 +
  cp /dev/null FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># zeros out "FILE" keeping current attributes</font>
 +
</li>
 +
<li>
 +
  touch FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># creates a FILE of zero size if does not exist or updates file's timestamp to current time</font>
 +
</li>
 +
<li>
 +
  \CMD&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># unalias "CMD"</font>
 +
</li>
 +
  <li>
 +
  "CMD"&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># unalias "CMD"</font>
 +
</li>
 +
<li>
 +
  while [ 1 ]; do CMD; sleep NUM; done&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># repeat CMD with NUM seconds between/wait</font>
 +
</li>
 +
<li>
 +
  cat FILE | while read LINE; do CMD; done&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># read a file line by line doing a CMD until file's end</font>
 +
</li>
 +
<li>
 +
  apt-get update&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># updates the system's package lists</font>
 +
</li>
 +
<li>
 +
  a2ensite kohlmeyer.us.conf&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># Apache...enable a virtual host</font>
 +
</li>
 +
<li>
 +
  ffmpeg -ss 4.5 -i input.mp3 -t 1.7 output.mp3&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># cut a mp3 from 4.5 seconds to 6.2 seconds</font>
 +
</li>
 +
<li>
 +
  vlc FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># play audio or video FILE</font>
 +
</li>
 +
<li>
 +
  eog FILE&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># display image FILE</font>
 +
</li>
 +
<li>
 +
  gnome-system-monitor&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># graphical display of system resources</font>
 +
</li>
 +
<li>
 +
  gimp&nbsp;&nbsp;&nbsp;&nbsp;<font color="#AAAAAA"># run GNU Image Manipulation Program</font>
 +
</li>

Latest revision as of 12:51, 11 June 2017

Linux Commands


Favorite Commands (Debian/Ubuntu):


Some Notation:
" #": everything following this to the end of the line is a comment...you can also paste it...the shell will ignore it
FILE: filename
DIR: directory
PATH: directory/[file] location
LINE: line's contents
CMD: command like awk, cat, echo, grep, etc.
LIT: literal/static variable no REGEX
REGEX: "REGular EXpression"...a pattern matching expression
DATE: date...format may vary
TIME: time...format may vary
NUM: numeric value
SEP: field separator
VAR: variable
URL: Uniform Resource Locator
/dev/null: a device file representing nothing
read: shell builtin that read's stdin
*: wildcard


  • type CMD    # cool builtin that tells you what you are looking at...
    • alias
    • builtin
    • command
    • etc.
  • uname -a    # lists basic system information
  • uptime    # print time since system boot
  • top    # traditional performance monitor
  • htop    # improved performance monitor
  • mytop    # a top like tool for MySQL
  • itop    # a top like tool I programmed for Informix 9.40.FC7
  • du -hd1 | sort -h    # disk usage (human size), one level deep and sum by directory...pipe to sort smallest to largest
  • find . -type f -exec grep -in "LIT/REGEX" {} /dev/null \;    # case insensitive search regular files for "LIT/REGEX" inside file...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 . -maxdepth 1 -type f    # list only regular files in current directory
  • rm -rf PATH    # remove a "PATH" and all content
  • awk -F'SEP' '{print $NUM}'    # print the column "NUM" delimited by "SEP"
  • locate LIT    # print the PATH of file name matching "*LIT*"
  • less -S FILE    # page "FILE" with no line wrap
  • wget URL    # get "URL" from http/ftp
  • scp PATH1 username@hostname:PATH2    # put "PATH1" to "PATH2"
  • scp -r PATH1 username@hostname:PATH2    # same as above, but recursively puts directory and all files under it
  • scp username@hostname:PATH1 PATH2    # get "PATH1" to "PATH2"
  • scp -r 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 $VAR    # display contents of variable "VAR"
  • >FILE    # zeros out "FILE" keeping current attributes
  • cp /dev/null FILE    # zeros out "FILE" keeping current attributes
  • touch FILE    # creates a FILE of zero size if does not exist or updates file's timestamp to current time
  • \CMD    # unalias "CMD"
  • "CMD"    # unalias "CMD"
  • while [ 1 ]; do CMD; sleep NUM; done    # repeat CMD with NUM seconds between/wait
  • cat FILE | while read LINE; do CMD; done    # read a file line by line doing a CMD until file's end
  • apt-get update    # updates the system's package lists
  • a2ensite kohlmeyer.us.conf    # Apache...enable a virtual host
  • ffmpeg -ss 4.5 -i input.mp3 -t 1.7 output.mp3    # cut a mp3 from 4.5 seconds to 6.2 seconds
  • vlc FILE    # play audio or video FILE
  • eog FILE    # display image FILE
  • gnome-system-monitor    # graphical display of system resources
  • gimp    # run GNU Image Manipulation Program