25 Awesome Linux Command One-Liners | by Kesk -*- | Feb, 2022

Save time in your day-to-day work and have enjoyable with it

I like working with the Linux shell. The shell enables you to get issues completed in seconds, and no want to make use of any graphical setting.
On this publish, I compile 25 command one-liners that I discover particularly helpful or humorous. I hope you want them!

1. Question Wikipedia through console

#dig +brief txt <key phrase>.wp.dg.cx
#For instance:
$dig +brief txt usa.wp.dg.cx"a. English is the official language of at the least 28 states226128148some sources give larger figures, based mostly on differing definitions of "official". English and Hawaiian are each official languages within the state of Hawaii. http://en.wikipedia.org/wiki/United_States"

2. Set a console clock into the fitting nook

Copy and paste the next sentence in a single line in your console:

$whereas sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;completed &

Binary clock:

$watch -n 1 'echo "obase=2;`date +%s`" | bc'

3. Mount a brief RAM partition

You should use it as a use and throw partition. Nevertheless, the partition and all the info can be gone when you reboot the system.

For instance, it can be utilized by packages or duties that require many studying/writing operations to enhance their efficiency.

$mount -t tmpfs tmpfs /mnt -o measurement=2048m

The above command will create a brief partition measurement 2048MB in tmpfs and mount it underneath the /mnt listing.

4. Checklist numerical values for every of the 256 colours in bash

$for code in 0..255; do echo -e "e[38;05;$codem $code: Check"; completed

5. Run the final command as root

$sudo !!

6. Kill course of by identify

$pkill -x chrome

7. Create an entire compress picture of a disk

To create a picture of a disk in your pc, you don’t want any third-party instruments or packages. Doing so is so simple as utilizing the command:

if: origin disk, on this case, sda.

$dd if=/dev/sda | gzip -c  > /path/to/my.disk.picture.gz bs=1M

Be aware: If you wish to clone the system disk, you’ll have to boot your pc with a reside model, for instance, with ubuntu reside USB. Be certain that no partitions are mounted from the supply laborious drive disk

bs: Units the block measurement to 1M.

Restore de system:

$gunzip -c /path/to/my.disk.picture.gz | dd of=/dev/sda

Warning: You need to be very cautious when utilizing the dd command; it may well destroy knowledge. Keep in mind the order of the enter file: <if> and output file: <of>.

8. Run the earlier command and changing


9. Restrict the CPU utilization for a course of

First, it’s a must to knot the pid (Course of identification quantity). For instance, discover out the chrome’s pid:

$pid of chrome
#for instance: 1543

Second, set the share to which you wish to restrict the CPU utilization to the earlier course of, on this case, at 25 p.c.

$sudo cpulimit -p 1543-l 25

10. Seek for an identical command beforehand typed in BASH

$Ctrl-R <search-text>

11. Processes per person counter

$ps hax -o person | type | uniq -c

12. Change one char with one other in all filenames of the present listing

You should use the Perl rename on Debian, Ubuntu, and derivatives (different distributions ship a special program as rename, and that program isn’t useful right here).

File 1
File 2
to File_1
$rename -v 's/ /_/g' *

With The ZSH or Z Shell:

autoload zmv
zmv '(*)' '$1// /_'

13. SSH connection by a bunch within the center

$ssh -t reachable_host ssh unreachable_host

14. Discover all information bigger than 5M and fewer than 10M

Helpful, for instance, to seek for a log file of a particular measurement.

$discover / -type f -size +50M -size -10M

15. Use the <rsync> command with a progress bar to repeat

$rsync -rv <src> <dst> --progress

16. Examine whether or not your pc is 32-bit or 64-bit

$getconf LONG_BIT

17. Simulates typing on the display screen

You’ll be able to simulate typing on the display screen and appear to be a hacker by controlling the pace at which you kind.

$echo "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." | pv -qL 20
  • q: Quiet don’t output any switch data in any respect.
  • L: Price-limit RATE restrict switch to RATE bytes per second.

Be aware: you should have put in the< pv> utility used to watch knowledge progress by a pipe.

$sudo apt set up pv

18. Present working listing of a course of

Be aware: See level 7 to acquire the PID of a course of.

$pwdx pid

19. Set password safety to a file utilizing vim

$vim -x file.txt

20. Take away strains in a file by a variety

$sed -i <file> -re '<begin>,<finish>d'

21. Get my public IP deal with.

$curl ifconfig.me$curl checkip.dyndns.org... or similars.

22. Monitor the progress of a command

$pv a_big_file.txt | gzip > a_big_file.log.gz

Be aware: you should have put in the< pv> utility.

23. Checklist all bash shortcuts

bind -P

24. Monitor reminiscence utilization in a human-readable manner

watch vmstat -sSM

25. A forecast within the shell

curl wttr.in/newyork

Additional: Enter the matrix

$perl -e '$|++; whereas (1)  print " ." x (rand(10) + 1), int(rand(2)) '

I hope you preferred this text. Thanks for taking the time to learn it!

More Posts