Linux commands are the backbone of any Linux user’s toolkit. It offers a gateway to efficient file management and system administration.
My journey with Linux began with a curiosity to explore its powerful command-line interface, but as I delved deeper, I understood that mastering these commands not only unlocked the full potential of Linux but also changed the way I use my machine.
In my opinion, proficiency in Linux commands is not just a skill but a necessity, as mastering these commands opens doors to endless possibilities.

With that being said, here I have prepared a list of the most useful and most frequently used Linux commands.
So, without any further ado, let’s get started –
Linux Commands for File Management
File management is a fundamental aspect of working with any operating system, and Linux offers a robust set of commands to handle files and directories efficiently.
cd command
The cd
command, short for “change directory,” is crucial for navigating your Linux file system. It allows you to switch between different directories to access files and perform operations.
Syntax
cd [options] [directory_name]
Here,
options
are optional flags used to modify the behavior of the command. Some common options include:
– | Go to the previous directory you were in. |
.. | Go up one directory level. |
~ | Go to your home directory. |
directory_name
: It is the name of the directory you want to switch to. You can specify full paths (e.g., /home/user/Documents
) or relative paths (e.g., ../data
).
pwd command
The pwd
command in Linux is used to print the full path of the current working directory. It helps users to know their current location in the filesystem.
Syntax
pwd [options]
Here,
options
are optional flags to modify the command’s behavior.-L
: Displays the logical path, including symbolic links.-P
: Displays the physical path, resolving symbolic links to their directory paths.
ls command
ls
is a ubiquitous command that allows you to list the contents of a directory.
Syntax
ls [options] [directory_name]
Here,
[options]
are flags to modify the output (e.g.,-l
for detailed information,-a
for hidden files)[directory_name]
specifies the directory to list (optional)
mkdir command
In Linux and Unix-like operating systems, the mkdir
command is used to create new directories (folders) within your file system. This is essential for organizing your files and keeping them structured.
Syntax
mkdir [options] [directory_name]
Here:
[options]
: Optional flags to modify the behavior of the command.[directory_name]
: The name or path of the directory you want to create. It can be a relative path (new_folder
) or an absolute path (/home/user/new_folder
).
rmdir command
The rmdir
command is used to remove empty directories from the Linux file system. If the directory contains files or subdirectories, it will not be removed, and an error will be displayed.
Syntax
rmdir [options] [directory_name]
Here:
[options]
are optional flags, such as--ignore-fail-on-non-empty
to ignore errors when directories are not empty.<code>[directory_name]
is the name of the directory to be removed.
rm command
The rm
command is used to remove files or directories. Unlike rmdir, rm
can delete both empty and non-empty directories when used with the correct options.
Syntax
rm [options] [file_name/directory_name]
Here:
[options]
include-r
for recursive deletion (used for directories) and-f
to force deletion without prompting.[file_name/directory_name]
is the name of the file or directory to delete.
touch command
The touch
command is primarily used to create empty files. It can also update the timestamp of existing files.
Syntax
touch [options] [file_name]
Here:
[options]
include-a
changing access time and-m
modifying the timestamp.[file_name]
is the name of the file to create or modify.
cp command
The cp
command is used to copy files and directories from one location to another.
Syntax
cp [options] [source] [destination]
Here:
[options]
include-r
for copying directories recursively and-u
to only copy updated files.[source]
is the file or directory to copy, and[destination]
is the target location.
mv command
The mv
command in Unix and Linux is used to move or rename files and directories. By specifying the source file and destination, mv
either relocate the file to a new directory or rename it within the same directory.
Syntax
mv [options] [source] [destination]
Here:
[options]
include-i
to prompt before overwriting and-u
only to move updated files.[source]
is the file or directory to move, and[destination]
is the target location or new name.
find command
The find
command is used to search for files or directories in a directory hierarchy based on various criteria such as name, size, type, or permissions.
Syntax
find [path] [expression]
Here:
[path]
: The directory to start the search (default is the current directory.
).[expression]
: Criteria like-name
,-type
,-size
, etc.
locate command
The locate
command searches for files using a pre-built database (maintained by updatedb
), making it faster than find
command.
Syntax
locate [pattern]
Here:
[pattern]
: The name or partial name of the file to search for.
tree command
The tree
command displays the contents of a directory in a tree-like structure, showing the hierarchical relationship between files and folders.
Syntax
tree [options] [path]
Here:
[options]
: Flags to modify the output, such as -L for limited depth.[path]
: The directory to display (default is the current directory).
basename command
The basename
command extracts the filename from a full path.
Syntax
basename [path] [suffix]
Here:
[path]
: The full path of the file.[suffix]
: Optional string to remove from the end of the filename.
dirname command
The dirname
command extracts the directory path from a full file path.
Syntax
dirname [path]
Here:
[path]
: The full path of the file.
stat command
The stat
command displays detailed information about a file, including size, permissions, modification time, and more.
Syntax
stat [file_name]
Here:
[file_name]
: The name of the file to inspect.
Check out the Best Linux Distro for Gaming for this year.
Linux Commands for Viewing and Editing Files
cat command
The cat
command is used to display the contents of a file, combine multiple files, or create new files.
Syntax
cat [options] [file_name]
Here:
[options]
include-n
to number lines and-E
to show end-of-line characters.[file_name]
is the file to display or concatenate.
nano command
The nano
command is a text editor that allows you to view and edit files directly in the terminal.
Syntax
nano [file_name]
Here:
[file_name]
is the file to open or create for editing.
vim command
The vim
command is another powerful text editor in Linux. It offers extensive features for code editing and customization.
Syntax
vim [file_name]
Here:
[file_name]
is the file to open or edit usingvim
.
head command
The head
command displays the first few lines of a file, making it useful for quickly viewing file headers.
Syntax
head [options] [file_name]
Here:
[options]
include-n [number]
specifying the number of lines to display.[file_name]
is the file to read.
tail command
The tail
command shows the last few lines of a file, which helps monitor log files.
Syntax
tail [options] [file_name]
Here:
[options]
include-f
following file updates in real-time.<code>[
file_name] is the file to read.
tac command
The tac
command displays the contents of a file in reverse order, with the last line appearing first and the first line appearing last.
Syntax
tac [options] [file_name]
Here:
[options]
include-s
to specify a separator other than a new line.[file_name]
is the file to be displayed in reverse order.
less command
The less
command allows you to view file content one screen at a time, enabling easy navigation.
Syntax
less [options] [file_name]
Here:
[options]
include-N
display line numbers and-S
horizontal scrolling.[file_name]
is the file you want to view.
more command
The more
command displays file content one screen at a time, similar to less
.
Syntax
more [options] [file_name]
Here:
[options]
include-d
to display navigation instructions and-c
to repaint the screen on each scroll.[file_name]
is the file you want to view.
gedit command
The gedit
command is a graphical text editor used for creating and editing text files.
Syntax
gedit [options] [file_name]
Here:
[options]
include--new-window
to open a new window and--standalone
run without GNOME services.[file_name]
is the file you want to create or edit.
wc command
The wc
command counts the number of lines, words, and characters in a file.
Syntax
wc [options] [file_name]
Here:
[options]
include-l
to count lines,-w
to count words, and-c
to count characters.[file_name]
is the file to analyze.
Check 10+ Best Free Download Managers for Linux for this year.
Linux Commands for Permissions and Ownership
chmod command
The chmod
command is used to change file permissions in Linux, defining who can read, write, or execute files.
Syntax
chmod [permissions] [file_name]
Here:
[permissions]
can be numeric (e.g.,755
) or symbolic (e.g.,u+x
to add execute permission for the owner).[file_name]
is the file or directory to modify.
chown command
The chown
command changes the ownership of a file or directory.
Syntax
chown [options] [owner][:group] [file_name]
Here:
[options]
include-R
applying changes recursively to directories.[owner]
is the new owner, and[group]
is the new group (optional).
umask command
The umask
command sets the default file permissions for newly created files and directories by subtracting the mask value from the system’s default permissions.
Syntax
umask [options] [mask_value]
Here:
[options]
include-S
to display the mask in symbolic notation.[mask_value]
is the permission mask to apply, typically in octal format.
lsattr command
The lsattr
command displays the attributes of files and directories, which control specific behaviors such as immutability.
Syntax
lsattr [options] [file_name]
Here:
[options]
include-d
to list attributes of directories and-R
for recursive listing.[file_name]
is the file or directory whose attributes you want to display.
chattr command
The chattr
command changes the attributes of files and directories, affecting their behavior, such as making them immutable.
Syntax
chattr [options] [attributes] [file_name]
Here:
[options]
include-R applying
changes recursively to directories.[attributes]
are the attribute flags to set, such as+i
for immutability.[file_name]
is the file or directory whose attributes you want to modify.
Linux Commands for Disk Usage and Management
df command
The df
command displays the disk space usage of file systems, including available and used space.
Syntax
df [options] [file_name]
Here:
[options]
include-h
for human-readable output and-T
to display the file system type.[file_name]
specifies a particular file or directory to analyze its file system.
du command
The du
command shows the disk usage of files and directories, including their sizes.
Syntax
du [options] [file_name]
Here:
[options]
include-h
human-readable sizes and-a
display all files.[file_name]
specifies the file or directory to analyze.
mount command
The mount
command mounts a file system, making it accessible for use.
Syntax
mount [options] [device] [mount_point]
Here:
[options]
include-o
for mounting with specific options like read-only (ro
).[device]
is the storage device to be mounted.[mount_point]
is the directory where the file system will be accessible.
umount command
The umount
command unmounts a file system, detaching it from the system.
Syntax
umount [options] [device_or_mount_point]
Here:
[options]
include-f
to force unmount and-l
for lazy unmounting.[device_or_mount_point]
is the mounted device or directory to unmount.
fsck command
The fsck
command checks and repairs a file system for errors or inconsistencies.
Syntax
fsck [options] [file_system]
Here:
[options]
include-y
automatically repair errors and -a automatic checks.[file_system]
is the specific file system to check.
blkid command
The blkid
command locates and displays block device attributes such as UUID and file system type.
Syntax
blkid [options] [device]
Here:
[options]
include-o
for output format and-s
to display specific attributes.- [device] is the block device to analyze.
lsblk command
The lsblk
command lists information about block devices, including their hierarchy and attributes.
Syntax
lsblk [options]
Here:
[options]
include-f
to display file system details and-a
for all devices.
mkfs command
The mkfs
command creates a new file system on a device.
Syntax
mkfs [options] [file_system_type] [device]
Here:
[options]
include-t
specifying the file system type.[file_system_type]
is the type of file system to create, such as ext4 or xfs.[device]
is the block device where the file system will be created.
parted command
The parted
command partitions a disk, allowing you to create, resize, or delete partitions.
Syntax
parted [options] [device]
Here:
[options]
include-l
to list partitions and-s
for scripting mode.[device]
is the disk to partition.
fdisk command
The fdisk
command partitions a disk interactively, enabling detailed control over partition tables.
Syntax
fdisk [options] [device]
Here:
[options]
include-l
to list partitions and-u
for sector unit display.[device]
is the disk to partition.
Linux Commands for Process Management
ps command
The ps
command lists the running processes on the system, providing information like process ID, terminal, CPU usage, and memory usage. It is commonly used to check the status of specific processes or troubleshoot issues.
Syntax
ps [options]
Here:
[options]
include-e
to display all processes and-f
for full details.
top command
The top
command displays real-time system processes, showing resource usage like CPU and memory. It provides dynamic updates, making it useful for monitoring system performance.
Syntax
top [options]
Here:
[options]
include-u
to filter by a specific user and-n
to limit the number of iterations.
htop command
The htop
command is an interactive process viewer that allows users to monitor and manage processes using an intuitive interface. It displays color-coded resource usage, and processes can be killed or prioritized directly from the interface.
Syntax
htop [options]
Here:
[options]
include-d
to set the delay between updates and-u
to filter by a user.
kill command
The kill
command terminates a process by specifying its process ID (PID
). It can send different signals, with the default being SIGTERM
to request a graceful termination.
Syntax
kill [options] [PID]
Here:
[options]
include-9
for forced termination.[PID]
is the ID of the process to terminate.
killall command
The killall
command terminates all processes that match a specified name. It is useful for ending multiple instances of a program simultaneously.
Syntax
killall [options] [process_name]
Here:
[options]
include-u
to kill the processes of a specific user.[process_name]
is the name of the process to terminate.
jobs command
The jobs
command lists all active background jobs in the current shell session. It displays job IDs, statuses, and associated commands.
Syntax
jobs [options]
Here:
[options]
include-l
to show process IDs.
fg command
The fg
command brings a background job to the foreground, resuming its execution in the terminal. It is typically used with a job ID to specify which job to foreground.
Syntax
fg [job_ID]
Here:
[job_ID]
is the identifier of the background job to bring to the foreground.
bg command
The bg
command resumes a stopped job in the background, allowing the terminal to be free for other tasks. It is often used to continue paused processes.
Syntax
bg [job_ID]
Here:
[job_ID]
is the identifier of the job to resume in the background.
nice command
The nice
command starts a process with a specified priority level, allowing resource allocation to be adjusted. Lower priority levels are “nicer” to other processes, reducing their resource usage.
Syntax
nice [options] [command]
Here:
[options]
include-n
to set the priority value.[command]
is the program or script to execute.
renice command
The renice
command changes the priority of a running process, modifying its resource allocation. It can target processes by PID
, user, or group.
Syntax
renice [priority] [options]
Here:
[priority]
is the new priority value to assign.[options]
include-p
to specify a PID or-u
for a user.
Linux Command for Networking
ping command
The ping
command tests connectivity to a host by sending ICMP
echo requests and measuring response times. It helps diagnose network connectivity issues.
Syntax
ping [options] [host]
Here:
[options]
include-c
to limit the number of pings and-i
to set the interval between pings.[host]
is the IP address or domain to test.
ifconfig command
The ifconfig
command displays or configures network interfaces on a system. It has been largely replaced by the ip
command in modern systems.
Syntax
ifconfig [interface] [options]
Here:
[interface]
specifies the network interface to configure.[options]
includeup
enabling the interface and down disabling it.
ip command
The ip
command manages IP addresses, routes, and interfaces, providing detailed network configuration options. It is the modern replacement for ifconfig
.
Syntax
ip [options] [object]
Here:
[options]
includeaddr
to display IP addresses andlink
for interface details.[object]
specifies the type of network entity to manage, such as address or route.
netstat command
The netstat
command displays network connections, routing tables, and interface statistics. It is useful for monitoring network activity and diagnosing issues.
Syntax
netstat [options]
Here:
[options]
include-a
to show all connections and-r
for the routing table.
ss command
The ss
command provides detailed network statistics, including active connections and listening ports. It is faster and more efficient than netstat
.
Syntax
ss [options]
Here:
[options]
include-t
to show TCP connections and-l
for listening ports.
traceroute command
The traceroute
command shows the route packets take to reach a host, including the delay at each hop. It is used to troubleshoot network routing issues.
Syntax
traceroute [options] [host]
Here:
[options]
include-n
to disable hostname resolution and-m
to set the maximum hops.[host]
is the IP address or domain to trace.
curl command
The curl
command transfers data to or from a server using various protocols, such as HTTP
, FTP
, and SFTP
. It is commonly used for testing APIs and downloading files.
Syntax
curl [options] [URL]
Here:
[options]
include-O
saving the file and-I
fetching only the headers.[URL]
is the address of the server or file to access.
wget command
The wget
command downloads files from the web using HTTP
, HTTPS
, or FTP
. It supports resuming downloads and recursive retrieval.
Syntax
wget [options] [URL]
Here:
[options]
include-c
resuming a download and-r
recursive downloading.[URL]
is the address of the file to download.
scp command
The scp
command securely copies files between systems using SSH. It ensures encrypted file transfers for enhanced security.
Syntax
scp [options] [source] [destination]
Here:
[options]
include-r
copying directories and-P
specifying an SSH port.[source]
is the file or directory to copy.[destination]
is the target location for the copy.
rsync command
The rsync
command synchronizes files between systems, supporting incremental file transfers and compression. It is highly efficient for backups and mirroring.
Syntax
rsync [options] [source] [destination]
Here:
[options]
include-a
for archive mode and-z
for compression.[source]
is the file or directory to synchronize.[destination]
is the target location for synchronization.
Linux Command for User Management
who command
The who
command shows a list of users currently logged into the system, along with their login times and terminals. It helps monitor system usage.
Syntax
who [options]
Here:
[options]
include-a
to display all available information and-q
to show only the user count.
w command
The w
command displays a detailed overview of who is logged in and what they are doing, including their processes and resource usage. It provides system load averages as well.
Syntax
w [options]
Here:
[options]
include-h
to hide the header and-u
to show the idle time.
whoami command
The whoami
command displays the username of the current user. It is commonly used to confirm the active user in a session.
Syntax
whoami
id command
The id
command displays the current user’s ID, group ID, and supplementary group information. It is useful for verifying user permissions and group memberships.
Syntax
id [options] [username]
Here:
[options]
include-u
for user ID only and-g
for group ID only.[username]
specifies a user to query (optional
).
adduser command
The adduser
command adds a new user to the system, creating their home directory and setting
Syntax
adduser [options] [username]
Here:
[options]
include--home
to specify a custom home directory and--shell
to set a default shell.[username]
is the name of the new user to add.
useradd command
The useradd
command is an alternative way to add a new user to the system, typically used in scripting or non-interactive environments. Unlike adduser
, it doesn’t automatically create home directories or set default files.
Syntax
useradd [options] [username]
Here:
[options]
include-m
creating a home directory and-s
specifying the shell.[username]
is the name of the new user to add.
passwd command
The passwd
command is used to change the password of a user. It can also set password expiration policies for improved security.
Syntax
passwd [options] [username]
Here:
[options]
include-l
locking the account and-u
unlocking it.[username]
specifies the user whose password is to be changed.
deluser command
The deluser
command deletes a user from the system, optionally removing their home directory and files. It is typically used to clean up inactive or unnecessary accounts.
Syntax
deluser [options] [username]
Here:
[options]
include--remove-home
deleting the user’s home directory.[username]
is the name of the user to delete.
groupadd command
The groupadd
command adds a new group to the system. It is useful for organizing users into groups with shared permissions.
Syntax
groupadd [options] [group_name]
Here:
[options]
include-g
specifying the group ID and-f
force the creation if the group already exists.[group_name]
is the name of the new group.
groups command
The groups
command shows the groups a user belongs to. It is useful for verifying group memberships and ensuring proper permissions.
Syntax
groups [username]
Here:
[username]
is the name of the user whose groups are to be displayed (optional
).
Linux Command for Package Management
Debian-Based Systems Commands
Debian-based systems are widely used for their stability and flexibility, with powerful package management tools to simplify software installation, removal, and updates. The package management system relies on commands like apt-get
, apt
, and dpkg
to handle packages and dependencies, ensuring smooth operation and efficient system maintenance. These commands allow users to easily manage software and customize their system to meet specific needs. Check the Package Management Linux Command for the Debian-based systems:
apt-get command
The apt-get
command is used to install
, remove
, and update
packages on Debian-based systems. It is a powerful tool for package management, especially for system-wide operations.
Syntax
apt-get [options] [command]
Here:
[options]
include-y
to automatically confirm actions and-q
for quiet mode.[command]
includes actions likeinstall
,remove
, andupgrade
.
apt command
The apt
command is a modern alternative to apt-get
managing packages on Debian-based systems. It combines several functionalities, offering a more user-friendly interface.
Syntax
apt [options] [command]
Here:
[options]
include-y
to confirm actions and-q
for quiet output.[command]
includes actions likeinstall
,remove
, andupdate
.
dpkg command
The dpkg
command is used to manage individual Debian packages at a lower level, such as installing, removing, or querying package details. It is often used in conjunction with <code>.
deb package files.
Syntax
dpkg [options] [command]
Here:
[options]
include-i
to install a package and-r
to remove it.[command]
includes actions like-l
for listing installed packages and-s
for querying package status.
Red Hat-Based Systems Commands
yum command
The yum
command is used for package management on Red Hat-based systems, allowing users to install, remove, and update packages. It also manages package dependencies automatically.
Syntax
yum [options] [command]
Here:
[options]
include-y
to automatically confirm actions and-q
for quiet output.[command]
includes actions likeinstall
,remove
, andupdate
.
dnf command
The dnf
command is a modern alternative to yum
, providing better performance and more features. It is the default package manager on newer Red Hat-based systems.
Syntax
dnf [options] [command]
Here:
[options]
include-y
for automatic confirmation and-q
for quiet mode.[command]
includes actions likeinstall
,remove
, andupdate
.
rpm command
The rpm
command is used to manage individual RPM packages on Red Hat-based systems. It can install
, uninstall
, and query packages, but lacks the automatic dependency resolution yum
and dnf
.
Syntax
rpm [options] [command]
Here:
[options]
include-i
to install a package and-e
to remove it.[command]
includes actions like-q
for querying packages and-V
for verifying packages.
Generic Commands
snap command
The snap
command is used to manage Snap packages, which are self-contained applications that work across various Linux distributions. It simplifies software installation and updates.
Syntax
snap [options] [command]
Here:
[options]
includeinstall
to install Snap packages andremove
to uninstall them.[command]
includes actions likelist
for showing installed snaps and refresh for updating snaps.
flatpak command
The flatpak
command is used to manage Flatpak
applications, which are containerized software packages that can run across different Linux distributions. It provides a standardized approach to application installation.
Syntax
flatpak [options] [command]
Here:
[options]
includeinstall
to install applications anduninstall
to remove them.[command]
includes actions likelist
to display installedFlatpak
apps andupdate
to update them.
Linux Commands for System Monitoring
uptime command
The uptime
command shows how long the system has been running, including the current time, system uptime, and load averages. It helps monitor system performance and the time since the last reboot.
Syntax
uptime [options]
Here:
[options]
include-p
to display a human-readable format for uptime.
free command
The free
command displays memory usage, showing total, used, free, and available memory on the system. It also provides details about swap space usage.
Syntax
free [options]
Here:
[options]
include-h
for human-readable format and-t
to show total memory (RAM + swap).
vmstat command
The vmstat
command reports information about system performance, including memory, CPU, I/O, and swap usage. It is useful for diagnosing performance issues and analyzing system resources.
Syntax
vmstat [options] [delay] [count]
Here:
[options]
include-s
for displaying system statistics and-m
for memory statistics.[delay]
is the time interval between reports, andcount
is the number of reports to generate.
iostat command
The iostat
command displays CPU and I/O statistics, including device utilization and throughput. It helps in monitoring the performance of CPU and storage subsystems.
Syntax
iostat [options] [device]
Here:
[options]
include-c
to display CPU statistics and-d
for disk statistics.[device]
specifies a particular storage device (optional
).
sar command
The sar
command monitors system activity, collecting and displaying performance data for various system resources. It provides insights into CPU, memory, disk, and network usage.
Syntax
sar [options] [interval] [count]
Here:
[options]
include-u
for CPU utilization and-r
for memory usage.[interval]
defines the time between each report, andcount
specifies the number of reports.
dmesg command
The dmesg
command displays kernel messages, including boot-up logs and hardware-related events. It is useful for troubleshooting hardware issues and monitoring system initialization.
Syntax
dmesg [options]
Here:
[options]
include-T
to display timestamps and-l
to filter by log level.
Linux Commands for Archiving and Compression
tar command
The tar
command is used to archive files and directories into a single file, often for easier storage or transfer. It can also compress files when combined with other utilities like gzip
or bzip2
.
Syntax
tar [options] [archive_name] [files]
Here:
[options]
include-c
for creating an archive,-x
for extracting, and-f
to specify the archive file name.[archive_name]
is the name of the resulting archive, and[files]
are the files or directories to be archived.
gzip command
The gzip
command is used to compress files, reducing their size using the GZIP
compression algorithm. It is commonly used tar
to create compressed archives.
Syntax
gzip [options] [file]
Here:
[options]
include-d
for decompressing and-k
to keep the original file.[file]
is the file to compress.
gunzip command
The gunzip
command is used to decompress .gz
files, restoring them to their original state. It works by reversing the compression done by gzip
.
Syntax
gunzip [options] [file]
Here:
[options]
include-c
to output to stdout and-k
to keep the original file.[file]
is the.gz
file to decompress.
zip command
The zip
command compresses files and directories into a .zip
archive, widely used for packaging multiple files into a single compressed file. It supports encryption and password protection.
Syntax
zip [options] [archive_name] [files]
Here:
[options]
include-r
to compress directories recursively and-e
to encrypt the archive.[archive_name]
is the name of the resulting.zip
file, and[files]
are the files or directories to compress.
unzip command
The unzip
command extracts files from a .zip
archive, allowing you to access the contents. It is commonly used for decompressing .zip
files downloaded from the web.
Syntax
unzip [options] [archive_name]
Here:
[options]
include-l
to list the contents and-d
to specify the destination directory.[archive_name]
is the.zip
archive to extract.
xz command
The xz
command compresses files using the XZ compression format, which provides high compression ratios. It is often used for compressing large files or directories.
Syntax
xz [options] [file]
Here:
[options]
include-d
for decompressing and-k
to keep the original file.[file]
is the file to compress.
7z command
The 7z
command is used to compress files using the 7-Zip compression format, known for its high compression ratio. It supports a variety of formats for both compression and extraction.
Syntax
7z [options] [archive_name] [files]
Here:
[options]
include-<code>a
for creating an archive and-<code>x
for extracting files.[archive_name]
is the name of the resulting archive, and[files]
are the files or directories to compress.
Linux Commands for Search and Text Processing
grep command
The grep
command is used to search for specific patterns within files, displaying matching lines. It supports regular expressions, allowing for powerful and flexible search capabilities.
Syntax
grep [options] [pattern] [file]
Here:
[options]
include-i
for case-insensitive search and-r
for recursive search in directories.[pattern]
is the search string or regular expression, and[file]
is the file or directory to search in.
awk command
The awk
command is a powerful text processing tool used for analyzing and manipulating text files, typically structured in columns. It supports complex pattern scanning and processing, often used for reports or data extraction.
Syntax
awk [options] 'program' [file]
Here:
[options]
include-F
to specify the field separator and-v
to set variables.[program]
is the AWK script to run, and[file]
is the input file to process.
sed command
The sed
command is a stream editor used for modifying text in files or streams, supporting functions like substitution, deletion, and insertion. It is often used for automated text transformations in scripts.
Syntax
sed [options] 'command' [file]
Here:
[options]
include-i
for in-place editing and-e
to specify multiple commands.[command]
defines the sed action (e.g., substitution or deletion), and[file]
is the file to edit.
sort command
The sort
command arranges the lines in a file or stream in a specified order, such as ascending or descending. It supports sorting by numeric or lexicographic values and can handle multiple columns.
Syntax
sort [options] [file]
Here:
[options]
include-n
for numerical sorting and-r
for reverse order.[file]
is the file or stream to sort.
uniq command
The uniq
command filters out consecutive duplicate lines in a file or stream, often used in conjunction with sort
to remove repeated entries. It helps in reducing redundant data in output.
Syntax
uniq [options] [file]
Here:
[options]
include-c
counting duplicates and-d
showing only duplicate lines.[file]
is the file or stream to process.
cut command
The cut
command extracts specific fields or columns from text files or streams, based on a delimiter. It is useful for extracting structured data like CSV files or logs.
Syntax
cut [options] [file]
Here:
[options]
include-d
to specify the delimiter and-f
to specify which fields to extract.[file]
is the file or stream to process.
diff command
The diff
command compares two files line by line, showing differences between them. It is commonly used to identify changes in configuration files or source code.
Syntax
diff [options] [file1] [file2]
Here:
[options]
include-u
for unified format and-c
for context format.[file1]
and[file2]
are the files to compare.
cmp command
The cmp
command compares two files byte by byte, useful for detecting differences at a binary level. It reports the first byte and line where the files differ.
Syntax
cmp [options] [file1] [file2]
Here:
[options]
include-b
for byte-by-byte comparison and-l
to display all differing bytes.[file1]
and[file2]
are the files to compare.
tee command
The tee
command reads from standard input and writes to both standard output and one or more files, allowing for the simultaneous capture and display of output. It is often used in pipelines to save command results.
Syntax
tee [options] [file]
Here:
[options]
include-a
to append output to the file and-i
for case-insensitive operation.[file]
is the file or files to which output is redirected.
Top 100 Linux Commands PDF Download
We’ve created a Linux Command Handbook for our readers, providing a curated list of the Top 100 Linux Commands to help you navigate and master the Linux environment with ease. Whether you’re a beginner or an experienced user, this PDF covers the most essential and powerful commands to enhance your workflow and productivity.
Feel free to check out the Top 100 Linux Commands PDF, and download it for free. Keep this handy guide with you to quickly reference commands whenever needed and accelerate your Linux journey.
Closing Comments
The 100 Linux commands discussed in this article are fundamental tools for file management, text processing, system monitoring, and network management. Understanding and effectively utilizing these commands can significantly enhance your efficiency in managing Linux systems and automating tasks. Whether you are working with package management, system resources, or comparing files, these commands provide essential functionality for both routine operations and advanced system administration tasks. Mastery of these commands is crucial for anyone looking to work proficiently within a Linux environment.