Difference between revisions of "Commands"
From Computer Science
Jump to navigationJump to search (Created page with " [pete](../../) > [guides](../) > [linux](./) > commands ---------------------------------------------------------------------- ===Introduction=== This page enumerates, cat...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | [[Guides]]> [[Linux Guide|linux]] > [[commands]] | |
− | |||
− | [ | ||
− | |||
---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||
===Introduction=== | ===Introduction=== | ||
Line 9: | 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 | + | 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 | + | the <code>ls</code> program, run |
− | + | <pre style="color: silver; background: black;"> | |
$ man ls | $ man ls | ||
− | + | </pre> | |
Some of the programs below are standard, as part of the "coreutils" and | Some of the programs below are standard, as part of the "coreutils" and | ||
Line 25: | Line 22: | ||
Only one right now. | 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 <code>grep</code> will cause it to search not only the | |
− | + | :files in the current directory, but also all files within and below it. | |
− | |||
− | |||
− | + | == Commands == | |
− | + | <big>'''The single most important one'''</big> | |
− | + | * <code>man</code>: access the online manual | |
− | + | ==== The second most important one, for system administration ==== | |
− | + | * <code>sudo</code>: run a program with temporarily-increased privileges | |
− | + | ==== Get me outta here ==== | |
− | + | * <code>exit</code>: terminate the terminal session | |
− | + | * <code>logout</code>: terminate the terminal session | |
− | + | * <code>Ctrl-d</code>: terminate the terminal session (only when no other characters have | |
− | + | :been entered at the prompt; otherwise behaves as Enter) | |
− | + | ==== Basic filesystem stuff ==== | |
− | + | * <code>pwd</code>: report the current working directory | |
− | + | * <code>ls</code>: list information about files | |
− | + | * <code>cd</code>: change to a different directory | |
− | + | * <code>mkdir</code>: create a directory | |
− | + | * <code>mv</code>: move a file (equivalent to renaming it, even if its new name puts it | |
− | + | :in a new directory) | |
− | + | * <code>cp</code>: copy a file | |
− | + | * <code>rm</code>: remove a file | |
− | + | * <code>rmdir</code>: remove a directory | |
− | + | * <code>touch</code>: create a file or, if the file exists, update its modification | |
− | + | :time | |
− | + | * <code>chmod</code>: change permissions of a file | |
− | + | * <code>chown</code>: change ownership (user/group) of a file | |
− | + | * <code>ln</code>: create a (symbolic) link | |
− | + | ==== Text analysis ==== | |
− | + | * <code>grep</code>: search inside file(s) | |
− | + | * <code>wc</code>: count characters/words/lines in a file | |
− | + | * <code>echo</code>: output a string to the terminal | |
− | + | * <code>cat</code>: output the contents of a file to the terminal | |
− | + | * <code>head</code>: print lines from the beginning of a file | |
− | + | * <code>tail</code>: print lines from the end of a file | |
− | + | * <code>diff</code>: compare the contents of files | |
− | + | * <code>less</code>: allow keyboard-based scrolling through a file (manpages are run | |
− | + | :through </code>less</code>, thus the same navigation commands apply) | |
− | + | ==== Text manipulation ==== | |
− | + | * <code>sort</code>: you'll never guess | |
− | + | * <code>uniq</code>: filter out consecutive duplicate lines from a file | |
− | + | * <code>cut</code>: combine files line by line | |
− | + | * <code>paste</code>: separate files line by line | |
− | + | * <code>sed</code>: modify files, line by line, according to regular expressions | |
− | + | * <code>awk</code>: lightweight programming language for modifying files line by line | |
− | + | * <code>fold</code>: break long lines into paragraphs | |
− | + | * <code>fmt</code>: more complex version of </code>fold</code> | |
− | + | * <code>column</code>: neatly format text into evenly-spaced columns | |
− | + | ==== More complex file stuff ==== | |
− | + | * <code>find</code>: locate files based on metadata (eg, name, size, modification time) | |
− | + | * <code>xargs</code>: often used to send the results of </code>find</code> to other programs | |
− | + | * <code>tar</code>: create an archive containing multiple files | |
− | + | * <code>gzip</code>: compress a file (historically ubiquitous) | |
− | + | * <code>xz</code>: compress a file (more recently popular) | |
− | + | * <code>stat</code>: report metadata information about a file | |
− | + | * <code>dd</code>: copy file contents (more tweakable than </code>cp</code>, useful for copying from | |
− | + | :raw devices, eg, </code>/dev/urandom</code>) | |
− | + | ==== Measuring and monitoring ==== | |
− | + | * <code>du</code>: measure sizes of files/directories | |
− | + | * <code>time</code>: measure the runtime of a program | |
− | + | * <code>ps</code>: list running processes (instant snapshot) | |
− | + | * <code>top</code>: list running processes (updates repeatedly) | |
− | + | ==== Random ==== | |
− | + | * <code>date</code>: report the date | |
− | + | * <code>sleep</code>: pause for a configurable duration | |
− | + | * <code>history</code>: list recently-run commands | |
− | + | * <code>clear</code>: clear the terminal screen | |
− | + | * <code>reset</code>: 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 ==== | |
− | + | * <code>ifconfig</code>: report information about network interface configuration | |
− | + | :(classic tool) | |
− | + | * <code>ip</code>: report information about network interface configuration (newer tool) | |
− | + | * <code>route</code>: manipulate routing table | |
− | + | * <code>netstat</code>: report information about network configuration | |
− | + | * <code>ping</code>: check reachability of machines over the Internet | |
− | + | * <code>traceroute</code>: trace the route to another machine on the Internet | |
− | + | * <code>mtr</code>: trace the route to another machine on the Internet (my preferred choice) | |
− | + | * <code>netcat</code>: the Swiss Army Knife of the Internet | |
− | + | * <code>wget</code>: save web pages as files | |
− | + | * <code>curl</code>: save web pages as files (alternate) | |
− | |||
− | + | ==== More complex ==== | |
− | + | * <code>ssh</code>: log into a machine over the Internet | |
− | + | * <code>rsync</code>: efficiently copies files (even across the Internet) | |
− | + | * <code>tmux</code>: resumable terminal sessions | |
− | + | * <code>script</code>: record the results of a terminal session in a file | |
− | + | * <code>cron</code>: schedule programs to be run at certain times | |
− | + | * <code>bc</code>: do math |
Latest revision as of 19:21, 9 February 2020
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 sessionlogout
: terminate the terminal sessionCtrl-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 directoryls
: list information about filescd
: change to a different directorymkdir
: create a directorymv
: move a file (equivalent to renaming it, even if its new name puts it
- in a new directory)
cp
: copy a filerm
: remove a filermdir
: remove a directorytouch
: create a file or, if the file exists, update its modification
- time
chmod
: change permissions of a filechown
: change ownership (user/group) of a fileln
: create a (symbolic) link
Text analysis
grep
: search inside file(s)wc
: count characters/words/lines in a fileecho
: output a string to the terminalcat
: output the contents of a file to the terminalhead
: print lines from the beginning of a filetail
: print lines from the end of a filediff
: compare the contents of filesless
: allow keyboard-based scrolling through a file (manpages are run
- through less, thus the same navigation commands apply)
Text manipulation
sort
: you'll never guessuniq
: filter out consecutive duplicate lines from a filecut
: combine files line by linepaste
: separate files line by linesed
: modify files, line by line, according to regular expressionsawk
: lightweight programming language for modifying files line by linefold
: break long lines into paragraphsfmt
: more complex version of foldcolumn
: 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 programstar
: create an archive containing multiple filesgzip
: compress a file (historically ubiquitous)xz
: compress a file (more recently popular)stat
: report metadata information about a filedd
: copy file contents (more tweakable than cp, useful for copying from
- raw devices, eg, /dev/urandom)
Measuring and monitoring
du
: measure sizes of files/directoriestime
: measure the runtime of a programps
: list running processes (instant snapshot)top
: list running processes (updates repeatedly)
Random
date
: report the datesleep
: pause for a configurable durationhistory
: list recently-run commandsclear
: clear the terminal screenreset
: 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 tablenetstat
: report information about network configurationping
: check reachability of machines over the Internettraceroute
: trace the route to another machine on the Internetmtr
: trace the route to another machine on the Internet (my preferred choice)netcat
: the Swiss Army Knife of the Internetwget
: save web pages as filescurl
: save web pages as files (alternate)
More complex
ssh
: log into a machine over the Internetrsync
: efficiently copies files (even across the Internet)tmux
: resumable terminal sessionsscript
: record the results of a terminal session in a filecron
: schedule programs to be run at certain timesbc
: do math