How VPS - How to use/setup VPS
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

3 Useful Hacks Every Linux User Must Know

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
64
VIEWS
Share on FacebookShare on Twitter

Contents

  1. 1. How to Schedule a Linux Job Without Cron
  2. 2. How to Clear Terminal without Using ‘clear’ Command
  3. 3. Run a command and come back to the current working directory automatically.
    1. Sample Output
    2. Sample Output

The world of Linux is filled with so much fun and interesting stuffs, the more we go in, the more we find stuffs. In our efforts to bring those little hacks and tips for you that makes you different from others, here we have came up with three little tricks.

1. How to Schedule a Linux Job Without Cron

Scheduling a job/command in Linux is acronym to cron. Whenever we need to schedule a job, we call cron, but do you know we can schedule a job at a later time without corn? You can do it as suggested below..

Run a command (say date) every 5 sec and write the output to a file (say date.txt). To achieve this scenario, we need to run the below one liner script directly on the command prompt.

$ while true; do date >> date.txt ; sleep 5 ; done &

Anatomy of the above one liner script:

  1. while true – Ask script to run while the condition is true, it acts as a loop which makes the command to run again-and-again or say in a loop.
  2. do – do perform what follows, ie., execute command or set of commands that lies ahead of do statement.
  3. date >> date.txt – here the output of date command is being written to a file date.txt. Also note that we have used >> and not >.
  4. >> ensures that the file (date.txt) is not overwritten every time the script execute. It just append the changes. Whereas > overwrite the file again and again.
  5. sleep 5 – It ask the shell to keep a time difference of 5 seconds before it executed again. Note the time here is always measured in seconds. Say if you want to execute the command every 6 minutes, you should use (6*60) 360, in succession of sleep.
  6. done – marks the end of while loop.
  7. & – Put the whole process in loop to background.

Similarly, we can execute any script in the same manner. Here is the command to call a script after certain interval (say 100 sec) and the name of script is script_name.sh.

Also worth mentioning that the script above should be run in the directory where the script to be called lies, else you need to provide full path (/home/$USER/…/script_name.sh). The syntax for calling script at above described interval is:

$ while true; do /bin/sh script_name.sh ; sleep 100 ; done &

Conclusion: The above one liner is not a replacement of Cron, because Cron utility supports a whole lots of options, as compared and is very flexible as well as customizable. However if we want to run certain test cases or I/O benchmark, then the above singe command will serve the purpose.

Read Also: 11 Linux Cron Job Scheduling Examples

2. How to Clear Terminal without Using ‘clear’ Command

What we do to clear the screen? Well you may think how silly it is to ask such question. Well, we all know it’s ‘clear‘ command. However if we make a habit of using key combination ‘ctrl+l‘ to clear terminal, we will save a lot of time of ours.

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.

Conclusion: 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, call command ‘clear’, for all other cases I could think of now, ctrl+l is more than sufficient.

3. Run a command and come back to the current working directory automatically.

Well this is an amazing hack not many people know. You may run a command no matter what it return back to the current directory. All you need to do is to run the command in parentheses i.e., in between ( and ).

Let see the example,

[email protected]:~$ (cd /home/avi/Downloads/)
Sample Output
[email protected]:~

First it cd to directory Downloads and then again return back to home directory in one go. May be you believe that the command didn’t executed and for some reason one or another it is not throwing error, since there is no change in prompt. Lets do a little more tweak..

[email protected]:~$ (cd /home/avi/Downloads/ && ls -l)
Sample Output
-rw-r-----  1 avi  avi     54272 May  3 18:37 text1.txt
-rw-r-----  1 avi  avi     54272 May  3 18:37 text2.txt
-rw-r-----  1 avi  avi     54272 May  3 18:37 text3.txt
[email protected]:~$

So in the above command it first changed the current directory to Downloads and then list the content of that directory before returning back to current directory. Also, it proves that command executed successfully. You may run any sort of command in the parentheses and return back to your current working directory without a hitch.

That’s all for now, if you know any such Linux hacks or tricks you may share with us via our comment section and don’t forget to share this article with your friends….

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
How VPS

How VPS

Related Posts

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Install Apache Tomcat 8 on CentOS 7
Linux

How to Install Apache Tomcat 8 on CentOS 7?

February 11, 2020
Install Arch Linux With Btrfs Snapshotting
Uncategorized

Install Arch Linux With Btrfs Snapshotting

February 13, 2020
Next Post

3 Ways to List All Installed Packages in RHEL, CentOS and Fedora

How To Create a Linux Swap File

20 Linux YUM (Yellowdog Updater, Modified) Commands for Package Management

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

Tips to Create ISO from CD, Watch User Activity and Check Memory Usages of Browser

4 years ago

How to Install MantisBT 2.5 on CentOS 7

3 years ago

How to Setup an Apache Subversion (SVN) Server on CentOS 7

3 years ago

How to Install Gitit on CentOS 7

3 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8 February 25, 2022
  • How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.