Linux is a powerful operating system widely used in servers, cloud environments, and development workflows. Understanding Linux commands is essential for DevOps professionals, system administrators, developers, and IT professionals. This is the first of our Linux command series; we'll discuss the fundamentals of system, hardware, and file commands.
Command | Description |
---|---|
uname | Show the name of the kernel. |
uname -r | Display the kernel version. |
uname -a | Show all system information. |
clear | Clear the terminal screen. |
Ctrl+L | Keyboard shortcut for clearing the screen. |
uptime | Display the duration for which the system has been running. |
uptime -p | Display uptime in an attractive format. |
hostname | Show the hostname of the system. |
hostname -i | Show the IP address of the system. |
hostnamectl set-hostname <name> | Change the system's hostname. |
date | Show the current date and time. |
timedatectl | Show or modify system time settings. |
timedatectl set-timezone <zone> | Set system timezone. |
lscpu | Show information about the CPU architecture. |
free -h | Show memory usage in a format that is easy to understand (human-readable format). |
df -h | Show the usage of disk space. |
touch <file> | Create empty file. |
rm <file> | Delete the file (ask for confirmation). |
rm -f <file> | Permanently delete a file without any confirmation prompts. |
rm -f * | Delete all files in the current directory. (This action is potentially dangerous.) |
mkdir <dir> | Create directory. |
mkdir -p <path> | Create nested directories. |
ls | Display files and directories. |
ls -l | Detailed listing. |
ls -a | List all files, including hidden. |
cd <dir> | Change directory. |
cd .. | Navigate to the parent directory. |
cd ~ | Navigate to the home directory. |
cd - | Navigate to the previous directory. |
cp <src> <dst> | Copy file(s). |
cp -r <src> <dst> | Copy directory recursively. |
mv <src> <dst> | Move or rename file/directory. |
System Commands
1. uname - Display System Information
uname ------------------ Linux
uname -r ------------------ 5.4.0-42-generic
uname -a ------------------ Linux ubuntu 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
The uname
command displays system information. The -a
flag shows all available details including kernel name, hostname, kernel release, kernel version, architecture, processor type, and operating system.
2. clear - Clear Terminal Screen
clear
Clears the terminal screen. You can also use the keyboard shortcut Ctrl+L
.
3. uptime - Show System Uptime
uptime ------------------ 14:30:45 up 3 days, 5:23, 2 users, load average: 0.15, 0.21, 0.18
uptime -p ------------------ up 3 days, 5 hours, 23 minutes
Shows how long the system has been running. The -p
option displays the result in a human-readable format.
4. hostname - Display or Set Hostname
hostname ------------------ ubuntu-server
hostname -i ------------------ 192.168.1.100
sudo hostnamectl set-hostname "new-server"
Displays the system's hostname. The -i
option shows the IP address. You can set a new hostname using hostnamectl set-hostname
.
5. date and timedatectl - Display or Set Date and Time
date ------------------ Mon Aug 9 14:35:22 UTC 2021
timedatectl ------------------ Local time: Mon 2021-08-09 14:35:25 UTC Universal time: Mon 2021-08-09 14:35:25 UTC RTC time: Mon 2021-08-09 14:35:25 Time zone: UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no
sudo timedatectl set-timezone Asia/Kolkata
The date
command shows the current date and time. The timedatectl
command provides detailed time settings and allows you to change the timezone.
Hardware Commands
1. lscpu - CPU Information
lscpu ------------------ Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 142 Model name: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz Stepping: 10 CPU MHz: 1800.000 CPU max MHz: 3400.0000 CPU min MHz: 400.0000
Displays detailed CPU architecture information.
2. free - Memory Usage
free -h ------------------ total used free shared buff/cache available Mem: 7.7Gi 1.2Gi 4.9Gi 123Mi 1.6Gi 6.1Gi Swap: 2.0Gi 0B 2.0Gi
Shows memory usage statistics. The -h
option makes the output human-readable.
3. df - Disk Space Usage
df -h ------------------ Filesystem Size Used Avail Use% Mounted on udev 3.9G 0 3.9G 0% /dev tmpfs 787M 1.2M 786M 1% /run /dev/sda1 50G 15G 33G 31% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda2 487M 107M 355M 24% /boot tmpfs 787M 0 787M 0% /run/user/1000
Displays disk space usage for all mounted filesystems. The -h
option shows sizes in a human-readable format.
File Commands
1. touch - Create Files
# Create a single file touch file1.txt # Create multiple files touch file1.txt file2.txt file3.txt # Create a sequence of files touch file{1..5}.txt
Creates empty files. You can create single or multiple files at once.
2. rm - Remove Files
# Remove a single file rm file1.txt # Force remove without confirmation rm -f file1.txt # Remove all .txt files rm -f *.txt # Remove a sequence of files rm -f file{1..5}.txt # Remove all files in the directory (DANGEROUS) rm -f *
Deletes files. Use with caution as deleted files cannot be easily recovered.
3. mkdir - Create Directories
# Create a single directory mkdir folder1 # Create multiple directories mkdir folder1 folder2 folder3 # Create nested directories mkdir -p parent/child/grandchild # Create a sequence of directories mkdir folder{1..5}
Creates directories. The -p
option creates parent directories as needed.
4. ls - List Files
ls ------------------ file1.txt file2.txt folder1
ls -l ------------------ total 8 -rw-r--r-- 1 user user 0 Aug 9 15:00 file1.txt -rw-r--r-- 1 user user 0 Aug 9 15:00 file2.txt drwxr-xr-x 2 user user 4096 Aug 9 15:00 folder1
ls -a ------------------ . .. .hidden file1.txt file2.txt folder1
Lists directory contents. -l
shows detailed listing, and -a
includes hidden files.
5. cd - Change Directory
cd folder1 # Enter folder1 cd .. # Move up one level cd ../.. # Move up two levels cd ~ # Go to home directory cd / # Go to root directory cd - # Go to previous directory
Changes the current working directory.
6. cp - Copy Files and Directories
# Copy a single file cp source.txt destination.txt # Copy multiple files cp file1.txt file2.txt /backup/ # Copy directory recursively cp -r folder1 folder2
Copies files and directories. Use the -r
option when copying directories.
7. mv - Move or Rename Files
# Rename a file mv oldname.txt newname.txt # Move a file mv file1.txt /backup/ # Move multiple files mv *.txt /backup/
Moves or renames files and directories.