Familiarization of basic Linux Commands- cpuinfo , meminfo, du and fdisk
cpuinfo
cpuinfo
command in Linux is not a standalone command but refers to a way of accessing detailed information about your system's CPU (Central Processing Unit). This information is crucial for understanding your processor's capabilities, such as its make, model, speed, and features.How to Access CPU Information?
To view detailed information about the CPU, you typically read the contents of a special file called /proc/cpuinfo
. The /proc
directory is a virtual filesystem in Linux that provides system and process information.
You can access this file using commands like cat
, less
, or grep
.
Basic Command to Display CPU Info
What Does /proc/cpuinfo
Contain?
When you run the above command, it displays detailed information about each processor core on your system. Let’s break down the key sections of the output.
Example Output
Here’s an example of what you might see:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xca
cpu MHz : 2600.000
cache size : 12288 KB
physical id : 0
siblings : 12
core id : 0
cpu cores : 6
apicid : 0
initial apicid : 0
fpu : yes
flags : fpu vme de pse tsc msr pae mce cx8 sep pge ...
Understanding the Key Fields
Here’s a breakdown of the key fields in the output:
processor
:- This is the ID of the processor or core.
- For example, if you have a quad-core CPU, you’ll see
processor: 0
,processor: 1
, etc.
vendor_id
:- The manufacturer of the CPU.
- Common values:
GenuineIntel
(Intel) orAuthenticAMD
(AMD).
cpu family
:- A number representing the generation of the CPU.
model
:- The specific model number of the CPU within the family.
model name
:- The full name of the CPU, including its brand and speed.
- Example:
Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
.
cpu MHz
:- The speed of the CPU in MHz (megahertz).
- This can vary based on power-saving modes or load.
cache size
:- The size of the L2 or L3 cache, measured in KB.
cpu cores
:- The total number of physical cores in the CPU.
siblings
:- The total number of logical processors, including hyper-threading.
flags
:- A list of features or instructions the CPU supports.
- Examples:
sse
,avx
,vmx
(virtualization), etc.
How to Filter Information?
If the output is too long, you can filter it to see specific details.
1. Find the CPU Model Name
Practical Uses of /proc/cpuinfo
1.Check CPU Compatibility:
- Identify whether your CPU supports specific features (e.g., virtualization, AVX, or SSE).
- Example: Look for
vmx
in theflags
section.
2.Monitor Performance:
- Ensure the CPU is running at the expected speed.
3.Diagnose Hardware Issues:
- Compare the CPU model and cache size to specifications to check for hardware mismatches.
4.System Optimization:
- Determine the number of cores to configure multi-threaded applications.
Alternative Tools to View CPU Info
For beginners, using /proc/cpuinfo
can be a bit overwhelming. Here are simpler commands/tools:
lscpu
Command:- Provides a concise summary of CPU details.
Graphical Tools:
- If you prefer a GUI, tools like
htop
orsysinfo
also display CPU details.
Summary
The /proc/cpuinfo
file is a goldmine of information about your CPU. Using commands like cat
, grep
, and lscpu
, you can easily check the number of cores, speed, and features your CPU supports. It's especially useful for configuring systems, diagnosing issues, and optimizing performance.
meminfo
This is an important file that provides detailed information about your computer's memory usage, including how much memory is installed, used, available, and much more.
What is /proc/meminfo
?
/proc/meminfo
is a virtual file in Linux that contains real-time memory statistics.- It is located in the
/proc
directory, which is a special directory containing system and process information. - The file is automatically updated by the Linux kernel and reflects the current state of your system's memory.
How to View /proc/meminfo
?
You can use the cat
command to display the content of this file in your terminal. Here’s how:
Command:
Breaking Down the Output
Let’s take it line by line and understand what each term means.
1. MemTotal
- What it means: Total amount of physical memory (RAM) installed on your computer.
- Why it matters: This is the maximum memory your system can use.
- Example:
MemTotal: 16392696 kB
(This shows you have about 16GB of RAM).
2. MemFree
- What it means: The amount of memory that is completely free and not being used by the system.
- Why it matters: Indicates how much unused memory is available right now.
- Example:
MemFree: 12345678 kB
(~12GB of RAM is unused).
3. MemAvailable
- What it means: The amount of memory available for applications, considering buffers and cache can be reused.
- Why it matters: This value is a better indicator of how much memory is truly available for new processes.
- Example:
MemAvailable: 14000000 kB
(~14GB of memory is ready to use).
4. Buffers
- What it means: Memory used for temporary storage of data being written to or read from disk.
- Why it matters: Buffers speed up disk operations by storing intermediate data.
- Example:
Buffers: 987654 kB
(~987MB used for buffering).
5. Cached
- What it means: Memory used to cache files for faster access.
- Why it matters: Cached memory is used to speed up access to frequently used files. This memory can be freed if needed.
- Example:
Cached: 7654321 kB
(~7.6GB of files are cached).
6. SwapTotal
- What it means: Total amount of swap space available.
- Why it matters: Swap is virtual memory stored on disk that acts as an overflow when RAM is full. However, it's slower than RAM.
- Example:
SwapTotal: 2097152 kB
(~2GB of swap space available).
7. SwapFree
- What it means: Amount of swap space that is currently unused.
- Why it matters: Indicates if your system is relying on swap due to insufficient RAM.
- Example:
SwapFree: 2097152 kB
(~2GB of swap is still free).
- What it means: Memory pages that have been modified but not yet written to disk.
- Why it matters: Small values are normal; large values might indicate disk performance issues.
- Example:
Dirty: 102 kB
.
9. AnonPages
- What it means: Memory used by applications (anonymous pages not backed by files).
- Why it matters: Reflects how much memory your running programs are consuming.
- Example:
AnonPages: 1234567 kB
(~1.2GB of application memory usage).
10. Slab
- What it means: Memory used by the Linux kernel for managing internal data structures.
- Why it matters: Helps you understand kernel memory usage.
- Example:
Slab: 5432101 kB
(~5.4GB is used by the kernel).
Practical Uses of /proc/meminfo
- Monitor memory usage: Check how much memory is free, used, or available.
- Diagnose performance issues: Low
MemFree
and highSwapFree
values indicate your system is low on RAM. - Analyze cache and buffer usage: Cached and buffered memory are essential for speeding up processes.
- Troubleshoot swap: Identify if your system is relying heavily on swap space, which can slow it down.
Filtering Specific Information
If you want to see specific memory details, you can use the grep
command.
Example 1: Check Total, Free, and Available Memory
grep -E "MemTotal|MemFree|MemAvailable" /proc/meminfoSimpler Alternatives to /proc/meminfo
If /proc/meminfo
looks overwhelming, you can use these commands for a summary:
1. Free Command
2. Top or Htop
Use real-time monitoring tools like: top htop
Conclusion
The /proc/meminfo
file is a great tool for understanding how memory is being used on your Linux system. It provides detailed information about physical memory, swap, buffers, cache, and kernel usage. With this knowledge, you can monitor system performance, troubleshoot issues, and optimize applications.
du command- disk usage
du
command is one of the most useful tools in Linux for checking disk usage. This command is perfect for finding out how much space files and directories are taking up on your system.What is the du
Command?
du
stands for Disk Usage.- It shows the amount of disk space used by files and directories.
- By default, it provides the size of directories and their contents in kilobytes (KB).
du
checks the current directory.Basic Usage
1. View Disk Usage of the Current Directory
Common Options in du
Let’s make the command more user-friendly with some helpful options!
1. Show Human-Readable Sizes
To see sizes in KB, MB, or GB, use the -h
option:
du -h
2. Summarize Total Size
To get only the total size of a directory, use the -s
option:
du -sh
3. Display Individual Files
To see the size of all files and directories, use the -a
option:
du -ah
4. Exclude Specific Files or Directories
You can exclude certain items using the --exclude
option:
du -h --exclude="*.log"
Example Use Case:
- Exclude all log files while analyzing disk usage.
5. Limit Depth of Directory Display
Use the --max-depth
option to restrict how deeply du
analyzes subdirectories:
du -h --max-depth=1
6. Sort Results by Size
Combine du
with the sort
command to display results from smallest to largest:
du -h | sort -h
Conclusion
The du
command is a powerful tool for understanding how disk space is being used on your system. It’s simple to use, and with the right options, it can provide valuable insights into disk usage.
fdisk command - Fixed Disk
fdisk command is used to manage or partition your hard drives.What is the fdisk
Command?
fdisk
stands for Fixed Disk.- It is a text-based tool used to create, delete, and manage partitions on a storage device like a hard disk or SSD.
- It supports MBR (Master Boot Record) partitioning.
⚠️ Warning: Since fdisk
modifies disk partitions, always proceed with caution. Incorrect usage can lead to data loss!
When to Use fdisk
?
- Adding a new hard drive to your system.
- Creating or resizing partitions for installing multiple operating systems.
- Removing unused or corrupt partitions.
Syntax of fdisk
The general syntax is:
fdisk [options] [device]
/dev/sda
refers to the first hard disk on your system.Basic Workflow of fdisk
Let’s go through the typical steps to use fdisk
effectively.
1. List All Available Disks
Before working with partitions, identify the disks available on your system:
fdisk -l
/dev/sda
or /dev/sdb
.2. Open a Disk in fdisk
To manage a specific disk, specify its device name:
fdisk /dev/sda
3. Display Current Partition Table
In fdisk
interactive mode, type:
p
This shows the current partitions on the selected disk.
4. Create a New Partition
To create a new partition, follow these steps:
- Press
n
to create a new partition. - Choose the partition type:
p
for primary partition.e
for extended partition.
- Specify the partition number (e.g., 1, 2).
- Enter the starting and ending sectors or press Enter for defaults.
5. Delete a Partition
To delete a partition:
- Press
d
. - Enter the partition number to delete (e.g., 1, 2, etc.).
6. Write Changes to Disk
Once you’ve created, deleted, or modified partitions, save your changes by typing:
w
fdisk
.If you want to exit without making changes, type:
q
Real-Life Use Cases
Setting Up a New Disk
- You’ve installed a new SSD and need to partition it before use.
Repartitioning a Disk
- If your disk has unallocated space, you can create new partitions to utilize it.
Troubleshooting Boot Issues
- You might need to fix or modify a boot partition.
Conclusion
The fdisk
command is a powerful tool for disk partitioning. While it’s a bit advanced, practice will make it easier to use. Remember to always double-check your commands to avoid unintentional data loss.
Comments
Post a Comment