Difference between revisions of "Commands"

From Computer Science
Jump to navigationJump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[pete](../../) > [guides](../) > [linux](./) > commands
+
[[Guides]]> [[Linux Guide|linux]] > [[commands]]
 
 
 
----------------------------------------------------------------------
 
----------------------------------------------------------------------
 
===Introduction===
 
===Introduction===
Line 7: Line 6:
 
command-line programs that you may find useful.  The documentation provided
 
command-line programs that you may find useful.  The documentation provided
 
here is (intentionally) insufficient to actually use them; recall that you can
 
here is (intentionally) insufficient to actually use them; recall that you can
use the `man` command to read the online manual page (arrow keys and pgup/pgdn
+
use the <code>man</code> command to read the online manual page (arrow keys and pgup/pgdn
 
scroll, 'q' to exit).  Therefore, to read about all the options accepted by
 
scroll, 'q' to exit).  Therefore, to read about all the options accepted by
the `ls` program, run
+
the <code>ls</code> program, run
  
 
<pre style="color: silver; background: black;">
 
<pre style="color: silver; background: black;">
Line 23: Line 22:
 
Only one right now.
 
Only one right now.
  
* Recursive" refers to an operation that descends into child directories,
+
* '''Recursive''' refers to an operation that descends into child directories,
 
:their children, their children's children, and so forth.  Therefore,
 
:their children, their children's children, and so forth.  Therefore,
:applying the '-r' parameter to `grep` will cause it to search not only the
+
:applying the '-r' parameter to <code>grep</code> will cause it to search not only the
 
:files in the current directory, but also all files within and below it.
 
:files in the current directory, but also all files within and below it.
  
Line 33: Line 32:
 
<big>'''The single most important one'''</big>
 
<big>'''The single most important one'''</big>
  
- `man`: access the online manual
+
* <code>man</code>: access the online manual
  
#### The second most important one, for system administration
+
==== The second most important one, for system administration ====
  
- `sudo`: run a program with temporarily-increased privileges
+
* <code>sudo</code>: run a program with temporarily-increased privileges
  
#### Get me outta here
+
==== Get me outta here ====
  
- `exit`: terminate the terminal session
+
* <code>exit</code>: terminate the terminal session
- `logout`: terminate the terminal session
+
* <code>logout</code>: terminate the terminal session
- `Ctrl-d`: terminate the terminal session (only when no other characters have
+
* <code>Ctrl-d</code>: terminate the terminal session (only when no other characters have
  been entered at the prompt; otherwise behaves as Enter)
+
:been entered at the prompt; otherwise behaves as Enter)
  
#### Basic filesystem stuff
+
==== Basic filesystem stuff ====
  
- `pwd`: report the current working directory
+
* <code>pwd</code>: report the current working directory
- `ls`: list information about files
+
* <code>ls</code>: list information about files
- `cd`: change to a different directory
+
* <code>cd</code>: change to a different directory
- `mkdir`: create a directory
+
* <code>mkdir</code>: create a directory
- `mv`: move a file (equivalent to renaming it, even if its new name puts it
+
* <code>mv</code>: move a file (equivalent to renaming it, even if its new name puts it
  in a new directory)
+
:in a new directory)
- `cp`: copy a file
+
* <code>cp</code>: copy a file
- `rm`: remove a file
+
* <code>rm</code>: remove a file
- `rmdir`: remove a directory
+
* <code>rmdir</code>: remove a directory
- `touch`: create a file or, if the file exists, update its modification
+
* <code>touch</code>: create a file or, if the file exists, update its modification
  time
+
:time
- `chmod`: change permissions of a file
+
* <code>chmod</code>: change permissions of a file
- `chown`: change ownership (user/group) of a file
+
* <code>chown</code>: change ownership (user/group) of a file
- `ln`: create a (symbolic) link
+
* <code>ln</code>: create a (symbolic) link
  
#### Text analysis
+
==== Text analysis ====
  
- `grep`: search inside file(s)
+
* <code>grep</code>: search inside file(s)
- `wc`: count characters/words/lines in a file
+
* <code>wc</code>: count characters/words/lines in a file
- `echo`: output a string to the terminal
+
* <code>echo</code>: output a string to the terminal
- `cat`: output the contents of a file to the terminal
+
* <code>cat</code>: output the contents of a file to the terminal
- `head`: print lines from the beginning of a file
+
* <code>head</code>: print lines from the beginning of a file
- `tail`: print lines from the end of a file
+
* <code>tail</code>: print lines from the end of a file
- `diff`: compare the contents of files
+
* <code>diff</code>: compare the contents of files
- `less`: allow keyboard-based scrolling through a file (manpages are run
+
* <code>less</code>: allow keyboard-based scrolling through a file (manpages are run
  through `less`, thus the same navigation commands apply)
+
:through </code>less</code>, thus the same navigation commands apply)
  
