Introduction to Linux Basics
Introduction to Linux Basics
Birth of Linux
On August 25, 1991, Linus Torvalds announced on the [Link] newsgroup that he
was working on a free operating system for 386(486) AT clones as a hobby. The initial version
(0.01) was released in September 1991. It was a basic, but functional kernel.
In 1992, Torvalds released Linux under the GNU General Public License (GPL), aligning it with
the GNU project's principles and allowing it to be freely used and modified.
Early distributions like Slackware (1993) and Debian (1993) emerged, packaging the Linux
kernel with GNU tools and other software.
Companies like Red Hat (1994) and SUSE (1994) began offering commercial distributions,
providing support and services.
2010s:
Linux became the foundation of Android, the world's most widely used mobile operating
system.
Cloud and Data Centers: Linux became the dominant OS for cloud computing, with platforms
like AWS, Google Cloud, and Azure heavily relying on Linux.
Containers: Technologies like Docker and Kubernetes, which are based on Linux,
revolutionized software deployment and orchestration.
Open Source: Linux is free and open-source software, meaning its source code is available
for anyone to view, modify, and distribute.
Modularity: Linux's modular architecture allows for customization and optimization for various
uses, from small embedded systems to large supercomputers.
Security: Linux's design principles and the open-source nature contribute to its security and
robustness.
/bin Stands for binaries, it contains tools like ls, cp, etc
/dev It stands for device, all physical devices such as USB drive,
etc are mounted here.
/mnt Stands for mount, this is a temporary mount point for regular
filesystem or empty directories.
/sbin It stands for system binaries, like /bin it also stores binaries
but these binaries are only for root user
/tmp A place to store temporary files, system clear these files upon
startup.
/usr All the binaries, documentation, libraries, and header files for
all the user applications are stored here.
1. The ls command in Linux is used to list directory contents. It provides information about files
and directories within the file system. The command has several options and flags that modify
its behavior to display various types of information.
● ls Basic Command
● ls -l Long Listing Format, displays detailed information about files and directories,
such as permissions, number of links, owner, group, size, and modification date.
● ls -a Lists all files, including hidden files (those starting with a dot `.`).
● ls -la Long Listing with Hidden Files
● ls -R Lists directories and their contents recursively.
● ls -lh Displays file sizes in a human-readable format (e.g., KB, MB).
● ls -lt Sorts files by modification time, newest first
2. The cd command in Linux is used to change the current working directory. Here’s a detailed
look at its usage
● cd [directory] directory: The path to the directory you want to navigate to.
● cd /path/to/directory Change to a Specific Directory
● cd .. Moves up one directory level.
3. The pwd command in Linux stands for "print working directory." It is used to display the
current working directory path.
● pwd This command will display the full path to the current directory you are in
Directory Not Empty: If you try to remove a directory that contains files or other directories,
you will receive an error.
6. The rm command in Linux is used to remove files or directories from the file system.
Be Cautious! The rm command permanently deletes files and directories. There's no built-in
undo or recovery feature, so use it carefully, especially with options like -f and -r
7. The cp command in Linux is used to copy files and directories from one location to another
● cp [options] source destination
● cp [Link] [Link] Copy a file to another file
● cp [Link] /path/to/destination/ Copy a file to another directory
● cp [Link] [Link] [Link] /path/to/destination/ Copy multiple files to another
directory
● cp -r source_directory/ /path/to/destination/ Copy a directory and its contents to
another directory
● cp -i [Link] /path/to/destination/ Copy files interactively (prompts before
overwriting)
● cp -p [Link] /path/to/destination/ Copy files while preserving their attributes
!!! By default, if a file with the same name already exists in the destination, cp will overwrite it
without warning. Use the -i option to prevent accidental overwrites.
8. The mv command in Linux is used to move or rename files and directories. It can be used to
move a file or directory from one location to another or to rename a file or directory without
changing its location.
9. The touch command in Linux is used to create empty files or update the timestamps of
existing files without altering their content. It's a simple yet versatile command that's useful in
various scenarios.
● touch [Link] If the specified file does not exist, touch will create an empty file.
● touch [Link] [Link] [Link] You can create multiple files at once by specifying
multiple filenames
● touch -c non_existent_file.txt Use the -c option if you only want to update the
timestamp of existing files and avoid creating new ones.
EXERCISE
EXERCISE
1. Start a new terminal
2. touch [Link] Create an empty file
3. mkdir my_directory Create a new directory
4. cp [Link] my_directory/ Copy file to the directory
5. mv [Link] [Link] Rename the file
6. mv [Link] my_directory/ Move file to a directory
7. rm my_directory/[Link] Remove the file
8. rmdir my_directory Remove the empty directory
9. rm -r my_directory/ Remove directory and its contents
10.Clear your screen
Review Questions:
1) What Linux command is used to know on which directory are you working
currently?
a) dir
b) prompt
c) who
d) pwd
e) cd
5) What Linux command(s) can be used to see the inside of a file (that is, to show
the contents of the file)? (select ALL that apply)
a) ls -l file
b) cat file
c) more file
d) less file
e) view file
10. The cat command in Linux is used to concatenate and display the content of files. It's one
of the most commonly used commands for viewing file contents in the terminal.
For very large files, consider using less or more instead of cat, as they allow you to scroll
through the file without loading the entire content into memory at once
11. The more command in Linux is used to view the content of a file one screen at a time. It’s
particularly useful for reading long files that don’t fit on a single screen, as it allows you to scroll
through the content interactively.
The tail command is a powerful tool for examining the end of files and monitoring real-time
changes, making it invaluable for system administration and debugging tasks.
[Link] (Vi IMproved) is a powerful and versatile text editor in Linux, an enhanced version of
the vi editor. It's widely used for editing configuration files, writing scripts, and programming.
vim provides a range of features including syntax highlighting, multiple modes, and extensive
customization.
1. Normal Mode (Default Mode) - Used for navigation and manipulating text. You start in this
mode when you open a file.
2. Insert Mode - Used for inserting text. Enter this mode by pressing i from Normal mode.
3. Visual Mode - Used for selecting text. Enter this mode by pressing v from Normal mode.
4. Command-Line Mode - Used for executing commands (e.g., saving, quitting). Enter this
mode by pressing : from Normal mode.
● vim [Link] Open a File
16. The chmod command in Linux is used to change the permissions of files and directories.
Permissions control who can read, write, or execute a file. The command can modify
permissions using symbolic mode or numeric mode.
● chmod [options] mode file_name Basic Syntax
Numeric Mode
Permissions can be set using a three-digit octal number where each digit represents a
category (User, Group, Others). Each digit is a sum of permissions:
- 4: Read
- 2: Write
- 1: Execute
For example:
Symbolic Mode
- r: Read
- w: Write
- x: Execute
+: Add a permission
-: Remove a permission
=: Set exact permissions
For example:
- To set permissions to rwxr-xr-- (User: read, write, execute; Group: read, execute; Others:
read): chmod 754 [Link]
Examples
Practical Tips
- Check Current Permissions: Use ls -l [Link] to view the current permissions of a file.
- Permissions on Directories: For directories, execute permission allows entering the directory,
and write permission allows creating and deleting files within it.
- Symbolic vs. Numeric Mode:Symbolic mode is more descriptive and easier to understand for
specific changes, while numeric mode is more compact and useful for setting permissions
directly.
The chmod command is essential for managing file and directory permissions in Linux,
ensuring appropriate access control and security.
17. The chown command in Linux is used to change the ownership of files and directories. It
allows you to specify a new owner and/or group for a file or directory. This is useful for
managing permissions and access control.
Key Concepts
Common Commands
Options
Examples
1. Change the Owner of a File
- To change the owner to bob and the group to admins: chown bob:admins [Link]
Practical Tips
- Check Current Ownership: Use ls -l [Link] to view the current owner and group of a file.
- Ownership and Permissions:Changing ownership does not alter file permissions; use chmod
for permission changes.
- Permissions: You typically need superuser (root) privileges to change ownership of files that
you do not own. Use sudo if necessary:
The chown command is a crucial tool for managing file ownership and ensuring proper access
control in Linux systems.
System Information and Management
18. The ps command in Linux is used to display information about active processes. It
provides a snapshot of the currently running processes, including details such as process IDs
(PIDs), memory usage, CPU usage, and more. This is useful for monitoring system
performance and managing processes.
Common Options
● ps aux
- ps -ef: Another common format for displaying all processes. It provides similar information to
ps aux.
- e: Show all processes.
- f: Display a full-format listing.
● ps -ef
● ps -e
● ps -u username
● ps -p 1234
-ps -l: Display detailed information in long format.
● ps -l
-ps -o format: Customize the output format. Replace format with fields like pid, user, cmd, etc.
● ps -o pid,user,cmd
Common Fields
When using ps aux or ps -ef, you might see the following fields:
Examples
Practical Tips
- Combining with Other Commands: You can use ps in combination with other commands like
grep to filter results. For example, to find processes related to nginx:
- Monitoring Processes: For real-time monitoring of processes, you might use top or htop,
which provide a dynamic view of system processes.
- Understanding Process States Familiarize yourself with common process states in the STAT
field, such as R (running), S (sleeping), and Z (zombie).
The ps command is an essential tool for managing and monitoring processes on a Linux
system, providing valuable insights into process behavior and system performance.
[Link] top command in Linux provides a dynamic, real-time view of the system’s resource
usage, including CPU, memory, and processes. It is a powerful tool for monitoring system
performance and diagnosing issues.
Overview of top
When you run top, it displays a continuously updating list of processes, sorted by CPU or
memory usage by default. It provides various system metrics and process details.
top -o %MEM
top -p 1234,5678
top -b -n 1
Examples
Practical Tips
- Performance Analysis: Use the top command to identify processes consuming excessive
resources and troubleshoot performance issues.
- Alternatives: For a more advanced and user-friendly interface, consider using htop, which
offers a similar functionality with a more interactive and graphical interface.
The top command is an essential tool for Linux system administrators and users to monitor
system performance, manage processes, and troubleshoot issues effectively.
20. The df command in Linux is used to display information about disk space usage on the file
system. It provides a quick overview of how much disk space is available, used, and free
across different file systems or mounted partitions.
● df [options] [file] Basic Syntax
Practical Tips
- Monitoring Disk Usage: Use df -h regularly to monitor disk space and prevent running out of
space, especially on critical partitions like /, /home, and /var.
- Troubleshooting: If a system is running out of disk space, df can help identify which partitions
or file systems are full.
- Inode Exhaustion:Running out of inodes can also prevent file creation. Use df -i to check
inode usage, especially on systems with many small files.
- Automated Monitoring: Combine df with scripts to automate disk space monitoring and send
alerts when free space drops below a threshold.
The df command is an essential tool for managing disk space on Linux systems, providing
critical information to ensure that storage resources are used efficiently and that the system
remains operational.
21. The du command in Linux is used to estimate and display the disk space usage of files
and directories. It helps you understand how much space a directory or a file is consuming,
which is useful for managing disk space.
Practical Tips
- Identifying Large Directories: Use du -sh * within a directory to quickly identify which
subdirectories or files are using the most space.
- Monitoring Disk Usage: Combine d with sort to find the largest directories:
- Using du with Network File Systems: When working with network-mounted file systems, use
the -x option to avoid traversing mounted points.
- Automating Disk Space Checks: Create a script that uses du to monitor disk space usage
and send alerts if certain thresholds are exceeded.
The du command is an essential tool for managing disk space on Linux systems, helping
users and administrators pinpoint where storage is being used and identify potential areas for
cleanup.
22. The free command in Linux is used to display information about the system’s memory
usage. It provides a quick overview of how much physical memory (RAM) and swap space is
available, used, and free.
The output also distinguishes between Mem (physical RAM) and Swap (swap space on disk).
- Physical Memory (Mem): This includes the total physical memory, how much is used, how
much is free, and how much is used for buffers/cache.
- Swap Memory (Swap): This shows the total swap space, how much is used, and how much
is free. Swap is used when physical memory is full, and the system starts swapping data to
disk, which is slower.
- Available Memory: This is an estimate of how much memory is available for starting new
applications without swapping.
Practical Tips
-System Performance Monitoring: The free command is useful for monitoring system
performance, particularly to see if your system is running low on memory or using swap
excessively.
- Understanding Buffers/Cache: The memory reported as used includes buffers and cache,
which are used by the system to optimize performance. The available memory provides a
better estimate of how much memory can be used by new applications.
- Identifying Memory Issues: Regularly checking memory usage with free can help identify
memory leaks or applications consuming too much memory, allowing for timely intervention
before the system starts swapping heavily.
The free command is a straightforward and powerful tool for understanding and monitoring
memory usage on a Linux system, helping to ensure that your system remains responsive and
efficient.
23. The uname command in Linux is used to display system information, including the kernel
name, version, and other details about the system. It’s a simple yet powerful command for
quickly identifying the operating system and kernel version of a system.
Practical Tips
- Checking Kernel Version: The uname -r command is particularly useful when you need to
know the exact version of the Linux kernel running on your system, such as when installing
kernel modules or troubleshooting compatibility issues.
- Verifying System Architecture:The uname -m option can help verify whether you are running
a 32-bit or 64-bit system, which is important when installing software or operating system
updates.
- System Information in Scripts: The uname command is commonly used in shell scripts to
make decisions based on the system type or kernel version, ensuring that the script behaves
appropriately on different systems.
- Understanding uname -a: The output of uname -a typically includes the kernel name,
hostname, kernel version, date of kernel compilation, architecture, and operating system,
providing a quick summary of key system information.
The uname command is a quick and useful tool for gathering essential system information,
particularly for system administrators and users who need to identify the kernel version,
system architecture, or other key details about their Linux environment.
24. The whoami command in Linux is used to display the username of the current user. It's a
simple and straightforward command that tells you which user account you are currently
operating under.
- When you type whoami and press Enter, the command outputs the username of the user
who is currently logged in and running the terminal session.
- The whoami command is essentially equivalent to running id -un, which also returns the
username of the current user.
Practical Uses
- Checking User Identity: The whoami command is useful when you need to confirm which
user account is being used, especially when working in a multi-user environment or when
using su or sudo to switch users.
- Scripting: In scripts, whoami can be used to conditionally execute commands based on the
current user. For example, certain commands might only be run if the script is executed by a
specific user.
- Debugging: If you're unsure which user context you're operating in, particularly after switching
users or running commands with elevated privileges, whoami provides a quick way to verify
your current user.
The whoami command is a quick and simple way to verify the user identity in a Linux session,
helping to avoid mistakes related to user permissions and context.
[Link] hostname command in Linux is used to display or set the system's hostname. The
hostname is the name assigned to a computer (or host) on a network and is used to identify
the machine in the network.
● hostname [options] [new_hostname] Basic Syntax
● hostname Display the Current Hostname of your machine
● sudo hostname mynewhost Change the Hostname change the hostname to
mynewhost
- Note:This change will only persist until the system reboots. To make it permanent, you'll
need to edit /etc/hostname and /etc/hosts (in most distributions).
Practical Tips
- Script Usage: In scripts, hostname can be used to make decisions based on the machine's
identity, such as setting specific configurations or logging information.
The hostname command is a versatile tool for managing and querying the system's
hostname, making it essential for network administration and system configuration.
26. The uptime command in Linux is used to display how long the system has been running,
along with the current time, the number of users currently logged in, and the system load
averages for the past 1, 5, and 15 minutes.
Output Overview
When you run the uptime command, the output typically includes:
Practical Tips
- System Health Check: The uptime command is useful for quickly checking how long a
system has been running, which can indicate stability or potential issues after a reboot.
- Monitoring System Load: The load averages give you an idea of how busy your system is. A
load average of 1.0 means the system is fully loaded (i.e., one process is using or waiting for
CPU resources per CPU core). Higher values indicate more load. If the load average is
consistently high, it might indicate that the system is under heavy usage or strain.
- Detecting Reboots: By looking at the uptime, you can determine when the system was last
rebooted, which can be useful for troubleshooting or verifying system stability.
Using uptime with Other Commands
- With watch: You can use watch with uptime to monitor the system's uptime and load
average in real time:
watch uptime
- In Scripts: The uptime command can be used in scripts to log or alert based on system
uptime or load averages, helping automate system monitoring.
The uptime command is a quick and effective tool for getting an overview of system
performance, making it a staple in both casual monitoring and serious system administration
tasks.
Networking
[Link] ping command in Linux is used to test the network connectivity between your system
and another system or device. It sends ICMP (Internet Control Message Protocol) echo
request packets to the target host and listens for echo reply packets to determine if the host is
reachable and how long it takes to respond.
This command will send ICMP packets to [Link] and display the results until you
stop it with Ctrl+C.
The -w option allows you to set a timeout, after which the ping command will stop, pinging
after 10 seconds.
You can specify the size of the packets sent using the -s option.
This command sends packets of 64 bytes in size.
The -f option sends packets as quickly as possible and requires root privileges. This is often
used for stress testing and network diagnostics.
Note that many networks are configured to block broadcast pings for security reasons.
Use the -i option to set the interval between sending packets (in seconds).
Practical Tips
- Network Troubleshooting: ping is a fundamental tool for diagnosing network issues. If you
can't reach a website, you can use ping to see if the problem is with network connectivity.
- Measuring Latency: The time value in the ping output gives you an idea of the latency (delay)
between your machine and the target. Higher times can indicate network congestion or other
issues.
- Checking Host Availability: You can use ping to see if a particular host (such as a server or
another computer) is up and running.
- Testing Network Configuration: After configuring network settings, ping can be used to verify
that your machine can communicate with other machines on the network.
- Script Usage: ping can be integrated into scripts for automated network monitoring, alerting
you when a host becomes unreachable.
The ping command is a versatile and essential tool for network administrators and users alike,
offering a simple way to check connectivity, diagnose issues, and measure network
performance.
[Link] Linux, both ifconfig and ip commands are used to manage network interfaces, but ip is
the more modern and powerful tool, and it’s recommended over ifconfig in most cases. Here’s
a comparison and explanation of each
1. Modern and Actively Maintained: ip is part of the iproute2 package, which is actively
maintained and includes more features for modern networking requirements.
2. More Comprehensive: The ip command covers a broader range of network configuration
tasks, including advanced routing, tunneling, and more.
3. Standardization: Many modern Linux distributions have moved away from ifconfig to ip,
making it the standard tool for network management.
Summary
- Use ifconfig if you are working on older systems where ip might not be available, or if you
are dealing with legacy scripts and tools that still rely on ifconfig.
- Use ip if you are on a modern Linux system and need a more powerful, flexible, and actively
supported tool for managing network interfaces.
For new scripts and tasks, it's generally recommended to use the ip command.
29. The netstat command in Linux is a powerful tool used for network troubleshooting and
monitoring. It provides detailed information about network connections, routing tables, interface
statistics, masquerade connections, and multicast memberships. However, it's worth noting
that netstat is now largely considered deprecated in favor of more modern tools like ss and ip
from the iproute2 package.
The watch command can be used to monitor the output of netstat in real-time.
Summary
- The netstat command is still useful, especially in legacy systems, but for modern systems,
you might want to familiarize yourself with ss and ip commands.
- netstat provides a wide range of options to troubleshoot and monitor network activities, but
it's recommended to transition to ss for better performance and additional features.
30. The scp (Secure Copy Protocol) command in Linux is used to securely transfer files and
directories between two systems over a network. It leverages SSH (Secure Shell) to provide
encrypted file transfers, making it a safer alternative to traditional file transfer methods like cp
(which only works locally) or ftp.
● scp username1@remote_host1:/path/to/file
username2@remote_host2:/path/to/destination
This command copy a File Between Two Remote Systems
The scp command is a simple yet powerful tool for secure file transfers between local and
remote systems. It’s a common utility for system administrators and anyone needing to move
files securely across networks.
31. The ssh (Secure Shell) command in Linux is used to securely connect to a remote
machine over a network. It allows users to execute commands, transfer files, and manage
systems remotely with encrypted communication, ensuring privacy and data integrity.
This command connects to the remote machine with IP address [Link] using the
specified user account.
This command connects to the remote machine using port 2222 instead of the default SSH
port 22
This command connects to the remote machine using the specified private key (id_rsa) for
authentication.
This command forwards connections on port 8080 on the local machine to port 80 on the
remote machine (through the SSH server).
This command forwards connections on port 8080 on the remote machine to port 3000 on the
local machine.
ssh myserver
Host myserver
HostName [Link]
User user
Port 2222
IdentityFile ~/.ssh/id_rsa
Summary
The ssh command is a versatile and essential tool for securely managing remote systems. It
offers a wide range of functionalities, from simple remote login to complex tunneling, file
transfer, and secure communication.
1. Repository Lists are Refreshed: The command downloads the latest package lists from the
repositories specified in your /etc/apt/[Link] file and any files in the
/etc/apt/[Link].d/ directory.
2. No Actual Packages are Installed or Upgraded: It doesn’t install or upgrade any packages;
it merely updates the local list of available packages and their versions.
3. Prepares the System for Package Management Operations: After running apt-get update,
you can then proceed with commands like apt-get upgrade or apt-get install to actually
upgrade packages or install new ones.
Summary
The apt-get update command is essential for keeping your system's package database up to
date. It's a necessary step before installing new software or performing system upgrades to
ensure that you have access to the latest versions of packages available in your configured
repositories.
[Link] apt-get upgrade command in Linux is used to upgrade all the installed packages on
your system to their latest available versions, as indicated by the package lists retrieved by
apt-get update.
1. Compares Installed Packages with Available Updates: The command checks the versions of
installed packages against the versions available in the repositories that were updated using
apt-get update.
2. Upgrades Packages: It upgrades all installed packages to the latest versions available, as
long as no packages need to be removed or new dependencies need to be installed.
3. Prompts for Confirmation:Before proceeding, it will typically display the list of packages that
will be upgraded and ask for your confirmation.
Upgrading the Kernel: apt-get upgrade typically upgrades the Linux kernel if a new version is
available. However, the older kernels are usually not removed automatically, which can lead to
the accumulation of old kernels on your system. You may need to manually remove old kernels
if disk space becomes an issue.
Reboot After Upgrading: After running apt-get upgrade, especially if the kernel or core
system libraries have been upgraded, it's recommended to reboot the system to ensure that all
changes take effect properly.
Summary
The apt-get upgrade command is a straightforward way to keep your installed packages up to
date with the latest versions available in your system's repositories. It's a key part of regular
system maintenance to ensure security and stability. For more complex upgrades that involve
changing dependencies, consider using apt-get dist-upgrade.
34. The apt-get remove command in Linux is used to uninstall or remove installed packages
from your system. Unlike apt-get purge, which also removes configuration files, apt-get
remove only removes the package binaries and leaves the configuration files intact.
1. Uninstallation of Specified Packages: The command removes the specified package(s) from
the system, but it leaves behind the configuration files in case you want to reinstall the
package later and retain your previous settings.
2. Dependency Handling: If the package being removed is a dependency for another installed
package, the system will alert you, but it won't automatically remove the dependent packages
unless you use the --auto-remove option.
3. Leaves Configuration Files: Configuration files, such as those located in /etc, are not
removed. This allows you to keep your custom settings if you reinstall the package later.
Important Considerations
- Use apt-get purge for Complete Removal:If you want to remove a package along with its
configuration files, use `sudo apt-get purge package-name` instead of sudo apt-get remove
package-name.
- Reclaiming Disk Space: After removing packages, you might want to run sudo apt-get
autoremove to clean up any orphaned dependencies that are no longer needed. Additionally,
sudo apt-get clean can be used to remove cached package files to free up disk space.
Summary
The apt-get remove command is a useful tool for uninstalling packages from your
Debian-based Linux system while keeping their configuration files intact. This command is
handy if you want to free up space or remove unnecessary software without losing your
custom settings. To fully remove a package, including its configuration files, consider using
apt-get purge.
Miscellaneous
35. The echo command in Linux is used to display a line of text or string on the terminal. It's a
simple yet powerful command that's commonly used in shell scripting and command-line
operations to output text or the results of commands.
Summary
The echo command is a versatile tool in Linux, useful for displaying messages, variable
values, command outputs, and more. It's an essential part of shell scripting and a fundamental
command for everyday use in the terminal.
[Link] history command in Linux displays the command history for the current user session.
It shows a list of commands that have been entered in the terminal, along with their
corresponding line numbers, allowing you to review or re-execute past commands.
Important Notes
- Persistent History: The history is typically stored in a file like ~/.bash_history, which is
updated when you log out. Commands from previous sessions are loaded into memory when
you start a new terminal session.
-Customizing History: You can customize how history behaves using environment variables
such as HISTFILE (to set the history file location), HISTSIZE (to set the number of commands
stored), and HISTCONTROL (to control which commands are saved).
- Avoid Logging Certain Commands: You can prevent certain commands from being saved in
history by starting the command with a space if HISTCONTROL is set to ignorespace.
Summary
The history command is an essential tool for tracking and managing your command-line
activities. It helps you efficiently recall and re-execute previous commands, search through
your history, and manage your command history for better productivity in the terminal.
[Link] clear the command history in Linux, you can use several methods depending on how
thoroughly you want to clear the history. Here are the steps to clear the command history from
both the current session and the persistent history file.
● history -c Clear the Current Session's History to clear the history for the current
session (but not the saved history in the .bash_history file)
● cat /dev/null > ~/.bash_history Clear the History File (`.bash_history`) To clear the
history file that stores the command history between sessions
● history -c && > ~/.bash_history && history -w To ensure that both the session
history and history file are cleared, you can combine the commands like this:
Important Notes
- Immediate Clearing: After running these commands, the cleared history will no longer be
available in the current session or when you start a new session.
- Shell Differences:The above commands are for bash shell. If you're using another shell (like
zsh or fish), the history commands and files might differ.
- Security: If you're clearing history for privacy reasons, make sure to clear both the session
and the history file.
Summary
- top: Displays real-time system resource usage, including CPU, memory, and processes.
- htop: An enhanced version of top with a more user-friendly interface (requires installation).
- vmstat: Provides detailed information about system processes, memory, paging, block IO,
and CPU activity.
- iostat: Reports CPU statistics and input/output statistics for devices and partitions.
- free: Displays the amount of free and used memory in the system.
- uptime: Shows how long the system has been running, along with the system load averages.
2. Process Management
4. Network Troubleshooting
- tail: Displays the last few lines of a file (commonly used with log files).
- grep: Searches for patterns in files (useful for log analysis)
- journalctl: Views logs managed by `systemd`.
- dmesg: Prints kernel ring buffer messages, useful for diagnosing hardware issues.
- strace: Traces system calls and signals, useful for debugging programs.
- lsof: Lists open files by processes, useful for finding which process is using a file or socket.
- tcpdump: Captures and analyzes network packets.
Summary
These commands form the core toolkit for troubleshooting a wide range of issues on Linux
systems. Familiarity with these tools allows you to diagnose and resolve problems efficiently,
ensuring the stability and performance of your system.
Referencies: [Link]