2025 Exclusive "20% OFF OFFER" for London Dedicated Servers See All

Top 50 Linux Commands That We Need Everyday

This compilation features 50 crucial Linux commands, organized by their relevance in everyday use. These commands cover file management, text editing, and system operations, making them essential for both casual users and professionals.

Essential Linux Commands for Day-to-Day Life

This compilation features 50 crucial Linux commands, organized by their relevance in everyday use. These commands are indispensable for tasks such as file management, text editing, and basic system operations. Keep in mind that the significance of each command can vary based on your specific role and the tasks you frequently undertake. Whether you’re a system administrator, developer, or casual user, your list of essential commands might differ.

ls
cd
pwd
cp
mv
rm
mkdir
cat
less
grep
sudo
ssh
man
nano
vim
touch
chmod
chown
ps
top
kill
apt/yum/dnf
wget
curl
ping
ifconfig/ip
tar
gzip
unzip
find
df
du
free
history
passwd
uname
date
whoami
which
alias
echo
tail
head
diff
wc
sort
uniq
sed
awk
cut
1. ls - List directory contents

The ls command in Linux is used to list the contents of a directory. It shows the files, folders, and other items located in the specified directory. By default, if no directory is specified, it lists the contents of the current directory.

Basic Syntax:

This command lists all the files and directories in the current directory.

bash
ls
Examples:

-l: Displays detailed information (permissions, owner, size, modification time) about each file or directory.

bash
ls -l

-a: Shows all files, including hidden ones (those that start with a dot .).

bash
ls -a

-h: Used with -l to show file sizes in human-readable format (e.g., KB, MB).

bash
ls -lh

-R: Recursively lists contents of all subdirectories.

bash
ls -R
2. cd - Change directory

The cd command in Linux stands for change directory. It allows you to navigate between different directories (folders) in the file system.

Basic Syntax:
bash
cd [directory]

Where [directory] is the path to the directory you want to switch to.

Examples:

Change to a specific directory:

bash
cd /home/user/Documents

This command moves you to the Documents directory inside the /home/user folder.

Change to the home directory: Simply type cd with no arguments, and it will take you to your user's home directory:

bash
cd

Go to the parent directory: To move up one directory level (to the parent folder):

bash
cd ..

Return to the previous directory: To switch back to the last directory you were in:

bash
cd -

Navigate to a relative path: If you are in /home/user/, and you want to go to the Documents folder inside it, you can use:

bash
cd Documents
Notes:
  • Paths can be absolute (starting from the root /) or relative (starting from the current location).

  • You can use ~ to represent the home directory. For example:

bash
cd ~/Downloads
3. pwd - Print working directory

The pwd command in Linux stands for Print Working Directory. It shows the full path of the directory you are currently in. This is useful when you want to know your exact location within the filesystem.

Basic Syntax:
bash
pwd

If you're inside the /home/user/Documents directory, this command will output:

bash
/home/user/Documents
Use Case:
  • Confirm current directory: When you're navigating through directories and want to verify where you are.

  • Absolute path reference: It helps you determine the complete path to your current location, which is important for scripts or referencing files.

Examples:

-P: Displays the physical path by resolving symbolic links.

bash
pwd -P

-L: Displays the logical path, showing any symbolic links (this is usually the default behavior).

bash
pwd -L
Summary:

The pwd command tells you exactly which directory you're in, showing its absolute path from the root (/).

4. cp - Copy files or directories

The cp command in Linux is used to copy files and directories from one location to another. It can copy single files, multiple files, or entire directories.

Basic Syntax:
bash
cp [options] source destination
  • source: The file or directory you want to copy.

  • destination: The location where you want the file or directory to be copied.

Examples:
bash
cp file1.txt /home/user/Documents/

This command copies file1.txt to the /home/user/Documents/ directory.

-r or -R: Copy directories recursively (copy all contents inside a directory). Without this option, cp only copies files.

bash
cp -r /source/directory /destination/directory

This will copy everything from /source/directory to /destination/directory.

-i: Prompt before overwriting an existing file in the destination.

bash
cp -i file1.txt /home/user/Documents/

If file1.txt already exists in /home/user/Documents/, you'll be asked whether to overwrite it.

-v: Verbose mode, which shows each file being copied.

bash
cp -v file1.txt /home/user/Documents/

This will display output like:

bash
'file1.txt' -> '/home/user/Documents/file1.txt'

-u: Copy only if the source file is newer than the destination file, or if the destination file doesn't exist.

bash
cp -u file1.txt /home/user/Documents/

-p: Preserve file attributes like timestamps, ownership, and permissions while copying.

bash
cp -p file1.txt /home/user/Documents/

Copy a file to a different directory:

bash
cp myfile.txt /home/user/backup/

Copy multiple files to a directory:

bash
cp file1.txt file2.txt /home/user/Documents/

Copy an entire directory and its contents:

bash
cp -r /home/user/project /backup/project_backup/
Summary:
  • The cp command is used for copying files or directories.

  • You can copy individual files, multiple files, or entire directories recursively.

  • Options like -i (interactive), -r (recursive), -v (verbose), and -p (preserve attributes) offer more control over the copy process.

5. mv - Move or rename files or directories

The mv command in Linux is used to move or rename files and directories. It either relocates a file/directory to a different location or renames it in the same directory. The behavior depends on whether the destination is a new or existing path.

Basic Syntax:
bash
mv [options] source destination
  • source: The file or directory you want to move or rename.

  • destination: The new location or the new name for the file or directory.

Examples:

Move a file to a new directory:

bash
mv file1.txt /home/user/Documents/

This moves file1.txt to the /home/user/Documents/ directory.

Rename a file:

bash
mv oldname.txt newname.txt

This renames oldname.txt to newname.txt within the same directory.

-i: Interactive mode. Prompts before overwriting an existing file in the destination.

bash
mv -i file1.txt /home/user/Documents/

If file1.txt already exists in the /home/user/Documents/ directory, you'll be asked whether to overwrite it.

-f: Force overwrite of the destination file without prompting.

bash
mv -f file1.txt /home/user/Documents/

This will overwrite any existing file1.txt in the destination directory without warning.

-n: Prevents overwriting files in the destination.

bash
mv -n file1.txt /home/user/Documents/

-v: Verbose mode. Shows the details of the move/rename operation.

bash
mv -v file1.txt /home/user/Documents/

Output:

bash
'file1.txt' -> '/home/user/Documents/file1.txt'

Move multiple files to a directory:

bash
mv file1.txt file2.txt /home/user/Documents/

Moves file1.txt and file2.txt to /home/user/Documents/.

Rename a directory:

bash
mv old_directory new_directory

Renames old_directory to new_directory.

Move and rename a file:

bash
mv file1.txt /home/user/Documents/newfile.txt

