Linux class note
lsusb
The lsusb command in Linux stands for "list USB" and is used to display information about the USB
buses and the devices connected to them.
🔧 Syntax:
lsusb
📋 Example Output:
Bus 002 Device 003: ID 046d:c534 Logitech, Inc. Unifying Receiver
Bus 001 Device 005: ID 0781:5567 SanDisk Corp. Cruzer Blade
🔍 Breakdown:
Bus 002 / Device 003: Physical location of the USB device.
ID 046d:c534: Vendor ID and Product ID.
Logitech, Inc. Unifying Receiver: Manufacturer and product name.
✅ Common Uses:
Check if USB devices (like pen drives, mice, keyboards) are detected.
Debug USB connection issues.
Get vendor and product IDs for driver installation or udev rules.
📌 Additional Options:
lsusb -v : Verbose output with detailed information (only accessible with sudo ).
lsusb -t : Show USB device hierarchy as a tree.
lsusb -D /dev/bus/usb/001/005 : Show details about a specific device.
lscpu
lscpu is a Linux command-line utility that displays CPU architecture information of your system.
🔹 What it does:
Provides detailed info about the processor(s) including:
Number of CPUs, cores, threads
Architecture type (e.g., x86_64)
CPU model, vendor
Cache sizes
CPU flags (capabilities)
🔹 Basic Usage:
lscpu
🔹 Example Output:
Architecture: x86_64
CPU(s): 8
Thread(s) per core: 2
Core(s) per socket: 4
Model name: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
CPU MHz: 1800.000
L1d cache: 32K
L2 cache: 256K
L3 cache: 6M
🔹 Why use it?
To understand CPU capabilities
Helpful for performance tuning, virtualization, and resource allocation
Useful for hardware inventory and debugging
lspci
lspci is a Linux command-line utility used to list all PCI (Peripheral Component Interconnect)
devices on your system.
🔹 What it does:
Displays information about hardware components connected via the PCI bus, like:
Network cards
Graphics cards
USB controllers
Audio devices
🔹 Basic Usage:
lspci
This gives a list of PCI devices with their bus ID, vendor, and device name.
🔹 Example Output:
00:1f.3 Audio device: Intel Corporation Cannon Lake PCH cAVS
01:00.0 VGA compatible controller: NVIDIA Corporation TU117M [GeForce GTX 1650
Mobile]
🔹 Common Options:
lspci -v → verbose output
lspci -vv → very verbose
lspci -nn → show numeric device/vendor IDs
lspci -k → show driver in use
✅ Use Case:
Useful for hardware troubleshooting, driver identification, and system auditing.
🔹 What is sda1 in Linux?
In Linux, sda1 refers to the first partition on the first detected SATA (or SCSI) hard disk.
🔸 Breaking it Down:
Let’s decode the name sda1 :
Part Meaning
sd Refers to a SCSI/SATA storage device
a The first disk detected (e.g., a = 1st disk, b = 2nd, etc.)
1 The first partition on that disk
So:
sda = the whole first hard drive
sda1 = the first partition on that drive
sda2 = the second partition on the same drive
and so on...
🔸 Example:
If your system has one hard disk with 3 partitions:
/dev/sda → the entire disk
/dev/sda1 → partition 1 (maybe /boot)
/dev/sda2 → partition 2 (maybe root /)
/dev/sda3 → partition 3 (maybe swap)
🔸 Related Devices:
Device Description
/dev/sda Entire first disk
/dev/sdb Second disk
/dev/sdc Third disk
/dev/sda1 1st partition on disk sda
/dev/sdb2 2nd partition on disk sdb
🔸 View Disk Partitions:
You can list and inspect disks and partitions using:
lsblk
or
sudo fdisk -l
🔹 ls Command in Linux
The ls command is used to list files and directories in the current working directory or a specified
path.
🔸 Basic Syntax:
ls [options] [directory]
🔸 Common Examples:
Command Description
ls List files and folders in current directory
ls /home/user List contents of a specific path
ls -l Long listing format (details like size, permissions)
ls -a Show all files including hidden (starting with . )
ls -la or ls -al Long listing with hidden files
ls -lh Human-readable sizes (e.g., KB, MB)
ls -lt Sort by modification time (newest first)
ls -R List directories recursively
ls -d */ Show only directories in current folder
🔸 Example Output of ls -l :
-rw-r--r-- 1 user user 1234 Jun 25 13:00 file.txt
drwxr-xr-x 2 user user 4096 Jun 24 09:20 myfolder
Field Meaning
-rw-r--r-- File permissions
1 Number of links
user user Owner and group
1234 File size in bytes
Jun 25 13:00 Last modified date/time
file.txt File name
🔸 Bonus Tips:
Color-coded output is often available to distinguish file types (directories, executables, etc.).
Combine with grep to filter:
ls | grep ".txt"
🔹 id Command in Linux
The id command is used to display the UID (User ID), GID (Group ID), and the groups that the current
or specified user belongs to.
🔸 Syntax:
id [username]
If no username is provided, it shows info for the current user.
🔸 Example:
id
Output:
uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo),1001(developers)
🔸 Meaning of the Output:
Field Description
uid=1000 User ID of the user
gid=1000 Primary group ID
groups=... List of groups the user is part of
🔸 Check ID for a Specific User:
id root
Shows UID, GID, and groups for the root user.
🔸 Related Commands:
Command Description
whoami Shows the current logged-in user
groups Lists group memberships
🔹 df Command in Linux
The df command stands for “disk free” — it shows the amount of disk space used and available
on mounted filesystems.
🔸 Basic Syntax:
df [options] [directory or device]
🔸 Most Common Usage:
df -h
✅ Shows disk usage in human-readable format (MB, GB, etc.)
🔸 Example Output of df -h :
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/sdb1 100G 60G 35G 64% /mnt/data
🔸 Column Breakdown:
Column Meaning
Filesystem Name of disk or partition
Size Total size of the filesystem
Used Space used
Avail Space available
Use% Percentage used
Mounted on Where it is mounted in the directory tree
🔸 Useful Options:
Option Description
-h Human-readable format (KB, MB, GB)
-T Show filesystem type
-a Include dummy and special filesystems
-i Show inode usage instead of disk space
🔸 Example:
df -Th
✅ Shows filesystem types (like ext4, xfs, etc.) in human-readable format.
#🔹 User Management Commands in Linux
User management in Linux includes creating, modifying, and deleting users and their permissions.
Here’s a full list of essential commands for managing users:
🧑💻 1. Add a New User
sudo adduser username
Creates a new user with a home directory and prompts for a password.
✅ Example:
sudo adduser alice
🗑️ 2. Delete a User
sudo deluser username
To delete user's home directory as well:
sudo deluser --remove-home username
📝 3. Modify a User
sudo usermod [options] username
Option Description
-l newname Change username
-d /new/home Change home directory
-g group Change primary group
-aG group Add to additional group
-s /bin/bash Change shell
✅ Example:
sudo usermod -aG sudo alice
🔑 4. Set or Change a User's Password
sudo passwd username
✅ Example:
sudo passwd bob
🔐 5. Lock/Unlock a User Account
Lock:
sudo usermod -L username
Unlock:
sudo usermod -U username
👥 6. Add/Remove User from a Group
Add:
sudo usermod -aG groupname username
Remove:
sudo gpasswd -d username groupname
👁️ 7. Show User Info
Current user:
whoami
UID, GID, groups:
id username
📂 8. View All Users
cut -d: -f1 /etc/passwd
📜 9. List All Groups
cut -d: -f1 /etc/group
🧑🏫 BONUS: Switch to Another User
su - username
🔹 Group Management in Linux
Groups in Linux help organize users and manage permissions efficiently by allowing access control to
files, directories, and system resources based on group membership.
🔸 Types of Groups
Group Type Description
Primary Group Default group assigned to a user. Typically has the same name as the user.
Secondary Group Additional groups the user belongs to for shared access and collaboration.
🧠 Note: A user can have only one primary group but multiple secondary groups.
🔹 View Group Information
Command Description
groups Show groups for current user
groups username Show groups for another user
id Display UID, GID, and groups
cat /etc/group Show all groups on the system
🔹 Group Management Commands
Task Command Example
✅ Create a group sudo addgroup developers
🗑️ Delete a group sudo delgroup developers
➕ Add user to a group sudo usermod -aG developers alice
➖ Remove user from a group sudo gpasswd -d alice developers
🔁 Change primary group sudo usermod -g developers alice
👀 List all groups cut -d: -f1 /etc/group
🔸 Example Use Case:
Imagine you're managing a software team:
1. Create a group:
sudo addgroup devteam
2. Add users to the group:
sudo usermod -aG devteam alice
sudo usermod -aG devteam bob
3. Set permissions for the group on a project folder:
sudo chown :devteam /home/projects/myapp
sudo chmod 770 /home/projects/myapp
Now, only members of the devteam group can access and modify the project.
🔹 Bonus: Group File Format
Groups are stored in the file:
/etc/group
Each line looks like:
groupname:x:GID:user1,user2,...