FOSSLinux with a Cool Linux Commands Cheat Sheet!
The world of Linux is uniquely structured by its maze of commands that continue to make it more than just an ordinary operating system. A typical Linux desktop user might relate to several hundreds of these commands. On the other hand, a server administrator used to bare-bone Linux server’s packages installation and management can count over 1000 differing commands.
So the real question this article piece is asking you is this, how many Linux commands are you familiar with? If we took a survey on all FossLinux readers, the majority answer would be ‘only a handful.’ This response is what this article is here to fix. There is more to using Linux commands on your Operating System terminal than just updating your system and navigating to user and system directories. If you are a Linux user, then you must flexibly adapt to the usage of as many Linux commands as possible.
The reason for memorizing most of the Linux commands is not because they are too many but because they are too random for you to categorically relate to the scenarios that best apply to each of them. FossLinux is here to fix this problem. We want to map each Linux command to where they belong categorically.
This approach’s expected long-term effect is that you continuously reference this Linux command cheat sheet based on the category of each specified command you seek. And because practice remains the initiator of perfection, you won’t have to remember or reference this article within no time. It will be your muscle memory doing all the work as you perfectly key-in the commands of your choice with complete adherence to their syntax rules.
Linux commands cheat sheet
Time to key-in these categorical Linux commands.
Commonly Used Linux Commands
You will most probably find yourself randomly needing to use these Linux command sets to improve your user experience and flexibly meet any set OS objectives.
|It is a list command and will display the directories and files visible under the present working directory
|Goes a step further to display or list files in sub-directories of the present working directory
|The argument -a in this list command helps list all the hidden files in the present working directory
|The argument -al in this list command gives a detailed list of the displayed files and directories with extra information such as size, permission, owner, etc.
|cd or cd ~
|Takes you to the Home directory of your Linux operating system
|navigates you backwards to the parent directory of the current directory you are under.
|combine it with a target directory under the present working directory to navigate to it e.g cd Downloads
|Takes you to the root directory of your Linux operating system
|cat > filename
|It will create a file called filename
|It will display the contents of a file called filename
|cat file_1 file_2 > file_3
|Joins the content of file_1 and file_2 and copies the result to a newly created file_3
|mv file_random "defined file path"
|It will move the file called file_random to the target file path or destination you will define.
|mv file_name new_filename
|It will rename the file called file_name to a new file name called new_filename
|A command used by sudoer users to execute privileged commands applicable to a root user or superuser.
|It will delete a file called filename
|Use it with a Linux command you do not understand to get help on how to use it. E.g man sudo
|It will display a list of the previous Linux terminal commands you have executed under that specific session.
|It will clear your command-line interface if you feel it is too crowded.
|it will create a director called directory_name
|It will delete a directory called my_directory
|You can use it to rename a directory or a file
|It will divide or split a file to x defined columns.
|Use it to add a header to a target file.
|Uses Line numbers to denote a target user file.
|lp -nc, lpr c
|It is a printing function and in this case it will print c copies of a target file.
|lp -d lp -P
|Helps you identify the name of the printer you are using.
|apt or apt-get
|A Debian distro package command for installing system updates and package applications
|mail -s 'mail_subject' -c 'cc-mail_address' -b 'bcc-mail_address' 'to-mail_address'
|Use this command to send an email from the terminal.
|mail -s "mail_subject" to-mail_address < attachment_filename
|Use this command to also send an email from the terminal but this time with an attachment.
Linux Commands for System Information
You will find these commands useful when you want to query specific information about your Linux system.
|Displays basic system information like machine name and the supported operating system architecture.
|Outputs the kernel release information like the kernel version.
|If you are using any Linux distro, this command displays its Distributor ID, Description, Release, and Codename.
|Outputs how long your Linux system has been active together with the load average of this duration.
|Outputs your system's hostname or the name you have given your Linux machine
|Outputs the assigned IP address your system is currently using depending on the network connection it is under.
|A useful command for you to gauge how many times your system restarted.
|Useful in displaying the current date and time.
|Outputs the present month's calendar.
|Lets you know who or which systems are online especially if you are in a large network.
|Outputs the name of the current user using the Linux system
Linux Commands for File Permissions
File permissions in Linux relate to Read (r), Write (w), and Execute (x) privileges. They employ changes associated with directory and file ownership. This ownership privilege can apply to a specific user, a user group, or other user levels defined within the Linux system.
|Outputs the file type and the file permissions needed to access the target file.
|chown root /u
|In this command, the ownership of /u is transferred to the root user.
|chown user:group file_name
|The user and group privileges linked to file_name are changed.
|chmod 777 [file_name]
|Everyone access the file called file_name will have read, write, and execute permissions.
|chmod 755 [file_name]
|The owner of the file called file_name will have read, write, and execute permissions while other users will only have read and execute permissions.
|chmod 766 [file_name]
|The owner of the file called file_name has complete access to it while group and other users can only read and execute.
|chown [user] [file_name]
|The ownership of the file called file_name is assigned or changed to a new owner called user.
|chmod -c -R
|Assign a file the read, write, and execute permissions.
|touch -a -t
|Useful in creating or modifying a file timestamp.
|chown -c -R
|Useful in changing the ownership of an assigned or owned file.
|chgrp -c -R
|Useful in changing the group permission of a file.
Linux Commands for Networking
Under a Linux operating system, it is almost impossible not to cross paths with network-related tasks. The following commands will be useful along the way.
|SSH username@ip_address or hostname
|Enables SSH login or sign-in to a remote Linux machine by specifying the machine's username and IP address.
|Useful in analyzing the responsiveness of a hostname connected to a network.
|Helps you view files under a remote computer's active directory.
|Access a directory called dir_name on a remote computer.
|It will upload a file called filename from your local computer to a target remote computer.
|It will download a file called filename from a specified remote computer to your local machine.
|Logout from a remote connection.
|ping -c hostname
|It will print a routing packet trace associated with the targeted hostname or IP address
|Grants user access to openSSH client.
|Used to dump network traffic.
|Grants access to the TELNET protocol's user interface.
|netstat -r -v
|Prints network routing, information, and connections.
|ip addr show
|Outputs network interfaces and their related IP addresses.
|ip address add [IP_address]
|Used under interface eth0 to assign an IP address.
|Outputs configured network interfaces' IP addresses.
|A netstat command for revealing active or listening ports on a network.
|A netstat command for displaying udp and tcp ports.
|Reveals more information regarding an active domain name on the internet.
|Reveals DNS information and configuration regarding an active domain name.
|dig -x host
|It is applicable when dealing with DNS and will reverse lookup an active domain.
|dig -x [IP_address]
|It is also applicable when dealing with DNS and will reverse lookup an active IP address.
|It will lookup the IP address of an active domain
|host -I hostname
|It will output the local IP address of the specified hostname with other additional useful information.
|Useful in downloading a file from a specified domain name storage directory.
|Outputs all the network interface details of a system with inclusion to the IP address.
|Outputs eth0 configuration and address details.
|Used to manage hardware and network drivers query and control settings
Linux Commands for Archives and File Compression
You will never fail to come across file archives or files in a compressed state within the Linux operating system environment. The following commands will be useful.
|Used for creating or extracting files with .tar or .tgz extensions.
|gzip, gunzip, zcat filename
|Used in creating, extracting. or viewing files with .gz extension
|Used in creating or extracting files with .Z extension.
|zip, unzip -v
|Used in creating or extracting files with .Zip extension.
|Used in creating or extracting files with .rpm extension.
|Used in creating or extracting files with .bz2 extension.
|Used in creating or extracting files with .rar extension.
|tar cf [compressed_filename.tar] [file_name]
|This command creates an tar archive called compressed_filename for the file_name file.
|tar xf [compressed_filename.tar]
|This command extracts the tar archive called compressed_filename.
|tar czf [compressed_filename.tar.gz]
|This command compresses a tar file into a gzip archive.
|tar cf my_archive.tar directory
|This command creates a tar archive called my_archive with a directory in it.
|tar xzf my_archive.tar.gz
|This command extracts a compressed tar file inside a gzip archive
|tar cjf archive.tar.bz2 director
|This command compresses a tar file inside a bz2 archive.
|tar xjf archive.tar.bz2
|This command extracts a tar file compressed inside a bz2 archive.
Linux Commands for Installing Packages
Since you will be using the Linux terminal to install most of your packages from various repositories, you will need to memorize the following commands.
|yum search [keyword]
|Trace a package installation based on specific keywords.
|yum install package.rpm
|The use of a YUM package manager to install and configure a package.
|yum info package
|The use of the YUM package manager to find more information about a package before optionally proceeding with its installation.
|rpm -i package.rpm
|Using the RPM package manager to install a downloaded package.
|yum remove package
|Using the YUM package manager to uninstall or remove a package from your system.
|tar zxvf sourcecode.tar.gz
|Command sequence to install a package software that comes as a source code.
|dnf install package.rpm
|Using the DNF package manager to install a package software.
|apt install package
|Using the APT package manager to install a package software.
|rpm -e package.rpm
|Using the RPM package manager to remove or uninstall an rpm package
Linux Search Commands
The commands in this category effectively deal with file patterns, sizes, and even their naming conventions.
|grep [pattern] [file]
|Employs a specific pattern to search the contents of a file.
|grep -r [pattern] [directory_name]
|Recursively or repeatedly searches within a specified directory for a defined pattern match.
|It will track and locate directories and files based on a name identity.
|find [/path/to/folder/location] -name [a]
|Traces a specific system directory location then queries the names of its files and folders based on a character match. In this case [a]
|find [/path/to/folder/location] -size [+100M]
|It will trace a system directory location and list the files within it that are bigger than 100 M in size.
|find /home/FossLinux -name 'prefix*'
|Traces a specified system path for files with a matching prefix.
Linux Commands for SSH Logins
SSH logins are useful when you want access to remote computers or servers. These commands give you undisputed flexibility in file access, management, and manipulation.
|Connects you to a remote machine or server based on a valid username and hostname or IP address.
|Connects you to a specified host through the default port 22.
|ssh -p [port] username@hostname
|Connects you to a remote machine or server through a specified port.
|Uses telnet's default port 23 to connect you to a target hostname, remote machine, or server.
Linux Commands for File Transfers and Management
It is very rare to log-in to a Linux operating system environment and not feel the urge to transfer a file, directory, or folder from one system path to another. These file management commands ensure that you won’t have to be switching from the command-line interface to the desktop graphical interface each time you feel like making a file or directory change or query.
|This command is useful when you need to find a specific file
|ls -a -C -h
|Lists or displays the content of an active directory.
|rm -r -f
|Used to remove or delete active files and directories instances.
|Uses updateddb(8) to track and find files on your system.
|cp -a -R -i
|Used to copy directories or files from an active directory instance.
|Give important information regarding the disk usage (storage space) on your Linux system. It is efficient when combined with the Sudo command.
|file -b -i
|Helps identify the type of file on your system.
|mv -f -i
|Used for moving directories or files to a different system path or location.
|grep, egrep, fgrep -i -v
|Useful in printing lines with a matching pattern.
|scp file.txt server:/tmp
|Uses secure copy command to copy file to a remote server. In this case the tmp folder
|scp server:/var/www/*.html /tmp
|Uses secure copy command to copy files from a remote server to a directory on a local machine. In this case it will copy all files with the .html extension.
|scp -r server:/var/www /tmp
|It will recursively copy all the files and directories on a remote server's active directory to a target machine directory. In this case the tmp directory
|rsync -a /home /backups/
|Synchronizes the content of two directories (/home and /backups) on the same machine.
|rsync -avz /home server:/backups/
|It synchronizes the content of an active director on a local machine with the content of an active directory on a remote server.
Linux File and Directory Commands
It would help if you also had flexibility in dealing with your user and system files and directories.
|It will list the files and directories under an active director path.
|Lists only active files, but in a long and detailed list.
|reveals the present directory you are working under.
|It will create a directory with the specified name.
|It will delete a file with the specified name.
|rm -r [directory_name]
|It will delete a directory with the specified name.
|rm -rf [directory_name]
|It will recursively and forcefully delete a directory with the specified name.
|cp filename1 filename2
|It will copy the contents of filename1 to filename2
|cp -r [directory1] [directory2]
|It will recursively copy the content of directory1 to directory2
|mv filename1 filename2
|It will rename filename1 to filename2
|ln -s /path/to/[file_name] [link_name]
|Use this command to create a symbolic link (link_name) to a specified file name (file_name).
|Used to create a new file with a specified extension.
|It will open and display the contents of a specified file.
|It will also open and display the contents of a specified file.
|cat filename1 >> filename2
|It appends or adds the content of filename1 at the bottom of filename2.
|Outputs the first ten lines of a specified file name.
|Outputs the last ten lines of a specified file name.
|gpg -c filename
|Used to encrypt a specified file.
|Used to decrypt a specified file with a .gpg extension.
|Outputs number of bytes, lines, and words of a specified file name.
|This command enables a user to browse through the content of a text file
|tail -f filename
|Not only outputs the last 10 lines of a specified file but also follows the growth progress of this file when more content is added to it.
|Takes you to the Home directory of our Linux system
|Takes you to the previous active directory or one level up.
|Navigate to the location of a specific directory name.
Linux Commands for Disk Utilities and Usage
It is also important to know how to interact with the various hardware components that connect with your Linux system.
|Works with mounted systems to reveal their free and used space.
|Works with mounted systems to reveal their free inodes. These inodes hold disk block location data an other attributes.
|Reveals disk information like types, sizes, and partitions.
|Outputs files and directories disk usage.
|Outputs your currently active directory's disk usage.
|Outputs the target mount point associated with all your file system.
|mount device_path mount_point
|Use this command syntax to mount a device.
|mkfs -t -V
|Use this command to create a new file system.
|Used for updating a file system, especially after lvextend*
|fsck -A -N
|Used to check and repair a file system.
|Used for creating a physical volume.
|mount -a -t
|Used for mounting a file system.
|Used for creating a logical volume.
|unmount -f -v
|Used for unmounting a mounted file system.
Linux Commands for Environment Variables
An environment variable describes the environment behavior of your operating system. The usage and description of the following commands make more sense to this definition.
|Outputs the value of a defined variable on the terminal.
|Outputs data related to all environment variables.
|variable_name = variable_value
|Use this command syntax to assign a variable name with a variable value.
|Used to remove or get rid of a variable.
|export Variable = value
|Used to assign an environment variable a new value.
Linux Commands for System Processes Management
If you are looking for an internal grip or understanding of how your Linux operating system relays its functions and operations, then the following commands will be useful.
|Sends a running process to execute in the background.
|Sends a stopped or halted process to keep executing on the foreground.
|Outputs all active processes details.
|It is an interactive process viewer command.
|Outputs a running process's status to a system user.
|Outputs all active or executing processes on the Linux system.
|ps -ef | grep process_name
|Outputs the running process information for a specified process name.
|Outputs a running processes's status in reference to its process ID.
|Reveals the process ID of a specified process.
|Kills a running process based on its process ID.
|Grants execution rights to a process with an assigned priority.
|Changes or alters the execution priority of an already running system process.
|Outputs free and used storage information regarding the system's hard disks.
|Outputs information about the system RAM's and swap's free and used memory.
|Also outputs information about the system RAM's and swap's free and used memory.
|Stops all the actively executing processes by their process names.
|Will stop a running process based on the process name.
|Outputs the Linux system's CPU temperature.
|Outputs actively running processes and provides an interface for real-time monitoring of these processes.
|kill -1 -9
|Used to send a signal to a running process.
|Used for managing system services through an executable sysV init script. You can start, stop, or restart the specified system service.
|Outputs a snapshot of the current running processes.
|Outputs system messages. Helps in troubleshooting the health status of your Linux system.
|Executes a program in the system background.
|Moves a running job n to the system's foreground.
Linux Commands for VI Editing
The command sequences related to the VI editor let you manage your files from the terminal without seeking a text editing app with a graphical interface. VIM is an improved version of this editor with additional features. The VIM editor absorbs all the implementation of the VI editor’s commands.
|launch the VIM editor.
|quit the editor without saving the implemented changes.
|quit the editor and also make changes to the open file.
|Takes the editor to insert mode and initiates a cursor.
|An insert mode that enables the system user to write their input after a cursor.
|An insert mode for writing at the end of the line.
|Used to exit the insert mode.
|Undo Vim command for the last change.
|Undo Vim command for an entire line.
|Insert mode for opening a new line.
|Vim command to delete a line.
|Vim command to delete three lines.
|Vim command to delete line content(s) that follow or succeed the cursor.
|Vim command to delete line content(s) that follow or succeed the cursor and additionally allows the system user to insert new text.
|Vim command to delete a word.
|Vim command to delete four words.
|Vim command to change a word.
|Vim command for character deletion at the cursor.
|Vim command to replace a character.
|With this command, all the characters succeeding the cursor are overwritten.
|Command to substitute a single character under cursor and then continues to insert mode.
|Command to substitute an entire line and then initiate insert mode at the beginning of that same line.
|Vim command to change the case (upper or lower) of individual characters.
Linux Commands for File Editors
You can use the following Linux command shortcuts to access your favorite file editor without the need to navigate to the Graphical User Interface to launch them
|Launches a basic editor.
|Launches visual editor.
|Launches the GNU nano editor.
|Launches an editor in view or read-only mode.
|Launches emacs, an extensible and customizable system editor.
|Launches sublime text editor.
|launches stream editor.
|launches pico, a simple editor.
Linux Commands for File Utilities
There is more to how you can interact with files on a Linux operating system. These Linux commands paint a clearer picture.
|Command for translating or deleting a character.
|uniq -c -u
|Command for reporting or omitting repeated lines.
|Command for splitting a file into segments.
|This command prints the number of bytes, words, and newlines on a specified file.
|Outputs the first few contents of a specified file.
|removes or deletes a file's section.
|Command to compare files line by line.
|Given that two files have a common field, this command will join the lines of these files.
|Enables a system user to view the contents of a file, a single file page view at a time.
|Command to sort the lines within a text file.
|After two files are sorted, this command can be used to sort them line by line.
|Command to concatenate or link files to a specific standard output.
|Command to output the last portion of a file.
Linux Commands for Scripting
Once your skillset on using the Linux operating system improves with time, you might be inspired to scribble some scripts from your OS environment. These commands apply both to the scripting languages you might be familiar with and the scripting environment setup to make your Linux OS life as comfortable as possible.[table “49” not found /]
Linux Commands for Hardware Information
What if you want to know how your hardware is performing under a Linux operating system environment? Consider the use of the following commands.
|Outputs the kernel ring buffer messages.
|Outputs CPU information of your machine.
|Outputs Memory information of your machine.
|Outputs both free and used machine memory info.
|Outputs the system's hardware configuration information.
|Outputs the system's block devices information.
|Outputs the system's PCI devices.
|Outputs the system's USB devices.
|Outputs the system's hardware information on DMI/SMBIOS related to the BIOS.
|hdparm -i /dev/disk
|Outputs a specified disk data information.
|hdparm -tT /dev/[device]
|Used with a specified system disk to output its read speed test performance.
|badblocks -s /dev/[device]
|Used to reveal and test unreadable blocks on a specified disk sda.
Linux Commands for Performance Monitoring and Statistics
It helps to statistically assess how the Linux OS is adapting to its hardware environment.
|Outputs processor-related statistics.
|Outputs statistical data related to the system's virtual memory.
|Outputs I/O (Input/Output) statistics.
|Outputs all the system's open files.
|lsof -u user
|Outputs a list of all the files opened by a system user.
|watch df -h
|A command to output periodic system updates.
|tail 100 /var/log/messages
|Command to output the most recent 100 syslog messages. The Debian systems equivalent of this command is /var/log/syslog
|tcpdump -i eth0
|An interface eth0-related command for outputting captured packets.
|tcpdump -i eth0 'port 80'
|Command for monitoring traffic through port 80
Linux Commands As Keyboard Shortcuts
To be good at these commands, you only need to master a few keyboard strokes.
|Ctrl + C
|Command to kill a running process.
|Ctrl + Z
|Command to stop a currently active process.
|Ctrl + W
|Command to cut a single word preceding the cursor.
|Ctrl + U
|Command to cut a line fragment preceding the cursor.
|Ctrl + K
|Command to cut a line fragment succeeding the cursor.
|Ctrl + Y
|Command to paste from clipboard.
|Ctrl + R
|Command to recall the last used command.
|Ctrl + O
|Command to execute the previously recalled command.
|Ctrl + G
|Command to exit command history.
|Command to execute a previously executed command.
|Command to sign off from an active session.
Linux Misc Commands
These are miscellaneous commands that are also useful in further improving your Linux operating system’s user experience.
|Command to print formatted date.
|A backquote to execute a specified command.
|A command for assigning or removing an environment variable.
|Command to print a calendar.
|A command used to evaluate an expression.
|Launches a high-precision calculator shell.
|Reveals the current system directory you are under.
The Linux Command Cheat Sheet exists to make the life of individuals pursuing a comfortable Linux life easy. You can comfortably adapt to these commands to make your Linux OS usage more efficient. As you have noticed, the categorical grouping of these commands has a few duplicated commands in other command categories. It just shows how flexible and adaptable a Linux command can be instead of being restricted to a single system function. Good luck in mastering and implementing these Linux Command Cheat Sheet categories.