This moves file1.txt to the /home/user/Documents/ directory and renames it to newfile.txt.

Move a directory and its contents:

bash
mv /source/directory /destination/directory

Moves the entire directory from /source/ to /destination/.

Summary:
  • The mv command is used to move files/directories to another location or rename them.

  • It doesn’t copy the file—it physically relocates it (unlike cp).

  • It can also be used interactively (-i), forcefully (-f), or with verbose output (-v).

6. rm - Remove files or directories

The rm command in Linux is used to remove (delete) files or directories. By default, it only removes files, but with the right options, it can delete directories and their contents as well.

Basic Syntax:
bash
rm [options] file
  • file: The file(s) or directory you want to remove.

Examples:
bash
rm file1.txt

This removes the file file1.txt from the current directory.

-r or -R: Recursively remove directories and their contents. This is necessary when deleting directories.

bash
rm -r directory/

This command deletes the directory named directory and all of its contents (subdirectories, files).

-f: Force removal without prompting for confirmation, even if the files are write-protected.

bash
rm -f file1.txt

This removes file1.txt without asking for confirmation, even if the file is write-protected.

-i: Interactive mode, which prompts for confirmation before each file is deleted.

bash
rm -i file1.txt

The system will ask: rm: remove regular file 'file1.txt'?, and you can respond with y (yes) or n (no).

-v: Verbose mode. Displays what is being deleted.

bash
rm -v file1.txt

This will output:

bash
removed 'file1.txt'

-rf or -r -f: Combine recursive and force options to delete a directory and its contents without confirmation.

bash
rm -rf directory/

This forcefully removes the directory and everything inside it without asking for confirmation.

Remove a single file:

bash
rm file1.txt

Remove multiple files:

bash
rm file1.txt file2.txt file3.txt

Remove a directory and all its contents:

bash
rm -r mydir/

This removes the directory mydir and everything inside it (including subdirectories and files).

Force-remove files without prompts:

bash
rm -f file1.txt

This deletes file1.txt without asking for confirmation, even if the file is write-protected.

Recursively and forcefully remove a directory:

bash
rm -rf /home/user/old_project/

This will forcefully and recursively delete the old_project directory and everything inside it.

Important Warning:
  • rm does not move files to the trash/recycle bin, it permanently deletes them. Be cautious when using rm, especially with the -r and -f options, as it can delete large amounts of data without recovery options.

Summary:
  • The rm command is used to delete files and directories.

  • Use -r for recursive deletion of directories, and -f to force deletion without confirmation.

  • Always use caution, especially when combining -r and -f options, as it can result in irreversible deletion of directories and files.

7. mkdir - Make directory

The mkdir command in Linux stands for Make Directory. It is used to create one or more new directories (folders) in the file system.

Basic Syntax:
bash
mkdir [options] directory_name
  • directory_name: The name of the directory you want to create.

Examples:
bash
mkdir mydir

This creates a directory named mydir in the current location.

-p: Create parent directories as needed. This option allows you to create a nested directory structure, including any parent directories that don’t exist.

bash
mkdir -p /home/user/projects/newproject

This will create the projects and newproject directories, even if projects does not exist.

-v: Verbose mode, which displays a message for each directory created.

bash
mkdir -v mydir

Output:

bash
mkdir: created directory 'mydir'

-m: Set the permissions for the new directory using octal mode (like chmod). For example, to create a directory with specific permissions:

bash
mkdir -m 755 mydir

This will create mydir with rwxr-xr-x permissions, where the owner has read, write, and execute permissions, and others only have read and execute.

Create multiple directories at once:

bash
mkdir dir1 dir2 dir3

This creates three directories: dir1, dir2, and dir3.

Create nested directories:

bash
mkdir -p /home/user/projects/project1/src

This creates the entire path if it doesn’t exist: projects/project1/src.

Create a directory with specific permissions:

bash
mkdir -m 700 private_folder

This creates a directory named private_folder with the following permissions:

  • Owner: Read, write, and execute (rwx)

  • Group: No permissions (---)

  • Others: No permissions (---)

In symbolic notation, the permissions are represented as rwx------, meaning only the owner has full access to the directory.

Verbose directory creation:

bash
mkdir -v myfolder

This will display a message confirming the creation of the directory.

Summary:
  • The mkdir command is used to create new directories.

  • The -p option allows for creating parent directories if they do not exist.

  • The -m option lets you set permissions while creating a directory, and the -v option shows messages for each created directory.

8. cat - Concatenate and display file content

The cat command in Linux is used to concatenate (join) and display the content of files. It can read and print the content of one or more files to the terminal.

Basic Syntax:
bash
cat [options] filename
  • filename: The name of the file you want to display.

Examples:
bash
cat file1.txt

This displays the contents of file1.txt in the terminal.

View a file's content:

bash
cat file1.txt

View multiple files together:

bash
cat file1.txt file2.txt

This will display the contents of file1.txt followed by file2.txt.

Create a new file:

bash
cat > newfile.txt

After typing the command, you can input content for newfile.txt and press Ctrl+D to save.

Append to a file:

bash
cat >> file.txt

This allows you to add content to the end of file.txt.

Summary:
  • cat is used to display the contents of files in the terminal.

  • It can also be used to combine multiple files or create new ones.

9. less - View file content one screen at a time

The less command in Linux is used to view the content of a file one screen at a time. It is useful for reading large files without overwhelming the terminal.

Basic Syntax:
bash
less filename
  • filename: The name of the file you want to view.

Example:
bash
less largefile.txt

This opens largefile.txt and lets you scroll through its content.

Key Features:
  • Scroll: You can navigate up and down through the file using the arrow keys, Page Up, Page Down, or spacebar.

  • Exit: Press q to quit less and return to the terminal.

  • Search: Press / and type a keyword to search within the file.

Summary:
  • less lets you view large files one page at a time.

  • You can navigate through the file and search for text, making it easier to read large files compared to commands like cat.

10. grep - Print lines matching a pattern

The grep command in Linux is used to search for lines that match a specific pattern in a file or output. It looks for the pattern you specify and prints the matching lines.

Basic Syntax:
bash
grep [options] "pattern" filename
  • "pattern": The word or text you're searching for.

  • filename: The file where you want to search for the pattern.

Examples:
bash
grep "hello" file1.txt

This searches for the word "hello" in file1.txt and prints any line that contains it.

-i: Ignore case (case-insensitive search).

bash
grep -i "hello" file1.txt

This finds "hello", "Hello", or "HELLO".

-r: Search recursively through directories.

bash
grep -r "pattern" /path/to/directory

-n: Show line numbers for matched lines.

bash
grep -n "hello" file1.txt
Summary:
  • grep is used to search for a specific pattern or word in a file.

  • It prints the lines where the pattern is found, making it useful for quickly finding information in large files.

