The Wayback Machine - https://web.archive.org/web/20240930224301/https://www.geeksforgeeks.org/daily-life-linux-commands/
Open In App

Daily life Linux Commands

Last Updated : 13 Sep, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
  1. Clear the Terminal : In our daily life, we use to work on Terminal if we are using LINUX. Continuous working on terminal makes the terminal screen full of commands and for removing them and making our screen totally free of character, we often use clear command. Key combination ‘Ctrl+l‘ has the same effect as ‘clear‘ command. So from next time use ctrl+l to clear your Linux Command Line Interface.
    Note: Since ctrl+l is a key combination, so we can not use it inside a script. If we need to clear screen inside a shell script, we just have to call command ‘clear’.
  2. Run command and get back to the directory, together:  This is also an amazing hack not known to many people. We may run command no matter what it is and then return back to the current directory. For this, all we need to do is to run the command in parentheses i.e., in between ( and ).
    For Example :
    Input :

    cd /home/shivam/Downloads/ && ls -l

    Output :

    -rw-r----- 1 shivam shivam    54272 May 3 18:37 text1.txt
    -rw-r----- 1 shivam shivam    54272 May 3 18:37 text2.txt
    -rw-r----- 1 shivam shivam    54272 May 3 18:37 text3.txt
    

    Explanation : In the above command it first changed the current directory to Downloads and then list the content of that directory before returning back to the current directory.

  3. Shortcut to Directories: You can create a shortcut to frequently accessed directories by adding them to the CDPATH environment variable. So, say If you frequently access “/var/www/html/”.
    Instead of typing “cd /var/www/html”, you can add /var/www/ to CDPATH and then you have to type “cd html” only.

    shivam:~> export CDPATH=$CDPATH:/var/www/
    shivam:~> cd html
    shivam:~:html>
    
  4. Replacing words or characters:
    • If you are working with any text file then to replace every instance of any word say “version” with “story” in myfile.txt, you can use sed command as:
      # sed 's/version/story/g' myfile.txt
      
    •  Additionally, if you want to ignore character case then you may use gi instead of g as:
      # sed 's/version/story/gi' myfile.txt
      
  5. Here are some useful shortcuts which you may use while working on terminal:
    Cursor Movement Control:

    • Ctrl-a: Move cursor to the start of a line
    • Ctrl-e: Move cursor to the end of a line
    • Ctrl-Left/Right: Navigate word by word (may not work in all terminals)Modify Text:
    • Ctrl-w: Delete the whole word to the left of the cursor
    • Ctrl-k: Erase to end of line
    • Ctrl-u: Erase to beginning of line
  6. Run top in batch mode: ‘top’ is a handy utility for monitoring the utilization of your system. It is invoked from the command line and it works by displaying lots of useful information, including CPU and memory usage, the number of running processes, load, the top resource hitters, and other useful bits. By default, top refreshes its report every 3 seconds.
    Mostly we run ‘top’ inside the terminal, look on the statistics for a few seconds and then graciously quit and continue our work.
    Better yet, if we wants to run such a utility only for a given period of time, without any user interaction:
    There are many possible answers:

    • You could schedule a job via cron.
    • You could run a shell script that runs ps every X seconds

    Instead of going wild about trying to patch a script, there’s a much, much simpler solution:

    top -b -d 10 -n 3 >> top-file
    

    We have top running in batch mode (-b). It’s going to refresh every 10 seconds, as specified by the delay (-d) flag, for a total count of 3 iterations (-n). The output will be sent to a file.Here is a screenshots of outut:
    linux 62

  7. Duplicate pipe content: ‘tee’ is a very useful utility that duplicates pipe content. Now, what makes tee really useful is that it can append data to existing files, making it ideal for writing periodic log information to multiple files at once.
    ps | tee file1 file2 file3
    

    We’re sending the output of the ps command to three different files! Or as many as we want. As you can see in the screenshots below, all three files were created at the same time and they all contain the same data.

  8. export: The ‘export’ command is one of the bash shell BUILTINS commands.It has three available command options. In general, it marks an environment variable to be exported with any newly forked child processes and thus it allows a child process to inherit all marked variables.
    Frequently Used Options with ‘export’

    • -p : List of all names that are exported in the current shell
    • -n: Remove names from export list
    • -f : Names are exported as functions

    Example :

    • command without ‘export’:
      $ a = geeksforgeeks.org
      $ echo $a
      geeksforgeeks.org
      $ bash
      $ echo $a
      

      From the above we can see that any new child process forked from a parent process by default does not inherit parent’s variables. This is where the export command comes handy.

      $ a = geeksforgeeks.org
      $ echo $a
      geeksforgeeks.org
      $ export a
      $ bash
      $ echo $a
      geeksforgeeks.org
      $

      On line 3, we now have used the export command to make the variable “a” to be exported when a new child process is created. As a result the variable “a” still contains the string “geeksforgeeks.org” even after a new bash shell was created.

  9. basename – Strips directory and suffix from filenames. basename prints NAME with any leading directory components removed. If Suffix is specified, it will also remove a trailing SUFFIX. For example: To get the name of the file present in test folder
    $ basename test/gfg.txt
    gfg.txt
  10. grep: grep searches files for a given character string or pattern and can replace the string with another. This is one method of searching for files within Linux.
    grep [option(s)] pattern [file(s)]
      • Search number of files: grep can search any number of files simultaneously. Thus, for example, the following would search the three files file1, file2 and file3 for any line that contains the string GfG
        grep GfG file1 file2 file3
      • Search text in all files: To search all text files in the current directory (i.e., the directory in which the user is currently working), if there is a phrase “Linux is”
         grep 'Linux is' *

    There are lot of more options which can be tried using grep command.