#### Text manipulation
+
==== Text manipulation ====
  
- `sort`: you'll never guess
+
* <code>sort</code>: you'll never guess
- `uniq`: filter out consecutive duplicate lines from a file
+
* <code>uniq</code>: filter out consecutive duplicate lines from a file
- `cut`: combine files line by line
+
* <code>cut</code>: combine files line by line
- `paste`: separate files line by line
+
* <code>paste</code>: separate files line by line
- `sed`: modify files, line by line, according to regular expressions
+
* <code>sed</code>: modify files, line by line, according to regular expressions
- `awk`: lightweight programming language for modifying files line by line
+
* <code>awk</code>: lightweight programming language for modifying files line by line
- `fold`: break long lines into paragraphs
+
* <code>fold</code>: break long lines into paragraphs
- `fmt`: more complex version of `fold`
+
* <code>fmt</code>: more complex version of </code>fold</code>
- `column`: neatly format text into evenly-spaced columns
+
* <code>column</code>: neatly format text into evenly-spaced columns
  
#### More complex file stuff
+
==== More complex file stuff ====
  
- `find`: locate files based on metadata (eg, name, size, modification time)
+
* <code>find</code>: locate files based on metadata (eg, name, size, modification time)
- `xargs`: often used to send the results of `find` to other programs
+
* <code>xargs</code>: often used to send the results of </code>find</code> to other programs
- `tar`: create an archive containing multiple files
+
* <code>tar</code>: create an archive containing multiple files
- `gzip`: compress a file (historically ubiquitous)
+
* <code>gzip</code>: compress a file (historically ubiquitous)
- `xz`: compress a file (more recently popular)
+
* <code>xz</code>: compress a file (more recently popular)
- `stat`: report metadata information about a file
+
* <code>stat</code>: report metadata information about a file
- `dd`: copy file contents (more tweakable than `cp`, useful for copying from
+
* <code>dd</code>: copy file contents (more tweakable than </code>cp</code>, useful for copying from
  raw devices, eg, `/dev/urandom`)
+
:raw devices, eg, </code>/dev/urandom</code>)
  
#### Measuring and monitoring
+
==== Measuring and monitoring ====
  
- `du`: measure sizes of files/directories
+
* <code>du</code>: measure sizes of files/directories
- `time`: measure the runtime of a program
+
* <code>time</code>: measure the runtime of a program
- `ps`: list running processes (instant snapshot)
+
* <code>ps</code>: list running processes (instant snapshot)
- `top`: list running processes (updates repeatedly)
+
* <code>top</code>: list running processes (updates repeatedly)
  
#### Random  
+
==== Random ====
  
- `date`: report the date
+
* <code>date</code>: report the date
- `sleep`: pause for a configurable duration
+
* <code>sleep</code>: pause for a configurable duration
- `history`: list recently-run commands
+
* <code>history</code>: list recently-run commands
- `clear`: clear the terminal screen
+
* <code>clear</code>: clear the terminal screen
- `reset`: clear the terminal screen with extreme prejudice (useful if you
+
* <code>reset</code>: clear the terminal screen with extreme prejudice (useful if you want to
  want to erase the scrollback buffer or reverse text corruption when playing
+
:erase the scrollback buffer or reverse text corruption when playing with, eg, customized fonts/colors in your shell)
  with, eg, customized fonts/colors in your shell)
 
  
#### Network
+
==== Network ====
  
- `ifconfig`: report information about network interface configuration
+
* <code>ifconfig</code>: report information about network interface configuration
  (classic tool)
+
:(classic tool)
- `ip`: report information about network interface configuration (newer tool)
+
* <code>ip</code>: report information about network interface configuration (newer tool)
- `route`: manipulate routing table
+
* <code>route</code>: manipulate routing table
- `netstat`: report information about network configuration
+
* <code>netstat</code>: report information about network configuration
- `ping`: check reachability of machines over the Internet
+
* <code>ping</code>: check reachability of machines over the Internet
- `traceroute`: trace the route to another machine on the Internet
+
* <code>traceroute</code>: trace the route to another machine on the Internet
- `mtr`: trace the route to another machine on the Internet (my preferred
+
* <code>mtr</code>: trace the route to another machine on the Internet (my preferred choice)
  choice)
+
* <code>netcat</code>: the Swiss Army Knife of the Internet
- `netcat`: the Swiss Army Knife of the Internet
+
* <code>wget</code>: save web pages as files
- `wget`: save web pages as files
+
* <code>curl</code>: save web pages as files (alternate)
- `curl`: save web pages as files (alternate)
 
  
#### More complex
+
==== More complex ====
  