11. sudo - Execute a command as another user (usually with root privileges)

The sudo command in Linux stands for "superuser do". It allows you to execute commands with the privileges of another user, typically the root user, which has full control over the system.

Basic Syntax:
bash
sudo command
  • command: The command you want to run with elevated privileges.

Example:
bash
sudo apt update

This command runs apt update with root privileges, allowing it to update the package list for the system.

Key Features:
  • Permission: Only users who are authorized (usually specified in the /etc/sudoers file) can use sudo.

  • Temporary Privileges: You may be prompted to enter your password to confirm your identity, and you can then run the command without needing the root password.

  • Log Actions: Commands run with sudo are logged for security auditing.

Summary:
  • sudo allows you to run commands with higher privileges, which is often necessary for tasks like installing software or modifying system files.

  • It helps maintain security by allowing controlled access to administrative tasks without sharing the root password.

12. ssh - OpenSSH SSH client (remote login program)

The ssh command in Linux stands for Secure Shell. It is a protocol used to securely log into a remote computer or server over a network. The ssh command is part of the OpenSSH package and provides a secure way to access and manage remote systems.

Basic Syntax:
bash
ssh [user@]hostname
  • user: (optional) The username you want to log in as on the remote machine. If omitted, it defaults to the current user's name.

  • hostname: The IP address or domain name of the remote computer you want to connect to.

Examples:
bash
ssh user@example.com

This command logs you into the remote server at example.com using the username user.

-p port: Specify a different port if the SSH server is running on a port other than the default (22).

bash
ssh -p 2222 user@example.com

-i identity_file: Use a specific SSH key for authentication.

bash
ssh -i /path/to/private_key user@example.com
Key Features:
  • Encryption: SSH encrypts the connection, ensuring that data transmitted over the network is secure from eavesdroppers.

  • Authentication: You can authenticate using a password or SSH keys for added security.

  • Port Forwarding: SSH allows you to forward ports securely, which can be used to tunnel other connections through the secure SSH connection.

  • File Transfer: You can use scp or sftp, which are part of the SSH suite, to securely transfer files between machines.

Summary:
  • ssh is a command-line tool used to securely connect to remote computers.

  • It provides a secure channel for remote login, making it essential for managing servers and performing administrative tasks remotely.

13. man - Display manual pages for commands

The man command in Linux stands for manual. It is used to display the manual pages (help documentation) for other commands and programs in the terminal. This is a valuable resource for learning how to use commands, understanding their options, and finding examples.

Basic Syntax:
bash
man command
  • command: The name of the command you want to learn about.

Example:
bash
man ls

This command displays the manual page for the ls command, which lists the contents of a directory.

Key Features:
  • Sections: The manual is organized into sections, covering topics like commands, system calls, library functions, and more.

  • Navigation: You can scroll through the manual pages using the arrow keys, Page Up, Page Down, and you can exit by pressing q.

  • Search: Within the manual, you can search for specific terms by pressing /, typing the term, and hitting Enter.

Common Sections in the Manual:
  1. User Commands: General commands available to users.

  2. System Calls: Functions that programs can call to interact with the kernel.

  3. Library Functions: Functions provided by system libraries.

  4. Special Files: Information about device files.

  5. File Formats and Conventions: Descriptions of file formats and conventions.

Summary:
  • The man command is used to access detailed documentation for commands in Linux.

  • It helps users understand how to use commands effectively, providing options, syntax, and examples.

14. nano - Simple text editor

The nano command in Linux is a simple text editor that allows you to create and edit text files in the terminal. It is user-friendly and often preferred by beginners due to its straightforward interface.

Basic Syntax:
bash
nano filename
  • filename: The name of the file you want to create or edit. If the file does not exist, nano will create it.

Example:
bash
nano myfile.txt

This opens myfile.txt in the nano editor for editing.

Key Features:
  • Basic Editing: You can type, delete, and edit text easily.

  • Navigation: Use the arrow keys to move around the text.

  • Shortcuts: Common actions (like saving and exiting) are performed using keyboard shortcuts:

    • Ctrl + O: Save the file (write out).

    • Ctrl + X: Exit the editor.

    • Ctrl + K: Cut the current line.

    • Ctrl + U: Paste the cut line.

Summary:
  • nano is a simple and easy-to-use text editor for creating and editing text files directly in the terminal.

  • Its straightforward interface and keyboard shortcuts make it accessible for users of all skill levels.

15. vim - Vi Improved, a text editor

The vim command in Linux stands for Vi IMproved. It is a powerful text editor that is an enhanced version of the original vi editor. vim is widely used for editing text and programming due to its rich features and flexibility.

Basic Syntax:
bash
vim filename
  • filename: The name of the file you want to create or edit. If the file does not exist, vim will create it.

Example:
bash
vim myfile.txt

This opens myfile.txt in the vim editor for editing.

Key Features:
  • Modes: vim operates in different modes:

    • Normal Mode: For navigating and editing text (default mode).

    • Insert Mode: For entering text. You can switch to this mode by pressing i.

    • Command Mode: For executing commands, accessed by pressing :.

  • Navigation: You can use keyboard shortcuts to navigate through the text (e.g., arrow keys, h, j, k, l).

  • Saving and Exiting:

    • To save changes and exit, type :wq and press Enter.

    • To exit without saving, type :q! and press Enter.

Summary:
  • vim is a powerful text editor used for editing files and programming.

  • It offers advanced features but has a steeper learning curve compared to simpler editors like nano.

  • Understanding its modes and commands is essential for efficient use.

16. touch - Create an empty file or update file timestamps

The touch command in Linux is used to create an empty file or to update the timestamps (access and modification times) of an existing file.

Basic Syntax:
bash
touch filename
  • filename: The name of the file you want to create or update.

Example:
bash
touch myfile.txt

This command will create an empty file named myfile.txt if it doesn’t already exist. If it does exist, touch will update its timestamps to the current time.

Key Features:
  • Create an Empty File: If you specify a filename that doesn't exist, touch will create a new, empty file.

  • Update Timestamps: If the file already exists, touch will change its last modified and last accessed times to the current time without modifying its content.

Summary:
  • The touch command is a simple way to create new empty files or update the timestamps of existing files.

  • It’s commonly used in scripting and file management tasks.

17. chmod - Change file permissions

The chmod command in Linux stands for change mode. It is used to change the permissions of files and directories. File permissions determine who can read, write, or execute a file.

Basic Syntax:
bash
chmod options permissions filename
  • options: Additional options (usually not needed for basic use).

  • permissions: The new permissions you want to set (can be numeric or symbolic).

  • filename: The name of the file or directory whose permissions you want to change.

Example:
bash
chmod 755 myfile.txt

