Linux Command Set 2 For DevOps
This is a multi-part series on DevOps 101. Access the complete DevOps series by clicking HERE
Access Set 1 of the Linux Commands for DevOps by clicking HERE
The du command
The du command, short for “disk usage”, is a useful tool for checking the size of files and directories on a Linux or Unix based system. It calculates and reports the amount of disk space used by each file and directory in a given path. By default, it displays the size of each directory, its subdirectories and their total sizes in a human-readable format. It also provides options for sorting and displaying the output in different ways, making it a useful tool for managing and optimizing storage space.
The df command
The df command is a Unix/Linux utility that displays the amount of disk space available on the file system. It is used to get a quick overview of the file system’s capacity and how much space is being used. The command also shows the system’s mount points, device numbers, and the amount of used and available space. With additional parameters, users can customize the output format, exclude specific file systems, and display file sizes in different units.
The basename command
The basename command is a simple Unix tool that is used to display the basename of a file. The basename is the last segment of a file’s path, which typically represents the actual name of the file itself. The basename command can be useful in scripts and other automation tasks where the full path of a file is not relevant, and only the file name is needed. The command can also be used to strip file extensions from a filename, which can be useful when working with certain types of files.
The dirname command
The “dirname” command in Unix-based systems is used to retrieve the directory portion of a given file path. This command is useful in situations where only the directory name is needed, for example when creating a file in a specific directory or navigating to a directory with the command line. The output of the “dirname” command is simply the directory name of the specified file path, without the file name itself.
The ps command
The ps command is a powerful tool for monitoring system processes on Unix and Unix-like operating systems. It allows users to view information about currently running processes, and can be used to kill or send signals to specific ones. The output of the ps command can be customized with a variety of flags, and can provide valuable insights into system performance and resource usage.
The top command
The top command is a popular Unix-based tool used to monitor system activity and display information about processes and resource usage. It provides a real-time, dynamic view of a system’s CPU, memory, and other key performance metrics. With top, system administrators can quickly identify processes that are consuming excessive resources and take appropriate action to optimize system performance. Top is a powerful tool for anyone looking to gain detailed insight into the operation of a Unix-based system.
The kill command
The “kill” command is a Unix command used to terminate a process. It sends a signal to a process, asking it to terminate. The signal can be specified by the user, but the default signal is SIGTERM, which allows the process to do any necessary cleanup before shutting down. If the process does not terminate within a certain amount of time, the signal can be escalated to SIGKILL, which forcefully terminates the process. The “kill” command can be a useful tool for terminating unresponsive or misbehaving processes.
The killall command
The killall command is a Unix/Linux utility used to terminate multiple processes by their names. It sends a signal to specified processes, requesting them to terminate. Unlike the kill command, which terminates a process by its process ID (PID), killall identifies a process by its name. The command is handy when you need to terminate all processes associated with a particular program or task quickly. However, it’s essential to use the command with caution as it may cause unintended consequences if used incorrectly.
The jobs command
The “jobs” command is a built-in Unix command that displays a list of all current jobs running in the background. Each job is assigned a unique number, which can be used to manage the job using other built-in commands. The output of the command displays the job number, the status of the job (running or stopped), the name of the command that launched the job, and the job ID. This command is useful for managing multiple tasks running in the background on a Unix system.
The bg command
The bg command in Linux allows a suspended job to continue running in the background. This means that the user can free up the terminal for other tasks while the job continues running. The bg command can also be used to change a job status from suspended to running. The command is executed with the job ID or job specification as an argument.
The fg command
The “fg” (foreground) command is a built-in command in UNIX and UNIX-like operating systems. It is primarily used to bring a previously suspended process to the foreground and allow it to continue running. This command is typically used to reclaim a terminal that has been temporarily taken over by another process, such as a job running in the background. To use the “fg” command, simply enter the command followed by the job ID number of the process to be brought to the foreground.
The type command
The “type” command is a built-in command in many operating systems, including Unix-based systems and Microsoft Windows. Its primary function is to display the contents of a file on the terminal or command prompt. This command can be useful for quickly checking the contents of a file without having to open it with a separate program. Additionally, the type command can be used in batch files or shell scripts to automate certain tasks that involve reading files.
The which command
The “which” command is a utility used in command-line interfaces to locate an executable file in the user’s path. When a user enters the name of a command, the “which” command will search through all the directories in the user’s defined path to find the file that contains the command. It can be particularly useful in debugging or in situations when a specific version of a program needs to be executed. The output of the command will typically display the full path to the executable file.
The nohup command
The nohup command is used in Unix and Linux operating systems to run a command or script that will continue to execute even after the user logs out or is disconnected from the computer. By default, when a user logs out, any process that was started by that user will also be terminated. However, by using nohup, the process becomes immune to the hangup (hup) signal, allowing it to continue running in the background even after the user has left the system. This can be useful for long and resource-intensive tasks that need to be completed without interruption.
The xargs command
The xargs command is a powerful utility in Linux and Unix systems that helps in passing command line arguments to other commands. It reads items separated by white space from input, and executes a specified command for each item. The command can also be controlled to limit the number of arguments passed per execution. This makes it useful for piping the output of one command to another, as well as for handling a large number of files or directories.
The vim command
Vim is a powerful text editor that is highly customizable and widely used by software developers and system administrators. It includes a wide variety of keyboard shortcuts, also known as commands, which can be used to perform various tasks such as navigating documents, editing text, and managing files. Some commonly used commands include yank (copy), paste, undo, and search. Vim is known for its efficiency and effectiveness, making it a popular choice among experienced users.
The nano command
Nano is a popular text editor used in the command line interface. It is known for its simplicity and ease of use, making it a great option for both experienced and novice users. Nano includes features such as syntax highlighting, search and replace, and multiple undo/redo. While it may not have the advanced capabilities of other text editors, its straightforward interface makes it a go-to option for quick and simple text editing tasks.
The emacs command
Emacs is a text editor that is highly customizable and extensible. It was first created in the 1970s and has since grown into a powerful tool for programmers and writers alike. Emacs has a steep learning curve, but its many features and capabilities make it a favorite among enthusiasts. It can be used for everything from editing simple text files to writing complex computer programs. Emacs also has a large community of users who have created countless plugins, themes, and other tools to extend its functionality even further.
The whoami command
The “whoami” command in Linux is used to display the username of the current user. It is a simple and useful command that comes in handy when working in a multi-user environment where different users log in and out frequently. The command has no options and can be used in the terminal or shell prompt. The output of the command is a single line that displays the username of the current user. This command can be useful for troubleshooting purposes or when you need to know which user is currently logged in to a particular system.
The who command
The “who” command is a Unix/Linux command used to display information about users who are currently logged into the system. It shows details such as the username, terminal, login time and remote host (if applicable). It is particularly useful for system administrators who need to monitor user activity and troubleshoot issues related to user logins. The “who” command can also be combined with other commands such as “grep” to filter the output based on certain criteria.
The su command
The su command in Linux and Unix systems is used to temporarily switch the current user to another user or become a superuser. It stands for “substitute user” and can be executed by users who have sufficient privileges to switch to another user account. The command is often used when performing administrative tasks that can only be executed by a superuser account. The su command can be combined with other commands to execute them with elevated permissions, providing the user with complete access to system resources and files.
The sudo command
The sudo command in Linux allows a user to execute commands as another user, typically the superuser. This is useful for performing administrative tasks that require elevated privileges. By default, the superuser account is disabled in most Linux distributions for security reasons, so using sudo is the recommended way to perform administrative actions. The sudo command also keeps a log of every command executed with it, providing an audit trail for system administrators.
The passwd command
The passwd a command in Unix-like operating systems that is used to change the password of a user account. The command is typically used by the user to change their own password, but it can also be used by a system administrator to change the password of another user. When the command is executed, the user is prompted to enter their old password and then their new password. The new password is then encrypted and stored in the system’s password file.
The ping command
The ping command is a network utility tool used to test the connection between two devices on a network. When this command is executed, the sending device sends a request packet to the receiving device. If the packet is received successfully, the receiving device sends a response packet back to the sending device, indicating that the connection is working properly. This tool can be useful in diagnosing network problems such as high latency or packet loss. The ping command is available on most operating systems including Windows, Mac OS, and Linux.
The traceroute command
Traceroute is a command-line tool used in networking that allows you to track the path taken by data packets between your computer and another destination on the internet. Each hop in the route is listed with the IP address of the device it passed through, as well as the latency or time it took for the packet to travel to that device. Traceroute is useful for determining network connectivity issues and for optimizing routing paths.
The clear command
The “clear” command is a command used in various computer programs and terminals to clear the current screen or terminal buffer. This command clears any text or information currently displayed on the screen or terminal, providing a clean slate for new information to be displayed. The “clear” command is particularly useful in situations where the screen or terminal output is cluttered, making it difficult to read or navigate. The command can be easily executed using a keyboard shortcut or by typing “clear” into the terminal/command prompt.
The clear command
The “clear” command is a computer command used to erase all existing content from a given area such as a console or terminal window. This command is often used to reset a display or console that has become cluttered with previous inputs. Using the “clear” command can provide a fresh start for an area which can help improve productivity and clarity.
The history command
The history command is a useful tool for users working in the command line interface (CLI) of a Unix-based operating system. When executed, this command lists previously executed commands for the current user. The history command essentially provides a log of previously executed CLI commands, along with a numerical ID assigned to each command. This can be helpful for quickly re-executing a previously used command without retyping it, or for reviewing previously executed commands for troubleshooting or forensic purposes. The history command has evolved over time, with various iterations and enhancements added to different versions of Unix and Unix-like operating systems.
The export command
The export command is a commonly used command in computer programming and software development. Its primary function is to export data or code from one location to another. This can be especially useful when working with large projects or collaborating with other developers. When used correctly, the export command can help to improve productivity and efficiency, making it an essential tool for programmers of all skill levels.
The crontab command
Crontab is a command in Unix/Linux operating systems which allows users to schedule commands or scripts to be executed automatically at a specified date and time. The command uses a simple text file called crontab file, which lists the commands to be run, as well as the schedule on which to run them. Crontab is useful for automating tasks that need to be executed periodically, such as backups or system maintenance. It can also be used to schedule commands to run at non-standard intervals, such as every five minutes or every other day.
The uname command
The uname command is a commonly used command in Unix and Unix-like operating systems. It is used to display detailed information about the current system, such as the operating system name, version, release number, and machine hardware name. By default, the command displays the kernel name, but options can be used to display additional information such as the hostname and processor type.
The env command
The env command is a command-line utility in Unix and Unix-like operating systems that allows the user to display or set environment variables. Environment variables are a fundamental part of the operating system, containing information such as the user’s home directory or the location of system libraries. The env command can be used to pass values from the current environment to a command or script, as well as to set new environment variables for a specific command or script.
The printenv command
The printenv command is a Unix and Linux utility that displays the current environment variables. When called without any arguments, it will display the names and values of all variables currently defined in the environment. Users can also specify a single variable as an argument and only see that variable’s value. This command is especially useful for debugging shell scripts and setting up development environments. It is also commonly used to access system-related environment variables such as PATH and HOME.
Thank you for taking the time to read this post. I hope it has been both informative and enjoyable. If you have any further questions or comments, please feel free to leave them below. Your feedback is always appreciated. Thank you again for your support and I hope to see you soon!
Stay tuned for the next post! Access Set 1 by clicking HERE. Access the complete DevOps series by clicking HERE