Basic (but) Useful Linux Commands
Revision for “Basic (but) Useful Linux Commands” created on May 5, 2023 @ 14:22:47
Title | Basic (but) Useful Linux Commands |
---|---|
Content | <h1>Command Line Basics - Useful Linux Commands</h1>
While it is possible to use Bodhi Linux without much knowledge or use of the Command Line Interface (CLI [terminal]) and to stick primarily with the Graphical User Interface (GUI), there are certain tasks that are more efficient/easier to perform via the CLI/terminal. Generally, you will use a terminal emulator (Bodhi Linux's default is <a href="https://www.bodhilinux.com/w/wiki/terminology/">Terminology</a>) to access the CLI/terminal from the GUI. As you become more proficient with using Bodhi Linux, you may find yourself gravitating toward the CLI/terminal for certain tasks.
Below is a list of some useful commands to get you started!
<p style="padding-left: 30px;"><em><strong>***CAUTION***</strong> - if you ever enter a command and are asked to authorize via the question, "Yes, do as I say!"<strong>, <span style="text-decoration: underline;">do not run the command</span></strong>. The operation you are attempting is about to purge system critical packages and will generally result in a non-usable system. You have been warned!***</em></p>
<h2>Basic Commands</h2>
<code>sudo</code> – <em>superuser do</em> - allows a user to run commands/programs with the privileges of another user, by default root or admin - use when programs request "elevated privileges"
<p style="padding-left: 30px;"><em>Note: In Bodhi Linux, the sudo password is your login password by default. </em></p>
<code>apt</code> - <em>Advanced Package Tool</em> - used to get and install packages/programs - replaces <em>apt-get</em>
<code>update</code> - lets package manager know about available packages/programs and their versions; does not install anything.
<code>upgrade</code> - will upgrade versions for packages/programs from the update but will not remove anything nor update dependencies not already installed.
<code>dist-upgrade</code> - will upgrade versions for packages/programs and will intelligently install/remove packages as necessary to complete the upgrade.
<p style="padding-left: 30px;"><em>For more details see: <a href="https://www.bodhilinux.com/w/keeping-bodhi-linux-up-to-date/">Keeping Bodhi Software Updated</a></em></p>
Examples:
<pre>sudo apt update && sudo apt dist-upgrade
sudo apt install cups
</pre>
<h2>Useful Terminal Hotkey Combinations</h2>
<ctrl>+<shift>+<c> copy
<ctrl>+<shift>+<v> paste
<ctrl>+<r> searches command line history
<ctrl>+<l> clears the terminal (lower case 'L')
<ctrl>+<u> erases entire line to the left of cursor
<ctrl>+<k> erases to the right
<ctrl>+<w> erases one word left
<ctrl>+<d> logout or exit
<h2>Commands that are Generally Useful to Know</h2>
<code>cat</code> - concatenate, read or modify a file; used to display the contents of a file
<code>cd</code> - change directory; used to change your working directory
<code>chmod</code> - change permissions; used to change the permissions of a file/directory.
<p style="padding-left: 30px;"><em>Note: you must own the file or be <code>sudo</code> for this command</em></p>
<code>cp</code> - copy; used to copy files/directories
<code>df</code> - shows the amount of disk space used and available on mounted file systems
<code>du</code> - shows the amount of disk space used by specified files/directories
<code>exit</code> - exits the terminal
<code>find</code> - searches directory for files that meet criteria (--name, searches by name; --type, by file type; --size, by file size)
<code>grep</code> - searches file for specific character strings/patterns and can be used to replace a string with another string
<code>ifconfig</code> - view network settings
<code>less</code> - used to view a file vs. opening a file - compared to the <code>more</code> command, <code>less</code> allows backward and forward movement w/in the file, line by line or by page (can be useful to <em>pipe </em>commands to <code>less</code> [the pipe symbol is the straight-line about your enter key; <code>|</code> ]).
<code>ln</code> - used to create a hard or symbolic link to a file
<code>ls</code> - lists files or directories
<code>man</code> - manual; displays built-in documentation/user manual within Bodhi/Linux - commands, how to, syntax, etc
<code>mkdir</code> - make directory; used to make an empty directory
<code>more</code> - used to view a file vs. opening a file - page by page scrolling
<code>mv</code> - move; used to move a file/directory
<code>netstat</code> - network statistics; displays info/statistics about network protocols in use and TCP/IP connections
<code>passwd</code> - password; used to change a user's own password (admin may change anyone's password)
<code>ping</code> - used to test a connection to a host/IP address
<code>pwd</code> - print working directory; displays your current working directory
<code>rm</code> - remove; used to remove/delete files
<code>rmdir</code> - remove directory; used to remove <em>empty </em>directories
<code>shutdown</code> - used to shutdown/halt/restart system (ex: <code>sudo shutdown - r now</code> will restart your system)
<code>top</code> - task manager program used to monitor system tasks/processes and system resource usage (CPU utilization, memory usage, run times) in real-time, with sorting possible
<code>touch</code> - used to create a blank file
<code>uname</code> - reports basic information about your environment (ex: <code>uname -a</code> will report kernel name, node name, kernel release, kernel version, machine, processor, hardware platform, and OS)
<code>whoami</code> - prints user/login name associated with the current user ID
<h2></h2>
<h2>Commands Options</h2>
<code>-a</code>, <code>--all</code> - all; shows all information (including hidden) or operates on all arguments
<code>*</code> - asterisk/splat; wildcard
<code>!</code> - exclamation/bang; in scripts, means "not"
<code>!!</code>- repeats last command in terminal
<code>-f</code> - force; force copy by removing destination file if needed
<p style="padding-left: 30px;"><em><strong>CAUTION: </strong>can authorize potentially destructive actions for which a command/program would generally request user confirmation before completing</em></p>
<code>-h</code>, <code>--help</code> - help; provides usage messages and assistance
<code>-i</code> - interactive; prompts before overwrites, etc
<code>-l</code>, <code>--list</code> - list; lists files or arguments
<code>|</code>, - pipe; sends the output of one command/program to another command/program for further processing
<p style="padding-left: 30px;"><em>Note: the pipe symbol is not an "L" - it is available via</em> <shift>+<\><em> (backslash) key on most QWERTY keyboards</em></p>
<code>-r</code>, <code>-R</code>, <code>--recursive</code> - recursive/reverse; operates a command recursively/down the directory tree
<code>-u</code>, <code>--update</code>; move when the source is newer than the destination
<code>-v</code>, <code>--verbose</code> - verbose; output additional information
<code>-y</code>, <code>--yes</code>; enters yes into a command string -
<p style="padding-left: 30px;"><em><strong>CAUTION: </strong>can authorize potentially destructive actions for which a command/program would generally request user confirmation before completing</em></p>
<h2></h2>
<h2>Commands for Directory Navigation</h2>
<code>/</code> - root directory
<code>/home</code> - home directory for the current user
<code>cd</code> - change directory (when used without providing a directory, will take you to your home directory)
<code>cd ~</code>- takes you to your home directory
<code>cd ..</code> - move up one level (the parent directory of current)
<code>cd ../../</code> - move up two levels
<code>cd -</code>- will take you to where you were previously
<p style="padding-left: 30px;"><em>Tip: Have a difficult time remembering commands? Press the up arrow key in <a href="https://www.bodhilinux.com/w/terminology/">Terminology</a> to display commands you have previous run from your terminal history – press up until you find your needed command/s then press enter!</em></p>
<a href="https://www.bodhilinux.com/">Bodhi Linux Home</a>
<a href="https://www.bodhilinux.com/w/wiki/">Bodhi Linux – Wiki Home Page</a>
<a href="https://www.bodhilinux.com/w/bodhi-linux-how-to/">Bodhi Linux – Wiki Table of Contents</a> |
Excerpt |