Command Redirection
|
Gets input from somewhere other than stdin (keyboard) |
|
Sends output somewhere other than stdout (monitor) |
|
Alternative to ">" (not really used) |
|
Redirects stdout; appends it to existing content (instead of overwriting it) |
|
Redirects only error messages (stderr) |
|
Redirects both stdout and stderr |
|
Pipes cmd1 into cmd2 (uses the output of cmd1 as the input for cmd2) |
Basic File/Directory Commands
|
List contents of dir1 |
|
additional info (owner, perms, etc.) |
|
lists all, including hidden files |
|
adds file inode to info displayed |
|
adds file size in human-readable format (e.g. MB instead of bytes) |
|
info for directory itself (rather than its contents) |
|
|
Create a new directory |
|
creates full path (multiple directories if needed) |
|
verbose (output shows action taken) |
|
|
Copy dir1 into dir2 |
|
recursively ("and its contents") |
|
|
Removes (deletes) an empty directory |
|
recursively ("and it's contents"), including special files |
|
interactively delete files (ask before deleting) |
|
Move file1 into dir1 |
|
verbose (output shows action taken) |
|
|
Creates a hard link from file "link" to file "target" |
|
makes a symbolic link instead of a hard link |
Locating Files
|
Search for file names with specified pattern (via "locate" database) |
|
Update the "locate" database |
|
|
Recursive search starting at "/dir" for pattern ("what") of specified type ("how") |
|
case-sensitive search for file name |
|
case-insensitive search for file name |
|
files owned by user with specified username |
|
files owned by user with UID 1002 |
|
files that are exactly 100 MB in size |
|
files that are [larger/smaller] than 100 MB |
|
specifically files (not directories) |
|
files where at least "other" has write perms |
|
file names associated with specified inode (i.e. including linked files) |
|
files modified in the last 5 minutes |
|
creation time |
< find /usr -size +100M -exec ls -lh {} \;
>
shows ls -l
output AND actual file size of search results
(essentially "pipes" results of find
into ls -lh
)
Users & Groups
Command |
Options |
What It Does |
|
Show UID, GID, & secondary groups (current user if not specified) |
|
Find out if usr1 is known to the system |
|
Add a new user |
|
set a specific UID |
|
|
create a user without a login shell |
|
Change properties of existing user |
|
adds text to comment field |
|
changes primary group to group1 |
|
replaces supplementary group with group1 |
|
appends group1 to supplementary groups |
|
locks user1's account (instead of deleting) |
|
Change current user's primary group (temporary; current session only) |
|
Deletes user1 but not their home directory |
|
deletes both user and home directory |
|
Displays simple list of groups user1 is a member of |
|
Set password for user1 |
|
Change password aging properties for user |
|
minimum # of days between password changes |
|
maximum # of days between password changes |
|
warning period before password expires |
|
inactivity period (password usable after expiration) |
|
require password change on next login |
|
date when account expires |
|
Find out if grp1 is known to the system |
|
Create a new group |
|
set a specific GID |
|
create a system group |
|
Change properties of existing group |
|
change GID to specified number |
To set the number of days from today when user's account expires:
chage -E $(date +days %Y-%m-%d)
To give full admin privileges to a user or group:
echo "[user1|%group1] ALL=(ALL) ALL" >> /etc/sudoers.d/name
Ownership & Permissions
|
Change owning user and owning group |
|
Change only owning group |
|
Alternate way to change owning group |
|
|
Change file/directory permissions |
|
recursive; applies to directory and all contents |
|
grants owning group the read permission |
|
removes execute perms for all parties (without changing other perms) |
|
recursively set perms for all parties to rw, with x perms on directory only |
|
octally set rwx perms for owning user & group, 0 for other |
|
(cont'd) Change special permissions |
|
set Sticky bit (in other) * For directories only * |
|
set Sticky bit – octal form (xxx = regular perms) |
|
set SetGID bit (in group) * For directories and files * |
|
set SetGID bit – octal form |
|
set both Sticky & SetGID bits (chmod "1"+"2") |
|
set SetUID bit (in user) * For files only * |
|
set SetUID bit – octal form |
|
|
Displays currently set umask (when used by itself) |
|
removes default perms (0 from user, 7 from group/other) |
|
preserves any special perms when removing defaults |
Octal Expression Values: r=4 | w=2 | x=1
Default permissions (on vanilla Linux):
directories=777 | files=666
Jobs & Load Handling
|
Displays currently logged-in users, login method, time, & resource usage info |
|
shows users' IP addresses (in addition to regular output) |
|
limits output to specified username |
|
Starts a new job in the background |
|
Displays jobs running in the background ("+" = default job) |
|
Brings job 1 to the foreground |
|
Sends job 1 to the background |
|
Returns the PID(s) of a currently running job |
|
Shows main PID of a process, among other things (can use if pidof
returns multiple) |
|
--- CPU Load Handling --- |
|
Displays the load average for the last 1, 5, and 15 mins |
|
Displays number of CPUs in the system, among other things |
|
simplified output (each row of numbers = 1 CPU) |
Process Priority Values: -20 to 19 (default = 0)
(negative = higher priority | positive = lower priority)
Viewing & Managing Processes
|
Shows info about processes; pipe to head
/ grep
/etc for less output (Note: " [output]
" = kernel thread) |
|
shows output in visual "tree" format |
Shows processes in visual tree format (may not always be installed) |
|
includes PIDs in tree output |
Linux terminal equivalent of Task Manager (Also shows load average) Keyboard Controls: |
|
k |
send a signal to a process from within top
|
|
Shift+M |
sort by memory usage |
|
Shift+P |
return to sorting by CPU usage |
|
l / t / m |
toggle "load", "threads", & "memory" header lines |
|
Sends signal 15 to specified process * Must use process ID * |
|
sends specified signal (can use signal name or number) |
|
displays list of signal options |
|
Kills processes by name instead of PID |
|
Look up & manage processes by name or other attributes (default is signal 15) |
|
specify signal to send |
|
sends signal to user's account (forces logout & shuts down their processes) |
|
kills specified terminal session (TTY) |
|
|
Starts a new process with an adjusted priority value (x) |
|
Change the priority value (x) of an existing process |
Managing Services & Daemons
--- System Commands --- |
|
reboots the system |
|
tells systemd you've made changes to a unit file & it needs to reinitialize those unit files |
|
shows which target is the default target that the system summons whenever it starts up |
systemctl set-default graphical.target
|
sets default target to "graphical.target" |
|
--- Unit Commands --- |
|
shows all the active & loaded units on the system |
|
filters output by specified type of unit |
|
shows all units known to systemd (including "inactive" & "not-found") |
|
shows status & details of specified unit (including location of unit files) |
systemctl is-enabled unit.service
|
shows whether the service is enabled (i.e. will start automatically on system boot) |
systemctl is-active unit.service
|
shows whether the service is active |
systemctl enable --now unit.service
|
enables the service & start it immediately (sets "enable" persistently) |
systemctl disable --now unit
|
stops service immediately & sets to "disabled" persistently |
|
sends the "hang up" signal; drops config file loaded in memory & reload it from file system |
|
kills the process & starts it up again fresh (main PID will change) |
systemctl reload-or-restart unit
|
reloads if possible, otherwise restart (for when you don't know if unit supports reload) |
systemctl list-dependencies unit.service
|
shows list of units required by unit.service for it to work |
|
shows units that call unit.service |
|
prevents unit from being started automatically or manually (not even via enable --now
command) |
|
undoes masking on a service |
File Systems & Block Devices
|
Simplified output about mountpoints & filesystems |
|
Lists block devices in tree format (incl. size, mountpoint, etc.) |
|
adds info about filesystems |
|
shows full device paths |
|
Shows info about block device & filesystem, including partition UUID (non-partition devices must have a filesystem to show output) |
|
Shows data (storage) utilization of filesystem, device, & mountpoint (Shows info for whole filesystem, even if location
is a subdirectory) |
|
human-readable format (converts bytes to MB, GB, etc.) |
|
|
Shows data (storage) utilization of a specific directory |
|
summary version of output |
|
human-readable format (converts bytes to MB, GB, etc.) |
|
Creates filesystem of specified type on specified block device (e.g. mkfs.ext4 /dev/vdc1
) |
|
Takes filesystem on specified block device & mounts it in specified directory |
|
Unmount the filesystem at the specified mountpoint |
|
List open files; shows which files are open in that filesystem |
|
Similar info as lsof
, but less detailed |
|
shows only the PID associated with the open file |
RPM Software Packages
|
Query all; shows all software packages installed on the system |
|
Query file; asks RPM database which software package owns "/file" |
|
Query package; runs command against the .rpm file itself |
|
list of files in the .rpm package |
|
shows config files shipped with the package |
|
shows documentation files shipped with the package |
|
information about the package file (metadata, summary, software description, etc.) |
Managing Software Packages (DNF)
Info Commands: |
|
Shows package metadata, summary, description, etc. (same as rpm -qpi
, but package doesn't have to be installed) |
|
Shows what software package provides the file (same as rpm -qf
, but package doesn't have to be installed) |
|
Searches for "gui" based on package name & metadata |
|
Includes package description when searching for "gui" |
|
Lists all available and/or installed software packages that begin with "x" |
|
Shows list of available software groups ("Environment Groups" = logical groupings of regular groups from "Available" list) |
|
Lists software packages included in specified group |
|
Displays history of DNF commands/actions |
|
Undoes number 3 from DNF history (e.g. if it installed something, "undo" will uninstall it) |
Download/Install Commands: |
dnf download --resolve package
|
Downloads software package & its dependencies without installing them |
|
Installs package & automatically resolves dependencies |
|
auto-yes (for non-interactive) |
|
|
Uninstalls package & any dependencies (if they aren't being used elsewhere) |
|
auto-yes (for non-interactive) |
|
|
Redownloads .rpm file & reinstalls newer version |
|
auto-yes (for non-interactive) |
Network Info Commands
|
Shows current IP & netmask for all interfaces |
|
Link-level properties of all interfaces (MAC addresses, etc.) |
|
Equivalent of ipconfig
(same info as link show
, plus IP addresses) |
|
abbreviated form |
|
|
Shows default route |
|
abbreviated form |
|
|
IPv4 ping | IPv6 ping |
|
Equivalent of tracert
/ traceroute
IPv6 version |
|
"My traceroute" program; gives extra info & continuous running stats |
|
Scans ports on host; shows port number/type, open state, associated service, etc. |
|
Sockets state information |
|
processes responsible for opening ports |
|
listening sockets |
|
UDP sockets |
|
translates names to numbers (e.g. process name + PID) |
|
TCP sockets |
|
|
Shows configured connection profiles |
|
|
abbreviated form |
|
|
only show currently active profiles |
|
Status of interfaces (devices), incl. type & profile name |
|
Shows settings applied to the specified interface (device) |
Network Configuration Commands (NMCLI)
nmcli con add <specs> [options]
|
Create a new connection profile <specs> = required configs [options] = other optional configs |
|
profile name |
|
type of connection |
|
interface to associate with profile |
|
specifies manual IPv4 address config (default=auto; only needed for manual) |
[ipv4.addresses address/cidr]
|
manually set IPv4 address & subnet |
|
specify DNS server address |
|
Modify properties of a connection profile |
|
set IPv4 default gateway |
+property.attribute value
|
add a value to an array of values (e.g. add an IP address to list of addresses) |
-property.attribute value
|
remove a value from an array of values |
|
Activates specified profile on whatever interface it's configured for |
|
Reloads profile after config changes Note: Must re- up
profile before new config will be applied to interface! |
SSH
|
Start ssh connection |
|
verbose; shows in detail what's happening while establishing connection |
|
enables graphical application support |
|
connect to ssh service not listening on default port 22 |
|
reads private key from identity file for public key authentication (not part of lecture; added from Google search when it came up in the quiz) |
-o option dest_server
Example: PreferredAuthenti cations=password
|
configures options when connecting to specified destination (Example: require a password; can use commas to specify multiple) |
|
|
Generates a public/private key pair |
|
generates key pair without extra prompts ( ''
= no passphrase; -f
specifies non-default file location) |
|
|
Installs public key on destination server |
|
specifies which public key to install |
Misc. Commands
|
Displays a short, one-line summary of what the command does |
|
Tells you what kind of file "something" is (More reliable than file extension) |
|
Creates output ( print
= Python equivalent) |
|
Displaying, setting, calculating... basically all things date-related |
|
display current date in international format (YYYY-mm-dd) |
|
display current time (24-hr clock) |
|
display # of seconds since epoch |
|
|
Shows the hostname of the current system. That is all. |
|
Shows IP address associated with specified hostname |
|
Shows properties of current system (hostname, OS, kernel, etc.) |
|
sets hostname to "new_name" |
|
|
Generates an SOS report |
|
lists available plugins for SOS (recommended to pipe to less
) |
|
automatically associates generated report with your Red Hat account (enables browsing the data via the web portal) |
|
Does nothing for specified time (used for scripting) |
|
Splits terminal window into multiple separate panes (I think) |
|
Opens window of gnome icons/emotes |
|
Opens built-in calculator (like Windows) |
|
|
|