Similar Reads

Useful CMD Commands for Daily Use in Windows OS
The Windows Command Prompt (CMD) is a powerful tool that many users overlook, but knowing a few useful CMD commands for Windows can make your daily tasks much more efficient. From navigating the file system to managing network settings, these daily use CMD commands can help streamline your workflow and solve common problems quickly. In this article
3 min read
Basic Linux Commands for day to day life
This article will explore the basic Linux commands and how to use them. 1. ls: How would we know what a folder contains? With a graphical interface, you'd do this by opening a folder and inspecting its contents. From the command line, you use the command ls instead to list a folder's contents. By default, ls will use a very compact output format. M
7 min read
Basic CentOS Linux Commands in linux
CentOS is a free and open-source operating system that aims to provide a stable reliable, and community-supported platform for servers and other enterprise applications. In this article, we will be covering CentOS Linux basics commands and functions of CentOS and also we will look into the advanced commands. These CentOS commands allow you to manag
3 min read
Internal and External Commands in Linux
The UNIX system is command-based i.e things happen because of the commands that you key in. All UNIX commands are seldom more than four characters long. They are grouped into two categories: Internal Commands : Commands which are built into the shell. For all the shell built-in commands, execution of the same is fast in the sense that the shell doe
4 min read
Useful and time saving bash commands in Linux
There are many useful bash scripts that can make things easier. Many things can be done just using the terminal. Here is a list of some of such useful bash scripts through which we can do things that cannot be done manually. 1. Counting the number of files(or directory) in a given directory: Go to the directory in which you want to count the number
3 min read
Process Control Commands in Unix/Linux
Process control commands in Unix are: bg - put suspended process into background fg - bring process into foreground jobs - list processes bg Command : bg is a process control command that resumes suspended process while keeping them running in the background. User can run a job in the background by adding a "&" symbol at the end of the command.
3 min read
Custom commands for linux terminal
Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux, the first step is to create a bash script for the command. The second step is to make the command executable. Syntax : $ nano ~/.bashrc Here, bashrc means run the Bash file. Bash is located at /bin/bash . This file helps in c
2 min read
Fun Commands in Linux
cowsay First we install it using sudo apt-get install cowsay. We use other objects to use -l to list them and -f to use them. xcowsay First, we install it using sudo apt-get install xcowsay. Then here is the way to use it. THE MATRIX Use below command to install it sudo apt-get install cmatrix Once installed, use below command to print. cmatrix To
1 min read
Basic Shell Commands in Linux
A shell is a special user program that provides an interface to the user to use operating system services. Shell accepts human-readable commands from the user and converts them into something which the kernel can understand. It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shel
3 min read
Python | Execute and parse Linux commands
Prerequisite: Introduction to Linux Shell and Shell Scripting Linux is one of the most popular operating systems and is a common choice for developers. It is popular because it is open source, it's free and customizable, it is very robust and adaptable. An operating system mainly consists of two parts: The kernel and the Shell. The kernel basically
6 min read
How to run Linux Commands on Windows 10?
It is a dilemma when you want to switch from one operating system to another. This is a common case when you switch from Windows to Linux. Either you store your data and then uninstall Windows to install Linux and then transfer your data or you can have a dual boot system where you encounter an option as to which OS to choose in the beginning. Don'
2 min read
Interesting Funny Commands in Linux
This entire article is all about showing off cool commands executable in the Linux terminal. This article is aimed at being a one-stop destination for all cool or you can say interesting funny commands in Linux to play. 1. The Matrix Effect: We all can agree on one thing that the falling down text effect from "The Matrix" movie is one of the best s
5 min read
Deprecated Linux Networking Commands and Their Replacements
In this article, let us have a close look at some networking commands that are deprecated. That means they are not provided by default and replaced by other commands that serve the same purpose. But please note that these commands can still be executed by first downloading the net-tools package onto the machine. sudo apt-get install net-toolsThese
4 min read
Linux vs Windows Commands
Most of us think that Linux has terminal and we can use a command-line interface only in Linux but it is just a myth. There is a PowerShell and a command prompt in windows as well where we may execute the commands easily. But Windows and Linux have commands with the same name as well. .linux-vs-windows-table { border-collapse: collapse; width: 100%
2 min read
How to Build Your Own Commands in Linux?
Linux is one of the most widely used open-source operating systems which supports both GUI as well as CLI. It has been widely used all over the world since its first distribution launched on September 17, 1991, by Linus Torvalds. It is widely known for its command-line operations. We have been using several commands in Linux like date command, mkdi
6 min read
List out all the Shells Using Linux Commands
There are various methods to list all the shells which are installed in our Linux system. A Shell is a software program that acts as an interface between the user and the operating system(OS). It can also be thought of as a command interpreter that is used to execute another program. Method 1: Using cat command Example: cat /etc/shells Explanation:
1 min read
Most Useful Commands to Manage Apache Web Server in Linux
Prerequisite: How do Web Servers work? Apache is one of the most widely used free, open-source Web Server applications in the world, mostly used in Unix-like operating systems but can also be used in windows. As a developer or system administrator, it will be very helpful for you to know about the Apache webserver. It has many notable features amon
3 min read
Viewing Progress of Commands Using Pipe Viewer Tool in Linux
Pipe Viewer (pv) is the CLI tool that allows users to track the progress of the process and display them on the terminal by giving information such as total data transferred, the time elapsed, completed percentage, etc. To visualize the process progress it can be used normally via pipe operator b/w processes. Why do we require it? Some processes ha
3 min read
How to Monitor Linux Commands Executed by System Users in Real-time?
If you are a Linux system administrator then you would definitely want to monitor the interactive activity of all system users, like monitoring the Linux commands they execute in real-time. In this brief Linux system security article, we will be going to discuss how to monitor all Linux shell commands executed by system users in real-time. Let's se
1 min read
Ways to Re-run Last Executed Commands in Linux
It would be quite efficient to re-execute the last command. If the command was quite big to type in again, this would be quite a great trick to improve efficiency. So let us see what the commands are to run the last executed command again in the Linux terminal. The ways to run the last executed command are as follows: Ctrl + PUp Arrow key.bang-bang
3 min read
How to Use Linux Commands in Windows with Cygwin
Cygwin is a collection of tools that provide a Linux Operating System's terminal look, feel, and some of its basic functionality for users of Windows OS who want to have a go over the basic commands of Linux without worrying about installing a Linux OS. To use this tool, first of all, we need to download Cygwin setup depending on the version of Win
3 min read
7 Linux Commands For Managing Users
Linux is a fantastic platform that allows multi-user access options. Different users can access the same Linux OS for working simultaneously. A user account allows multiple people to access directories, terminals, the Internet, etc. There are three types of user accounts: User Account: This account is for general use with limited permissions.System
3 min read
Useful Commands For Filtering Text for Effective File Operations in Linux
In this article, let us learn about different commands used in Linux for filtering text to implement effective file operations on Linux Machines. What is a filter in Linux? In Linux Operating System, Filters act as a specialized program to get desired output from the client/user by taking the help of other files and pipes to perform a series of ope
7 min read
How to execute commands remotely using SSH in Linux?
Many times users need to work in remote systems. For which they have to log in to the remote server, execute certain commands and come out of that session. Is it possible to perform all these actions locally? Yes, it's possible using ssh client. In this article, we will see different ways of running remote commands locally using ssh. Pre-requisite
2 min read
How to Run Multiple Commands on Multiple Linux Servers
In this article, we'll learn how to run multiple commands on multiple Linux servers. It was a manual task completed by System Administrators. Let's say, they made some changes to a server and if they need to make the same changes to many servers they would need to log into each server and repeatedly make changes to each of them. But we can run mult
3 min read
List All Available Commands and Aliases in Linux
There might be sometimes a need to list all the commands and aliases supported by the current system. As we already know, an alias is a custom shortcut that references a command. It can be very useful to replace long commands with a small alternative command. While a command is a program that we can run in the terminal to produce some output or cha
3 min read
The “Argument List Too Long” Error in Linux Commands
There are times when we encounter directories that contain a large number of files, if we try to perform certain operations on those particular directories we may get the error Argument List Too Long. In this article, we will see the cause of this error and how to resolve this error. We have created a directory(temp) with a large number of files (
4 min read
YUM Commands for Linux Package Management
If you are a Linux user or system administrator, chances are you've come across YUM (Yellowdog Updater, Modified) at some point in your journey. YUM is a powerful package management tool that simplifies the process of installing, updating, and managing software on Red Hat-based Linux distributions like CentOS and Fedora. In this article, we will de
4 min read
Executing Linux Commands Without Storing Them in History
In Linux, a lot of work is done via the command line or terminal. However, sometimes we might run a command that might contain some sensitive information or we just do not want to clutter our history file with unnecessary commands. In such cases, we want to execute Linux commands without keeping them in memory. There are multiple ways to achieve th
6 min read
10 Useful firewall-cmd Commands in Linux
"Firewall-cmd" is a command-line tool used to manage firewalld, a dynamic firewall management tool found in many Linux distributions, such as Fedora, Red Hat, and CentOS. When it comes to managing firewall rules, Firewalld is more user-friendly and dynamic than the previous IPtables system. Administrators can configure the firewall by adding or rem
7 min read