Advanced Linux Command Ease your Life

 

  1. Delete large File content immediately: Suppose large file name is access.log then different way to remove large content
    a. # > access.log
    b. # true > access.log
    c. # cat /dev/null > access.log
    d. # cp /dev/null access.log
    e. # dd if=/dev/null of=access.log
    g. # echo -n "" > access.log
    h. # truncate -s 0 access.log
  2. Search top 5 large file size files:
    #find /var/lib/docker/ -type f -exec du -Sh {} + | sort -rh | head -n 5
    # du -a /var/lib/docker/ | sort -rh | head -5
  3. 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
    To Replace a whole line with input start of line parametre
    #sed -i -e '/^#PasswordAuthentication/s/^.*$/PasswordAuthentication yes/' /etc/ssh/sshd_config
    Delete Particular lines
    sed -i -e '259,260 d' settings.php
    Add a sentence after a particular line (For Example add ‘charset’ => ‘utf8mb4’ after 258 line no in setting.php file)
    sed -i -e "258 a 'charset' => 'utf8mb4'," sites/default/setting.php
  4. Install packages with no proxy in UBUNTU LINUX (ByPass Proxy)
    apt-get -o Acquire::http::proxy=false install kgraphviewer
  5. The name nohup stands for “no hangup.” The hangup (HUPsignal, which is normally sent to a process to inform it the user has logged off (or “hung up”), is intercepted by nohup, allowing the process to continue running.
    nohup command [command-argument …]
    Run the command mycommand. It does not receive input. All output, including any error messages, is written to the file nohup.out in the working directory, or in your home directory. If mycommand is running when you log out or close the terminal, mycommand does not terminate.
    To check logs :cat nohup.out
    Example: #nohup rsync -arzvp <soure_file> <Destination_file_path> &
    Above command will excecute in background and Now check the progress with the following command
    #tailf -f  nohup.out
  6. Troubleshooting and Collecting Information for linux:
    dmesg records all the system changes done or occur in real time.
    #dmesg | tail -20
    #dmesg | grep usb or dmesg  | grep eth
    #watch "dmesg | tail -20"  
  7. Enjoy

Comments

Popular posts from this blog

Convert .iso Image to .qcow2 Image

THE ULTIMATE DOCKER CHEAT SHEET

Configuring Shared Folders in VMWare Workstation with a UBUNTU Guest OS and Windows Host