This command sets the permissions of myfile.txt so that:

  • The owner can read, write, and execute (7).

  • The group can read and execute (5).

  • Others can read and execute (5).

Understanding Permissions:
  • Numeric Method:

    • r (read) = 4

    • w (write) = 2

    • x (execute) = 1

    • Add these numbers to set permissions (e.g., 7 = 4 + 2 + 1).

  • Symbolic Method:

    • Use letters to set permissions: u (user/owner), g (group), o (others).

    • Example:

      • chmod u+x myfile.txt (adds execute permission for the owner).

Summary:
  • The chmod command is used to change file and directory permissions.

  • Properly setting permissions is crucial for system security and controlling access to files.

18. chown - Change file owner

The chown command in Linux stands for change owner. It is used to change the owner of a file or directory. This command allows you to specify which user should have ownership of a particular file.

Basic Syntax:
bash
chown new_owner filename
  • new_owner: The username of the new owner you want to assign.

  • filename: The name of the file or directory whose owner you want to change.

Example:
bash
chown john myfile.txt

This command changes the owner of myfile.txt to the user john.

Key Features:
  • Ownership: Each file and directory has an owner (the user who created it) and a group associated with it. Changing ownership can affect who has permission to access or modify the file.

  • Recursive Change: You can change the owner of all files within a directory by using the -R option:

    bash
    chown -R john /path/to/directory
Summary:
  • The chown command is used to change the owner of files and directories in Linux.

  • This is useful for managing file permissions and access control in multi-user environments.

19. ps - Report a snapshot of current processes

The ps command in Linux stands for process status. It is used to display information about the currently running processes on the system. This includes details such as the process ID (PID), the terminal associated with the process, CPU and memory usage, and the command that started the process.

Basic Syntax:
bash
ps [options]
Common Options:
  • ps: Without any options, it shows processes running in the current terminal.

  • ps aux: Displays all running processes for all users in a detailed format.

    • a: Show processes for all users.

    • u: Provide detailed information about the processes.

    • x: Show processes not attached to a terminal.

Example:
bash
ps aux

This command lists all processes currently running, along with their details.

Key Features:
  • PID: The unique identifier for each process.

  • USER: The username of the person who owns the process.

  • %CPU: The percentage of CPU usage.

  • %MEM: The percentage of memory usage.

  • VSZ: Virtual memory size of the process.

  • RSS: Resident Set Size (physical memory used).

  • TTY: The terminal associated with the process.

  • START: The time when the process started.

  • COMMAND: The command that initiated the process.

Summary:
  • The ps command is used to report a snapshot of the current processes running on the system.

  • It is a valuable tool for monitoring system activity and resource usage.

20. top - Display Linux processes

The top command in Linux is used to display real-time information about the currently running processes on the system. It provides a dynamic, continuously updated view of system activity, including CPU usage, memory usage, and process information.

Basic Syntax:

Simply type top in the terminal and press Enter:

bash
top
Key Features:
  • Real-Time Monitoring: The top command updates the displayed information every few seconds, allowing you to monitor system performance in real-time.

  • Process Information: It shows a list of processes with various details, including:

    • PID: Process ID.

    • USER: The owner of the process.

    • PR: Process priority.

    • NI: Nice value (priority adjustment).

    • VIRT: Virtual memory used by the process.

    • RES: Resident memory (physical RAM used).

    • SHR: Shared memory.

    • S: Process status (running, sleeping, etc.).

    • %CPU: CPU usage percentage.

    • %MEM: Memory usage percentage.

    • TIME+: Total CPU time consumed by the process.

    • COMMAND: The command that started the process.

  • System Summary: At the top of the top display, you can see overall system statistics, such as:

    • Total tasks (running, sleeping, stopped, zombie).

    • CPU usage (user, system, idle).

    • Memory usage (total, used, free, buffers, cached).

