Linux Terminal Cheat Sheet
Commonly used commands
This quick reference helps you get familiar with the following basic Linux commands:
which- Get the full path to a command's executable file.yum- Search for, install, remove, and update packages and dependencies for Fedora, CentOS, and Red Hat Enterprise Linux (RHEL).
apt- For the handling, installation and removal of software on Debian and Debian-based Linux distributionspacman- For the handling, installation and removal of software on Arch-based Linux distributionsdnf- DandifiedyumFor the handling, installation and removal of software on Red Hat-based Linux distributions as a replacement for normalyum
cat- Display file contents on the terminal.clear- Clear the terminal display.echo- Print text or variables in the terminal.top- Get information about running processes.systemctl- get or set the status of a process or service on the devicejournalctl- Print log entries from the systemd journal
env- Display all environment variables running on the system.export- Export environment variables.printenv- Print a particular environment variable to the console.source- Execute commands stored in a file from within the current shell, or refresh environment variables.
cd- Change to another directory.cp- Copy the contents of the source directory or file to a target directory or file.find- Locate a file or directory by name.grep- Search for a string within an output.ls- List the contents of a directory.mkdir- Create directories.more- View and traverse the content of a file or stdout.mv- Move or rename files.pwd- Get the name of the present working directory.rm- Delete files or directories.tar- Extract and compress files.chmod- Change Mode, > The chmod, or change mode, command allows an administrator to set or modify a file’s permissions. Every UNIX/Linux file has an owner user and an owner group attached to it, and every file has permissions associated with it. The permissions are as follows: read, write, or execute.
df- List disks and current disk usagelsblk- list block device currently mountedfdisk -l- list all connected device and their partitions
curl- Get or post a file to or from the Internet according to a URL.ip- Gets the IP information for the physical or virtual machine.netstat- Get information about network connections and more.ssh- Establish a secure encrypted connection between two hosts over an insecure network.wget- Direct download files from the Internet.
&&- Execute commands in a sequence.kill- Removes a running process from memory.ps- Display active processes.
poweroff- Shut down a computer.restart- Restart a computer.
whoami- Display the user ID.groupadd- Create a new groupgroupmod- modify an existing groupgroupdel- delete an existing groupchage- change age of valid passwd for user
Common Operators used in commands
|- The pipe symbol, pipe the output of one command to another||- this does in fact not mean double pipe, this means OR, if a specified command fails, execute the other.run A || run B, will run either A or B.>>- Append to a file preserving it's existing content>- Append and overwrite contents of a file<- Known as input redirection, take the input from somewhere, example:cat < fileA.txtwill display the contents of fileA.txt<<- Here document, takes multiple lines of input to the given command and when the given keyword is types ends the command Example:cat > output.txt <<END, will allow you to type multiple lines in the command until you type END to close.=- standard assignment operator, assigns a variable a value!- this means not, as in!=means does not equal.;- will allow you to run multiple commands in a single line, this simply separates them\- escape character to allow you to display characters uninterrupted.&- run command and send task to background
Usage Syntax for the commands above
Most of the syntax for how to use the commands above is as simple as just using the man pages for each respective command. They will indicate usage syntax and any flags you have to type and other operators you need to use with it.
A rule of thumb regarding flags is
- -a = typically means all
- -l = typically means list
- -f = typically means force
- -r = typically means recursive
User and Group Management
usermod -aG sales jdeng.
sudo useradd jdeng
sudo groupadd sales
sudo usermod -aG sales jdeng
sudo tail /etc/group | grep sales
Piping output from one command to another
This command displays the contents of file A and then pipes it's output to grep to search for a specific string inside the file.
cat fileA.txt | grep fileAText
The same can be done with directories
ls | grep Documents
This lists the current working directories folders and files and then pipes it to grep to look for a file of folder called documents.
This can also be done using the
Electric Meatball's Digital Garden Home
Permissions
User and Group Permissions Cheat Sheet