Essential Linux Commands Every Engineer Should Know
Binayak Bhandari, Ph.D.
Among World’s Top 2% Scientists in Industrial Engineering & Automation; AI expert in Engineering Applications
Welcome to my 22nd episode of my Engineering Exploration series. In this article, we’ll explore 35 Fundamental Linux Commands that every engineer should know. Whether you’re an experienced professional or just starting out, these commands are essential tools for navigating and mastering the Linux environment.
Many beginners often confuse Unix and Linux, thinking they’re the same with different names. While they share many similarities, there are key differences, such as licensing. Linux (e.g., Ubuntu, Fedora, Debian) is open source, typically released under the GNU General Public License (GPL), which allows users to freely view, modify, and distribute the code. In contrast, Unix is often proprietary, with licensing agreements controlled by different commercial vendors.
With these differences in mind, let’s dive into thirty-five (35) fundamental Linux commands that will enhance your proficiency in the Linux environment. The screenshots provided in this article are from Ubuntu running on a Raspberry Pi, offering practical insights into each command.
‘ls’ – List Directory Contents
One of the most frequently used Linux commands is ‘ls’ which lists all the files and directories in the current working directory.
The command, executed without any arguments, outputs all the files and directories in the current working directory. There are some variations of this command as below.
Variations
'cd' – Change Directory
While working in Linux terminal, you will have to move from one directory to another frequently. The ‘cd’ command allows you to navigate between directories in the Linux terminal. The argument for this command is the path to the directory you want to navigate. Please see following example to better understand the use case.
cd / # Change to the root directory
cd ~ # Change to your home (or personal) directory
cd /path/to/directory # Change to a specific directory
Variations
‘cd ..’ # Move up one directory
‘cd../’ # Move to root
'pwd' – Print Working Directory
The ‘pwd’ command displays the full path of the current working directory, helping you keep rack of where you are in the filesystem.
'mkdir' – Make Directory
The ‘mkdir’ command creates a new directory. This command takes one argument: the name of the directory
mkdir new_directory
mkdir dir1 dir2 dir3 #Create multiple directories at once
'rmdir' – Remove Directory
The ‘rmdir’ command removes an empty directory.
rmdir directory_name # Remove an empty directory
rmdir dir1 dir2 dir3 #Remove multiple empty directories
'touch' – Create and Empty File or Update a Timestamp
The ‘touch’ command is the easiest way to create a new file. It takes the filename as an argument as shown in the example below.
touch new_file : Create a new empty file
If you want to create multiple files, you can just use a single touch command followed by the name of the files.
Or you can use one-liner
touch existing_file # Update the timestamp of an existing file
'rm' – Remove Files /Directories
The ‘rm’ command removes files or directories.
rm file_name # Remove a file
rm -r directory_name #Remove a directory and its contents
rm -f file_name # Force remove a file without prompting
'cp' – Copy Files or Directories
The ‘cp’ command copies files or directories.
cp source_file destination_file # Copy a file
# Copy a directory and its contents (-r is recursively copying the whole folder contents)
cp -r source_directory destination_directory
'mv' – Move or Rename Files or Directories
The ‘mv’ command moves or renames files or directories.
mv old_name new_name # Rename a file or directory
The file1 file is now moved (and renamed) to file2.
mv file_name /path/to/directory # Move a file to another directory
'nano' – Text Editor
The ‘nano’ command opens the GNU nano text editor.
nano file_name # Open a file in the nano text editor
This will open the file in the GNU nano text editor as shown below. You can write and edit the file. Here I have written two lines.
To save and Exit: Press ‘Ctrl + X’ followed by ‘y’ to save.
'cat' – Concatenate and Display Files
If you want to see what is inside the file, use ‘cat’ command, which is used to display the contents of a file.
cat file_name
cat file1 file2 # Concatenate multiple files and display the output
'echo' – Display a Line of Text
The ‘echo’ command prints text or the value of a variable to the terminal.
echo “Hello, world!” # Print a message to the terminal
echo $HOME # Print the value of a variable
This command can also be used to write stuff to a new or existing file. In the below example, I am writing ‘File contents’ to the binayak1 file.
'man' – Manual Page (abbreviation of manual)
The ‘man’ command displays the user manual for any command that run on the terminal. To execute this command type man followed by a command name
man [command] #Display the manual page for the specified command.
Variations
man -f, -whatis #Display a concise one-line description of the command.
man -k, -apropos #Search for commands related to a given keyword.
man -a, -all #Display all matching manual pages for the specified command.
man[spacebar] #Move forward one page in the manual.
man [enter] #Move forward one line the manual
man B #Move backward one page in the manual
man Q #Quit the manual viewer
'useradd' – Add a new user
This command is used to create a new user.
Remember that in order to add the new user you must have the privilege of sudo. That is you must have super user access.
'adduser'
To log in as luke (we just added) use command su as below:
'chmod' – Change File Permissions (abbreviation of CHange MODe)
The ‘chmod’ command allows you to change the access mode or permissions of a file or directory, allowing you to specify who can access files, search directories, and run scripts.
The file in the Linux system have certain permissions, such as the owner has full permission to read, write, and execute, the group would have the permission to read, read but no execution permission, while the world would have read permission and not the write and execute permission.
The ‘chmod’ command is used to modify this permission so that it can grant or restrict access to directories and files.
领英推荐
chmod [options] [mode] [File_name]
Here,
·???????? Options:?Optional flags that modify the behaviour of the?chmod?command.
·???????? Mode:?The permissions to be set, represented by a three-digit octal number or symbolic notation (e.g., u=rw,go=rx).
·???????? File_name:?The file name or directory for which the permissions are to be changed.
Example: Read, write and execute permissions to the file owner:
chmod u+rw [file_name]
You can see the access mode of file ‘are’ is different from other files such as ‘my’, ‘these’.
'chown' – Change File Owner and Group
The ‘chown’ command changes the owner and group of a file or directory.
'sudo' – Execute a Command as Another User
The ‘sudo’ command allows you to execute a command with SuperUser DO privileges. Sudo is generally used as a prefix for some commands that only superusers are allowed to run. This is the equivalent of the ‘run as administrator’ option in Windows.
'df' – Disk Space Usage
The ‘df’ command displays the amount of disk space used and available on filesystems.
df -h # Display disk space in human-readable format.
'du' – Disk Usage
The ‘du’ command estimates the disk space used by files and directories
'ps' – Report Process Status
The ‘ps’ command displays information about currently running processes.
'top' – Display Linux Tasks
The ‘top’ command provides a dynamic real-time view of running system processes.
'apt'– Package managers (Debian-based)
The ‘apt’ command manages packages on Debian-based distributions. APT stands for Advanced Package Tool.
sudo apt update # Update package lists
sudo apt install package_name # Install a package
Similarly, to remove the installed package use the ‘remove’ option instead of ‘install’.
'whoami'
This command is used to determine the current username of the logged in user. This is especially useful where multiple usernames are used across different computer. It helps identify the user and the computer being accessed.
'open'
The ‘open’ command opens files or applications with the default applicaiton. This command takes one argument which is the file_name.
'head/tail'
The ‘head’ command displays the first few lines of a file and send them to standard output (your terminal screen), while ‘tail’ command shows the last few lines. To demonstrate the working of this command, I have created a txt file with some text denoting the lines in the file and saved it /home/binayak/Documents. Let's try to read the first and last 5 lines of the book.
'date'
The ‘date’ command displays or sets the system date and time.
date # Display the current date and time
'killall'
The ‘killall’ command terminates all processes with the specified name instead of using PID.
'ip address'
The ‘ip address' command displays all IP addresses assigned to network interfaces.
'ifconfig' – Display network interfaces and IP addresses
The ‘ifconfig’ command displays the network interface and IP addresses.
'ping'
The ‘ping’ command checks the network connectivity between your system and another host.
'reboot'
The ‘reboot’ command reboots/restarts the system immediately.
'shutdown'
The ‘shutdown’ command is used to power off, restart or halt the system.
shutdown [options] [time] [message]
sudo shutdown now
'clear' – Clear the terminal display
The ‘clear’ command clears the terminal screen, removing all previous output and giving the user a clean terminal to work with.
'grep' – Global Regular Expresion Print
The ‘grep’ command is used to search for specific patterns within files. It scans files for lines that match a given regular expression and outputs the matching lines.
Summary:
We looked at 35 fundamental Linux commands that is essential for any engineer working on a Linux environment. From basic file management and navigation to more advanced tasks like process control and network configuration, these commands form the backbone of daily operations on Linux systems. I hope you found this article useful. Happy learning!!
Reference:
IEGC at Davidshield Online
3 个月Great summary of the basic commands Binayak Bhandari, Ph.D. ! It's not only helpful for engineers, also for academics in Social Studies and education!!