- `ssh`: log into a machine over the Internet
+
* <code>ssh</code>: log into a machine over the Internet
- `rsync`: efficiently copies files (even across the Internet)
+
* <code>rsync</code>: efficiently copies files (even across the Internet)
- `tmux`: resumable terminal sessions
+
* <code>tmux</code>: resumable terminal sessions
- `script`: record the results of a terminal session in a file
+
* <code>script</code>: record the results of a terminal session in a file
- `cron`: schedule programs to be run at certain times
+
* <code>cron</code>: schedule programs to be run at certain times
- `bc`: do math
+
* <code>bc</code>: do math

Latest revision as of 19:21, 9 February 2020

Guides> linux > commands


Introduction

This page enumerates, categorizes, and very briefly describes a bunch of Linux command-line programs that you may find useful. The documentation provided here is (intentionally) insufficient to actually use them; recall that you can use the man command to read the online manual page (arrow keys and pgup/pgdn scroll, 'q' to exit). Therefore, to read about all the options accepted by the ls program, run

$ man ls

Some of the programs below are standard, as part of the "coreutils" and "util-linux" packages in Arch Linux; others will need to be installed separately.

Vocabulary

Only one right now.

  • Recursive refers to an operation that descends into child directories,
their children, their children's children, and so forth. Therefore,
applying the '-r' parameter to grep will cause it to search not only the
files in the current directory, but also all files within and below it.


Commands

The single most important one

  • man: access the online manual

The second most important one, for system administration

  • sudo: run a program with temporarily-increased privileges

Get me outta here

  • exit: terminate the terminal session
  • logout: terminate the terminal session
  • Ctrl-d: terminate the terminal session (only when no other characters have
been entered at the prompt; otherwise behaves as Enter)

Basic filesystem stuff

  • pwd: report the current working directory
  • ls: list information about files
  • cd: change to a different directory
  • mkdir: create a directory
  • mv: move a file (equivalent to renaming it, even if its new name puts it
in a new directory)
  • cp: copy a file
  • rm: remove a file
  • rmdir: remove a directory
  • touch: create a file or, if the file exists, update its modification
time
  • chmod: change permissions of a file
  • chown: change ownership (user/group) of a file
  • ln: create a (symbolic) link

Text analysis

  • grep: search inside file(s)
  • wc: count characters/words/lines in a file
  • echo: output a string to the terminal
  • cat: output the contents of a file to the terminal
  • head: print lines from the beginning of a file
  • tail: print lines from the end of a file
  • diff: compare the contents of files
  • less: allow keyboard-based scrolling through a file (manpages are run
through less, thus the same navigation commands apply)

Text manipulation

  • sort: you'll never guess
  • uniq: filter out consecutive duplicate lines from a file
  • cut: combine files line by line
  • paste: separate files line by line
  • sed: modify files, line by line, according to regular expressions
  • awk: lightweight programming language for modifying files line by line
  • fold: break long lines into paragraphs
  • fmt: more complex version of fold
  • column: neatly format text into evenly-spaced columns

More complex file stuff

  • find: locate files based on metadata (eg, name, size, modification time)
  • xargs: often used to send the results of find to other programs
  • tar: create an archive containing multiple files
  • gzip: compress a file (historically ubiquitous)
  • xz: compress a file (more recently popular)
  • stat: report metadata information about a file
  • dd: copy file contents (more tweakable than cp, useful for copying from
raw devices, eg, /dev/urandom)

Measuring and monitoring

  • du: measure sizes of files/directories
  • time: measure the runtime of a program
  • ps: list running processes (instant snapshot)
  • top: list running processes (updates repeatedly)

Random

  • date: report the date
  • sleep: pause for a configurable duration
  • history: list recently-run commands
  • clear: clear the terminal screen
  • reset: clear the terminal screen with extreme prejudice (useful if you want to
erase the scrollback buffer or reverse text corruption when playing with, eg, customized fonts/colors in your shell)

Network

  • ifconfig: report information about network interface configuration
(classic tool)
  • ip: report information about network interface configuration (newer tool)
  • route: manipulate routing table
  • netstat: report information about network configuration
  • ping: check reachability of machines over the Internet
  • traceroute: trace the route to another machine on the Internet
  • mtr: trace the route to another machine on the Internet (my preferred choice)
  • netcat: the Swiss Army Knife of the Internet
  • wget: save web pages as files
  • curl: save web pages as files (alternate)

More complex

  • ssh: log into a machine over the Internet
  • rsync: efficiently copies files (even across the Internet)
  • tmux: resumable terminal sessions
  • script: record the results of a terminal session in a file
  • cron: schedule programs to be run at certain times
  • bc: do math