Interactive Commands:
  • While top is running, you can use various keyboard shortcuts to control its behavior:

    • h: Display help information.

    • k: Kill a process (you'll be prompted for the PID).

    • r: Change the priority of a process.

    • q: Quit the top command.

Summary:
  • The top command is a powerful tool for monitoring system processes and performance in real-time.

  • It provides essential information for system administration and troubleshooting, allowing users to identify resource-intensive processes and manage system performance effectively.

21. kill - Send a signal to a process

The kill command in Linux is used to send a signal to a process, which can instruct the process to terminate, pause, or perform other actions based on the signal sent. Despite its name, kill can do more than just terminate processes; it can also send various types of signals.

Basic Syntax:
bash
kill [options] PID
  • PID: The Process ID of the process you want to send a signal to.

Common Signals:
  • SIGTERM (15): The default signal sent by the kill command. It politely requests a process to terminate gracefully, allowing it to clean up resources before exiting.

  • SIGKILL (9): Forces a process to terminate immediately without performing any cleanup. This signal cannot be ignored or handled by the process.

  • SIGSTOP (19): Pauses (stops) the process. The process remains in the background and can be resumed later. This signal cannot be caught or ignored.

  • SIGCONT (18): Resumes a paused (stopped) process that was previously halted by SIGSTOP or SIGTSTP.

Example:

To gracefully terminate a process:

bash
kill 1234

This sends the default SIGTERM signal to the process with PID 1234.

To forcefully kill a process:

bash
kill -9 1234

This sends the SIGKILL signal to the process with PID 1234.

To pause a process:

bash
kill -19 1234

This sends the SIGSTOP signal to the process.

Summary:
  • The kill command is a vital tool for managing processes in Linux by sending various signals to them.

  • It's commonly used for terminating unresponsive processes, pausing tasks, or managing system resources effectively.

22. apt, yum, dnf - Package management tool

The apt, yum, and dnf commands are package management tools used in Linux distributions to handle software installation, removal, and management. Each tool is associated with different Linux distributions and serves a similar purpose.

APT (Advanced Package Tool)
  • Usage: Primarily used in Debian-based systems like Ubuntu.

  • Basic Commands:

    • Update Package List:

      bash
      sudo apt update

      This command refreshes the list of available packages and their versions.

    • Upgrade Installed Packages:

      bash
      sudo apt upgrade

      This command upgrades all installed packages to their latest versions.

    • Install a Package:

      bash
      sudo apt install package_name

      This installs a specific package.

    • Remove a Package:

      bash
      sudo apt remove package_name

      This removes a specific package.

YUM (Yellowdog Updater Modified)
  • Usage: Used in older Red Hat-based systems like CentOS and Fedora.

  • Basic Commands:

    • Update Package List and Upgrade:

      bash
      sudo yum update

      This command updates the package list and upgrades installed packages.

    • Install a Package:

      bash
      sudo yum install package_name

      This installs a specific package.

    • Remove a Package:

      bash
      sudo yum remove package_name

      This removes a specific package.

DNF (Dandified YUM)
  • Usage: The next-generation version of YUM, used in newer Red Hat-based systems like Fedora and CentOS 8.

  • Basic Commands:

    • Update Package List and Upgrade:

      bash
      sudo dnf update

      This command updates the package list and upgrades installed packages.

    • Install a Package:

      bash
      sudo dnf install package_name

      This installs a specific package.

    • Remove a Package:

      bash
      sudo dnf remove package_name

      This removes a specific package.

Summary:
  • apt is used for Debian-based distributions, while yum and dnf are used for Red Hat-based distributions.

  • These package management tools simplify software management on Linux systems by handling package installation, updates, and removal efficiently.

  • They also manage dependencies, ensuring that all necessary libraries and packages are installed for a given application to function correctly.

23. wget - Retrieve files using HTTP, HTTPS and FTP

The wget command in Linux is a powerful utility used to retrieve files from the web via HTTP, HTTPS, and FTP protocols. It is commonly used for downloading files from the internet and can handle various types of downloads, including single files, directories, and entire websites.

Basic Syntax:
bash
wget [options] [URL]
  • [options]: Optional flags to modify the behavior of the command.

  • [URL]: The web address of the file you want to download.

Example:

To download a single file:

bash
wget http://example.com/file.zip

To download a website recursively:

bash
wget -r http://example.com/

-O filename: Save the downloaded file with a specific name.

bash
wget -O custom_name.txt http://example.com/file.txt

-r: Recursively download files (used for downloading entire websites or directories).

bash
wget -r http://example.com/directory/

-P directory: Specify a directory to save the downloaded files.

bash
wget -P /path/to/directory http://example.com/file.txt

--limit-rate=rate: Limit the download speed to a specified rate.

bash
wget --limit-rate=200k http://example.com/file.zip

-c: Continue an incomplete download. This is useful for resuming large files.

bash
wget -c http://example.com/largefile.zip

--no-check-certificate: Bypass SSL certificate checks (useful for self-signed certificates).

bash
wget --no-check-certificate https://example.com/file.zip
Summary:
  • The wget command is a versatile tool for downloading files from the internet in Linux.

  • It supports various protocols (HTTP, HTTPS, FTP) and offers a wide range of options to customize the download process, making it particularly useful for both casual users and system administrators.

24. curl - Transfer data from or to a server

The curl command in Linux is a versatile tool used to transfer data to or from a server using various protocols, including HTTP, HTTPS, FTP, SCP, SFTP, and more. It is commonly used for downloading files, sending data to APIs, and testing web services.

Basic Syntax:
bash
curl [options] [URL]
  • [options]: Optional flags to modify the behavior of the command.

  • [URL]: The address of the server to connect to.

Example:

To download a file:

bash
curl -O http://example.com/file.zip

To send a JSON POST request to an API:

bash
curl -H "Content-Type: application/json" -d '{"key":"value"}' -X POST
http://example.com/api

-O: Save the output to a file with the same name as the remote file.

bash
curl -O http://example.com/file.zip

-o filename: Save the output to a specified file.

bash
curl -o custom_name.zip http://example.com/file.zip

-L: Follow redirects. This is useful for URLs that redirect to another location.

bash
curl -L http://example.com/redirected_url

-d: Send data with a POST request (useful for APIs).

bash
curl -d "param1=value1¶m2=value2" -X POST http://example.com/api

-H: Add custom headers to the request.

bash
curl -H "Authorization: Bearer token" http://example.com/api

-I: Fetch only the HTTP headers.

bash
curl -I http://example.com

-u username:password: Authenticate with a username and password.

bash
curl -u user:pass http://example.com/protected
Summary:
  • The curl command is a powerful tool for transferring data between a client and a server in Linux.

  • It supports a wide range of protocols and options, making it highly flexible for various data transfer tasks, including file downloads and API interactions. Make sure to install it if it is not already available on your system.

25. ping - Send ICMP ECHO_REQUEST to network hosts

The ping command in Linux is used to test the reachability of a network host by sending Internet Control Message Protocol (ICMP) ECHO_REQUEST packets. It is a fundamental tool for diagnosing network connectivity issues and measuring round-trip time.

Basic Syntax:
bash
ping [options] destination
  • destination: The IP address or hostname of the target you want to ping.

Example:

To ping a website, you can use:

bash
ping example.com

This command sends ICMP ECHO_REQUEST packets to example.com, displaying the response time and packet loss statistics.

Key Features:
  • Continuous Operation: By default, ping continues to send packets until interrupted. You can stop it by pressing Ctrl + C.

  • Packet Count: You can specify the number of packets to send with the -c option:

    bash
    ping -c 4 example.com
  • This command sends 4 ICMP packets to the target.

  • Timeout and Interval Options: You can adjust the wait time between packets with the -i option, or set a timeout for responses with the -W option.

Summary:
  • The ping command is a simple yet powerful tool for testing network connectivity and diagnosing issues.

  • It is generally available by default in most Linux distributions, coming from the iputils package.

  • It is widely used by network administrators and users to verify the status of network hosts and troubleshoot connectivity problems.

26. ifconfig (or ip) - Configure network interface parameters

The ifconfig command (short for "interface configuration") is used in Linux to configure network interface parameters. It allows users to view and change the configuration of network interfaces, such as IP addresses, netmasks, and MAC addresses. The ip command is a more modern alternative that provides similar functionality with additional features and is recommended for use in newer systems.

Basic Syntax:

ifconfig:

bash
ifconfig [interface] [options]
  • interface: The name of the network interface (e.g., eth0, wlan0).

ip:

bash
ip [options] [command] [parameters]
Example:
  1. Using ifconfig:

    To display the current network configuration:

    bash
    ifconfig

    To set an IP address on a specific interface:

    bash
    sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
  2. Using ip:

    To display the current network configuration:

    bash
    ip addr show

    To set an IP address on a specific interface:

    bash
    sudo ip addr add 192.168.1.10/24 dev eth0
Key Features:
  • View Configuration: Both commands allow you to view the current configuration of network interfaces, including IP addresses, netmasks, and hardware addresses (MAC).

  • Modify Configuration: You can modify interface parameters, such as changing the IP address or enabling/disabling an interface.

  • Multi-Protocol Support: The ip command supports both IPv4 and IPv6, making it more versatile for modern networking needs.

Summary:
  • The ifconfig and ip commands are used to configure network interface parameters in Linux.

  • While ifconfig is part of the older net-tools package, ip is part of the modern iproute2 package and is generally preferred for managing network configurations today.

  • Both commands provide essential functionality for network management.

27. tar - Tape archiving utility

The tar command in Linux is used for creating and manipulating archive files. It is commonly used to compress multiple files and directories into a single file, making it easier to store, share, or transfer them.

Basic Syntax:
bash
tar [options] [archive-file] [file-or-directory-to-archive]
Example:

Create an Archive: To create a tar archive named archive.tar from the directory myfolder:

bash
tar -cvf archive.tar myfolder
  • c: Create a new archive.

  • v: Verbose mode (show progress in the terminal).

  • f: Specify the archive filename.

Extract an Archive: To extract the contents of archive.tar:

bash
tar -xvf archive.tar
  • x: Extract files from an archive.

Create a Compressed Archive: To create a compressed tar.gz archive named archive.tar.gz:

bash
tar -czvf archive.tar.gz myfolder
  • z: Compress the archive using gzip.

Extract a Compressed Archive: To extract a tar.gz archive:

bash
tar -xzvf archive.tar.gz

List Contents of an Archive: To list the contents of archive.tar without extracting:

bash
tar -tvf archive.tar
Key Features:
  • Compression: The tar command can create compressed archives using gzip or bzip2, reducing file size.

  • Archiving: It can archive multiple files and directories into a single file, which simplifies file management and distribution.

  • Preservation of Metadata: When creating archives, tar preserves file permissions, timestamps, and directory structure.

Summary:
  • The tar command is a versatile tool in Linux for creating, extracting, and managing archive files.

  • It is widely used for backups, file compression, and distribution of multiple files and directories.

  • With support for compression and preservation of file attributes, tar is essential for effective file management in Linux environments.

28. gzip - Compress or expand files

The gzip command in Linux is used to compress or expand files, reducing their size for storage or transmission. It is commonly used to compress single files, and it creates files with the .gz extension.

Basic Syntax:
bash
gzip [options] [file]
Example:

Compress a File: To compress a file named example.txt:

bash
gzip example.txt

This will create example.txt.gz and remove the original file.

Decompress a File: To decompress a file named example.txt.gz:

bash
gzip -d example.txt.gz

Alternatively, you can use:

bash
gunzip example.txt.gz

Compress Multiple Files: To compress multiple files at once:

bash
gzip file1.txt file2.txt

This will create file1.txt.gz and file2.txt.gz, removing the original files.

Keep Original Files: To compress a file while keeping the original:

bash
gzip -k example.txt

View Compression Info: To display information about a compressed file:

bash
gzip -l example.txt.gz
Key Features:
  • High Compression Ratio: gzip uses the DEFLATE algorithm, providing effective compression for text and other types of files.

  • Stream Processing: It can compress data streams directly from input/output, making it suitable for use in pipelines.

Summary:
  • The gzip command is a powerful utility in Linux for compressing and decompressing files, which helps save disk space and speed up file transfers.

  • It is widely used due to its efficiency and ease of use.

  • With features for managing multiple files and maintaining original files, gzip is an essential tool for effective file management in Linux environments.

29. unzip - List, test and extract compressed files in a ZIP archive

The unzip command in Linux is used to extract files from ZIP archives. It can also list the contents of a ZIP file and test the integrity of the compressed files.

Basic Syntax:
bash
unzip [options] [zipfile.zip]
Example:

Extract a ZIP File: To extract all files from archive.zip:

bash
unzip archive.zip

List Contents of a ZIP File: To list the contents without extracting:

bash
unzip -l archive.zip

Extract to a Specific Directory: To extract files to a specified directory:

bash
unzip archive.zip -d /path/to/directory

Test ZIP File Integrity: To test the integrity of the files in archive.zip:

bash
unzip -t archive.zip
Key Features:
  • Partial Extraction: You can extract specific files from a ZIP archive.

  • Directory Structure: Maintains the original directory structure when extracting files.

  • File Integrity Testing: Tests the integrity of the compressed files before extraction.

Summary:
  • The unzip command is a versatile tool for managing ZIP archives in Linux.

  • It allows users to extract, list, and test files within ZIP files easily.

  • With its support for maintaining directory structures and verifying file integrity, unzip is essential for handling compressed files effectively.

30. find - Search for files in a directory hierarchy

The find command in Linux is used to search for files and directories within a directory hierarchy based on various criteria like name, size, modification time, etc.

Basic Syntax:
bash
find [path] [options] [expression]
Example:

Find Files by Name: To find all files named example.txt in the current directory and subdirectories:

bash
find . -name example.txt

Find Files by Type: To find all directories in /home:

bash
find /home -type d

Find Files by Size: To find files larger than 10MB:

bash
find . -size +10M

Find and Execute a Command: To find and delete all .log files:

bash
find . -name "*.log" -exec rm {} \;
Key Features:
  • Search by name, type, size, modification date, etc.

  • Execute actions (e.g., delete, move, or modify files) on matching files.

  • Recursive search through directory hierarchies.

Summary:
  • The find command is a powerful tool for locating files and directories based on various attributes in Linux.

  • Its versatility allows for complex searches and the ability to perform operations on the found files, making it essential for file management tasks.

31. df - Report file system disk space usage

The df command in Linux displays the amount of disk space used and available on file systems.

Basic Syntax:
bash
df [options]
Example:

Display Disk Usage: To display disk space usage for all file systems:

bash
df

Human-Readable Format: To display disk usage in a human-readable format (e.g., MB, GB):

bash
df -h

Display Specific File System: To check the space on a specific file system or partition:

bash
df /dev/sda1
Key Features:
  • Human-readable output (-h option for easier understanding).

  • Shows total, used, and available space on all mounted file systems.

  • Works with specific file systems, partitions, or directories.

Summary:
  • Reports disk space usage.

  • Provides human-readable options.

  • Works on specific file systems or partitions.

  • Useful for system monitoring and management.

32. du - Estimate file space usage

The du command in Linux displays the disk usage of files and directories.

Basic Syntax:
bash
du [options] [path]
Example:

Display Disk Usage for a Directory: To display disk usage for the current directory and its subdirectories:

bash
du

Human-Readable Format: To show disk usage in a human-readable format (e.g., KB, MB):

bash
du -h

Summarize Total Disk Usage: To display only the total disk usage for a directory:

bash
du -sh /path/to/directory

Show Disk Usage for Files: To include individual file sizes along with directories:

bash
du -a
Key Features:
  • Estimates disk usage recursively for directories and subdirectories.

  • Human-readable option (-h) to show sizes in KB, MB, GB.

  • Summarizes total usage for specified directories.

  • Supports showing individual file sizes (-a option).

Summary:
  • Estimates file and directory space usage.

  • Displays human-readable sizes with -h.

  • Summarizes disk usage for directories.

  • Useful for tracking storage consumption.

33. free - Display amount of free and used memory in the system

The free command in Linux shows the total, used, and available memory (RAM) and swap space in the system.

Basic Syntax:
bash
free [options]
Example:

Display Memory Usage: To show memory and swap usage:

bash
free

Human-Readable Format: To display memory in a human-readable format (e.g., MB, GB):

bash
free -h

Display in Megabytes: To show memory in megabytes:

bash
free -m

Show Memory in Gigabytes:

bash
free -g
Key Features:
  • Displays total, used, free, and available memory.

  • Human-readable output (-h option for easier understanding).

  • Shows detailed memory statistics including RAM and swap space.

Summary:
  • Displays system memory usage.

  • Supports human-readable output with -h.

  • Shows statistics for both RAM and swap.

  • Useful for monitoring system performance and memory consumption.

34. history - Command History

The history command in Linux displays the list of previously executed commands in the terminal.

Basic Syntax:
bash
history [options] [number]
Example:

Display Command History: To display all previously executed commands:

bash
history

Run a Specific Command from History: To rerun the 15th command from history:

bash
!15

Clear Command History: To clear the history list:

bash
history -c
Key Features:
  • Displays previously executed commands with corresponding line numbers.

  • Rerun commands from history using !n, where n is the command number.

  • Clear history with -c option.

Summary:
  • Lists past terminal commands.

  • Supports rerunning commands from history.

  • Can clear command history for privacy.

  • Useful for recalling or reusing commands.

35. passwd - Change user password

The passwd command in Linux is used to change a user's password.

Basic Syntax:
bash
passwd [options] [username]
Example:

Change Current User Password: To change the password for the current user:

bash
passwd

Change Password for Another User (requires superuser privileges): To change the password for a specific user (e.g., john):

bash
sudo passwd john
Key Features:
  • Prompts for the new password and confirmation for security.

  • Can be used by users to change their own passwords or by administrators to change others' passwords.

  • Optionally supports password aging policies.

Summary:
  • Used to change user passwords.

  • Can operate on the current user or specify another user.

  • Requires confirmation of the new password for security.

  • Essential for maintaining user account security.

36. uname - Print system information

The uname command in Linux is used to display basic information about the system's kernel and operating system.

Basic Syntax:
bash
uname [options]
Example:

Display Basic System Information: To print the system's kernel name:

bash
uname

Display All System Information: To print detailed system information (kernel name, version, machine, etc.):

bash
uname -a
Key Features:
  • Displays kernel and OS details such as kernel name, version, machine hardware name, and more.

  • Options for specific information like -r for kernel version, -n for network node hostname.

Summary:
  • Prints kernel and system details.

  • Use -a for comprehensive system information.

  • Helpful for system diagnostics and identification.

37. date - Display or set the system date and time

The date command in Linux is used to display the current date and time or to set the system date and time.

Basic Syntax:
bash
date [options] [+format]
Example:

Display Current Date and Time: To display the current date and time:

bash
date

Display Date in a Specific Format: To display the date in a custom format (e.g., YYYY-MM-DD):

bash
date +"%Y-%m-%d"

Set the System Date and Time (requires superuser privileges): To set the date and time to a specific value:

bash
sudo date -s "2024-09-30 12:00:00"
Key Features:
  • Custom formatting for displaying date and time using format specifiers.

  • Set the system date and time with the appropriate permissions.

  • Supports time zones and can display in UTC with -u.

Summary:
  • Displays or sets the system date and time.

  • Supports custom formatting options.

  • Useful for time management and system configuration.

38. whoami - Print effective user id

The whoami command in Linux is used to display the username of the current user who is executing the command.

Basic Syntax:
bash
whoami
Example:

Display Current User: To print the username of the currently logged-in user:

bash
whoami
Key Features:
  • Quickly identifies the current user executing the command.

  • Useful in scripts to determine the effective user context.

Summary:
  • Prints the effective username of the current user.

  • Simple and straightforward to use.

  • Helpful for verifying user identity in multi-user environments.

39. which - Locate a command

The which command in Linux is used to identify the location of executable files associated with a specified command.

Basic Syntax:
bash
which [options] command
Example:

Locate the Command: To find the path of the ls command:

bash
which ls
Key Features:
  • Shows the full path of the executable that will be run when a command is typed.

  • Can be used to verify which version of a command will be executed, especially in environments with multiple versions installed.

Summary:
  • Locates the executable file associated with a command.

  • Provides the path for clarity on which version is being used.

  • Useful for debugging and environment management.

40. alias - Create an alias for a command

The alias command in Linux is used to create shortcuts or custom names for commands, making it easier to execute long or complex commands.

Basic Syntax:
bash
alias name='command'
Example:

Create an Alias: To create an alias named ll for the ls -l command:

bash
alias ll='ls -l'

List All Aliases: To display all currently defined aliases:

bash
alias
Key Features:
  • Simplifies command execution by allowing users to create shorter or more memorable names for longer commands.

  • Aliases are typically defined in the shell configuration files (like .bashrc or .bash_profile) to persist across sessions.

Summary:
  • Creates shortcuts for commands to enhance productivity.

  • Improves efficiency by reducing the need to type lengthy commands.

  • Custom aliases can be defined per user and persist in the shell environment.

41. echo - Display a line of text

The echo command in Linux is used to display a line of text or a variable value in the terminal.

Basic Syntax:
bash
echo [options] [string]
Example:

Display Simple Text: To display a line of text:

bash
echo "Hello, World!"

Display Environment Variable: To display the value of an environment variable (e.g., HOME):

bash
echo $HOME
Key Features:
  • Outputs text to the terminal and can include special characters.

  • Supports options like -n (omit the trailing newline) and -e (enable interpretation of backslash escapes).

Summary:
  • Used to print text or variable values to the terminal.

  • Simple and versatile for scripting and command-line usage.

  • Supports various options for formatting output.

42. tail - Display the end of a file

The tail command in Linux is used to display the last part of files, typically to view the most recent entries in logs.

Basic Syntax:
bash
tail [options] [file]
Example:

Display Last 10 Lines of a File: To display the last 10 lines of a file named example.txt:

bash
tail example.txt

Display Last N Lines: To display the last 20 lines of a file:

bash
tail -n 20 example.txt

Follow a File: To continuously monitor a file (e.g., log file) for new entries:

bash
tail -f example.log
Key Features:
  • Displays the last part of a file, useful for checking log files.

  • Options allow customization, such as specifying the number of lines or following file changes in real time.

Summary:
  • Displays the end of files, particularly useful for logs and output monitoring.

  • Provides options for tailored output, including real-time updates.

  • A simple yet powerful tool for file inspection and monitoring.

43. head - Display the beginning of a file

The head command in Linux is used to display the first part of files, allowing users to quickly view the initial lines of text files.

Basic Syntax:
bash
head [options] [file]
Example:

Display the First 10 Lines of a File: To display the first 10 lines of a file named example.txt:

bash
head example.txt

Display the First N Lines: To display the first 15 lines of a file:

bash
head -n 15 example.txt
Key Features:
  • Displays the beginning of a file, useful for quickly checking file contents.

  • Options allow customization, such as specifying the number of lines to display.

Summary:
  • Displays the start of files, particularly useful for reviewing configuration files or data.

  • Provides options for tailored output, including specifying the number of lines.

  • A straightforward tool for quick content inspection.

44. diff - Compare files line by line

The diff command in Linux is used to compare the contents of two files line by line, highlighting the differences between them.

Basic Syntax:
bash
diff [options] file1 file2
Example:

Compare Two Files: To compare two text files named file1.txt and file2.txt:

bash
diff file1.txt file2.txt
Key Features:
  • Outputs differences in a human-readable format, indicating which lines need to be added or removed.

  • Supports various options for context and unified output formats, making it easier to read differences.

Summary:
  • Compares the contents of two files line by line, useful for identifying changes.

  • Provides a detailed output of differences, aiding in file management and version control.

  • A fundamental tool for developers and system administrators to track changes in files.

45. wc - Print newline, word, and byte counts for each file

The wc (word count) command in Linux is used to count the number of newlines, words, and bytes in files.

Basic Syntax:
bash
wc [options] [file]
Example:

Count Lines, Words, and Bytes: To count the lines, words, and bytes in a file named example.txt:

bash
wc example.txt

Count Only Lines: To count only the number of lines:

bash
wc -l example.txt

Count Only Words: Count Only Words:

bash
wc -w example.txt
Key Features:
  • Counts different metrics: Lines (-l), words (-w), characters or bytes (-c), and more.

  • Can process multiple files at once and provide cumulative counts.

Summary:
  • Provides statistics on the number of lines, words, and bytes in files.

  • Useful for file analysis and data processing.

  • A simple yet effective tool for text file management and evaluation.

46. sort - Sort lines of text files

The sort command in Linux is used to sort the lines of text files alphabetically or numerically.

Basic Syntax:
bash
sort [options] [file]
Example:

Sort a File Alphabetically: To sort the lines of a file named example.txt alphabetically:

bash
sort example.txt

Sort in Reverse Order: To sort the lines in reverse alphabetical order:

bash
sort -r example.txt

Sort Numerically: To sort the lines numerically (useful for sorting numbers):

bash
sort -n numbers.txt
Key Features:
  • Supports various sorting options: Reverse order (-r), numeric sort (-n), and more.

  • Can sort based on specific fields or columns with additional options.

Summary:
  • Sorts lines of text files in a specified order, enhancing file organization.

  • Provides various options for customized sorting based on requirements.

  • A fundamental tool for text processing and data management in Linux.

47. uniq - Report or omit repeated lines

The uniq command in Linux is used to filter out repeated lines in a file or input, allowing users to report unique lines.

Basic Syntax:
bash
uniq [options] [input_file] [output_file]
Example:

Remove Duplicate Lines: To remove adjacent duplicate lines from a file named example.txt and display the unique lines:

bash
uniq example.txt

Count Occurrences of Each Line: To count how many times each line appears:

bash
uniq -c example.txt
Key Features:
  • Removes consecutive duplicate lines: Only works with adjacent lines, so it's often used in conjunction with sort.

  • Can report the number of occurrences of each line with the -c option.

Summary:
  • Filters and displays unique lines from input, useful for data processing.

  • Often used alongside the sort command to prepare input for uniq.

  • A simple yet powerful tool for managing and analyzing text data.

48. sed - Stream editor for filtering and transforming text

The sed (stream editor) command in Linux is used for parsing and transforming text in a pipeline, allowing users to perform basic text transformations on an input stream (file or input from a pipeline).

Basic Syntax:
bash
sed [options] 'command' [file]
Example:

Replace Text: To replace the first occurrence of "old" with "new" in a file named example.txt:

bash
sed 's/old/new/' example.txt

Delete Lines: To delete the second line of a file:

bash
sed '2d' example.txt
Key Features:
  • Text Replacement: Use the s command for substitution to modify text.

  • Line Deletion: Easily delete specific lines using line numbers.

  • Supports Regular Expressions: Can perform complex text manipulations with regex.

Summary:
  • A powerful tool for editing text streams, commonly used in shell scripting and text processing.

  • Allows for both simple substitutions and complex text manipulations.

  • Essential for automation tasks that involve text processing in Linux environments.

49. awk - Pattern scanning and processing language

The awk command in Linux is a versatile programming language designed for pattern scanning and processing. It is used primarily for processing text files and data streams.

Basic Syntax:
bash
awk 'pattern { action }' [file]
Example:

Print Specific Columns: To print the first and third columns of a file named data.txt:

bash
awk '{ print $1, $3 }' data.txt

Calculate the Sum of a Column: To sum the values in the second column:

bash
awk '{ sum += $2 } END { print sum }' data.txt
Key Features:
  • Field Separation: Automatically splits each line into fields based on whitespace or a specified delimiter.

  • Built-in Functions: Supports various functions for string manipulation, mathematical operations, and more.

  • Pattern Matching: Can perform actions based on specified patterns using regular expressions.

Summary:
  • awk is a powerful text-processing tool ideal for extracting and manipulating data from structured text files.

  • Commonly used in data reporting and processing tasks, especially for CSV and tab-delimited files.

  • Essential for scripting and automating data analysis in Linux environments.

50. cut - Remove sections from each line of files

The cut command in Linux is used to extract sections from each line of input files or standard input, making it useful for processing structured data.

Basic Syntax:
bash
cut [options] [file]
Example:

Extract Specific Fields: To extract the second and fourth fields from a comma-separated file named data.csv:

bash
cut -d',' -f2,4 data.csv

Extract Character Range: To extract the first 5 characters from each line of a file named text.txt:

bash
cut -c1-5 text.txt
Key Features:
  • Field Delimiter: Use the -d option to specify a delimiter (e.g., comma, tab) to separate fields.

  • Field Selection: Use the -f option to select specific fields.

  • Character Selection: Use the -c option to select specific character positions.

Summary:
  • cut is a simple yet effective tool for extracting parts of lines in text files.

  • Commonly used for processing CSV and tab-delimited files, as well as extracting substrings.

  • Valuable for text manipulation tasks in shell scripting and data processing in Linux environments.

Conclusion

Mastering the top 50 Linux commands can greatly enhance your productivity and efficiency, whether you're handling basic system operations, file management, or text editing tasks. By integrating these commands into your daily workflow, you can streamline your processes and make the most out of the Linux environment.

If you have any questions or encounter issues related to Linux systems or server management, don't hesitate to contact iDatam for expert support and solutions.

Discover iDatam Dedicated Server Locations

iDatam servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.

Up