The next one-liner Linux instructions have already been shared in picture templates in our social networks. These instructions are simply single line instructions that makes your command line life simpler and higher. I’ve determined to collect all instructions that we shared in our social community pages, put all of them collectively in a single article and publish it on the finish of each month. Moreover, I’ve included some extra ideas & methods and associated assets to be taught Linux stuffs. A few of the instructions given beneath are collected from Arch wiki, /r/linux, Askubuntu, and Stack Overflow. All credit score goes to the group. And a few are my very own findings from day-to-day expertise. That is the primary half within the sequence. We will likely be publishing the next elements at each month-end.
Some Random One-liner Linux Instructions
These instructions are largely for newbies. All instructions are given in no order. If there are any typos, errors in instructions, let me know within the remark part beneath. I’ll test and replace them ASAP.
1. Open random man pages
Really feel bored at work? Open any random man pages and begin studying it. It’s good for killing your boring time.
$ apropos . | shuf -n 1 | awk ‘print$1’ | xargs man
To know extra about Apropos, test the next hyperlink.
2. Show details about a Linux distribution
To indicate all of the obtainable details about your present distribution, package deal administration and base particulars, run:
$ echo /and so on/*_ver* /and so on/*-rel*; cat /and so on/*_ver* /and so on/*-rel*
Pattern output from Ubuntu 18.04 desktop:
/and so on/debian_version /and so on/lsb-release /and so on/os-release
DISTRIB_DESCRIPTION=”Ubuntu 18.04.three LTS”
VERSION=”18.04.three LTS (Bionic Beaver)”
PRETTY_NAME=”Ubuntu 18.04.three LTS”
three. Get notification when a command is accomplished
To get notified when a command is accomplished, add the next line at finish of the command. It’s good for monitoring instructions that takes very long time to finish.
;notify-send carried out
$ ls -l ;notify-send carried out
four. Discover recordsdata larger than X dimension
To search out recordsdata larger than X dimension, for instance 10 MB, and kind them by dimension, run:
$ discover . -size +10M -type f -print0 | xargs -Zero ls -Ssh | kind -z
We are able to additionally discover recordsdata smaller than X dimension as described within the beneath hyperlink.
5. Run Linux instructions non-interactively
To run Linux instructions non-interactively, use “sure” command like beneath.
$ sure | sudo apt set up vim
It doesn’t require person intervention. To place this merely, you don’t should sort “sure” or “y” to finish the given command. It could be helpful in scripts. It’s additionally harmful. You may by accident do some damages when deleting recordsdata or directories. Be cautious when utilizing “sure” command.
6. Recall Nth command from historical past
We are able to recall “N”th command out of your BASH historical past with out executing it. For instance, the next command will show 12th command from the historical past, nevertheless it received’t execute it.
7. Be taught Unix/Linux file system hierarchy
To study Unix/Linux file system hierarchy, run:
$ man hier
eight. Know what a command will do
When you don’t know what a specific command will do, you should use Explainshell internet service.
Explainshell breaks down the lengthy/complicated instructions and immediately show what every command half will precisely do. That is advisable website to newbies.
9. Find out how to use Terminal if ENTER key isn’t working
To make use of the Terminal on a system the place the ENTER key doesn’t work, use the next keyboard shortcuts:
10. Discover damaged symbolic hyperlinks
To search out all damaged sym hyperlinks in your system, run:
$ discover . -type l ! -exec check -e ; -print
11. Monitoring CPU velocity
To watch CPU velocity in actual time, run:
$ watch grep “cpu MHz” /proc/cpuinfo
Press CTRL+c to cease monitoring.
12. Discover set up date
To discover the precise set up and date of your Linux OS, use the next instructions:
$ head -n1 /var/log/pacman.log
If the logs are already deleted, use the next instructions as root person.
# fs=$(df / | tail -1 | minimize -f1 -d’ ‘) && tune2fs -l $fs | grep created
# tune2fs -l /dev/sda1 | grep ‘Filesystem created:’
On RPM primarily based techniques equivalent to Fedora, RHEL and its clones equivalent to CentOS, Scientific Linux, Oracle Linux:
$ sudo rpm -qi basesystem
$ sudo rpm -qi basesystem | grep Set up
13. Discover most used instructions
To search out most used instructions in your Linux command, run:
$ historical past | awk ‘print $2’ | kind|uniq -c|kind -nr|head -15
This command will show the highest 15 most used instructions.
Extra examples within the beneath hyperlink.
14. Discover final sleep time
Discover when was the final time your system went to sleep:
$ journalctl -u sleep.goal
15. Allow and begin a service
To allow and begin a service, for instance docker, with a single command:
# systemctl allow –now docker
Often, I allow and begin a service like beneath till I got here to know this one-liner.
# systemctl allow docker
# systemctl begin docker
16. Distinction between “&&” and “;” operators between instructions
The “&&” operator executes the second command provided that the primary command was profitable.
$ sudo sh -c ‘apt-get replace && apt-get improve’
Within the above case, the second command (apt-get improve) will execute provided that the primary command was profitable. In any other case, it received’t run.
The “;” operator executes the second command whether or not the primary command was profitable or failed.
$ sudo sh -c ‘apt-get replace ; apt-get improve’
Within the above case, the second command (apt-get improve) will execute even when the primary command is failed.
16. Monitoring Kernel messages
To watch Kernel messages in dwell, run:
$ dmesg -wx
To cease monitoring press CTRL+c.
Examine Netdata device to observe all the pieces in a Linux system.
17. Copy all the pieces besides one file or listing
$ rsync -avz –exclude ‘ostechnix’ dir1/ dir2/
The above command will copy all the pieces from dir1 to dir2, besides “ostechnix”. The “ostechnix” will be both file or folder.
18. Examine service standing
To test if a specific service is enabled or not at startup, use:
$ systemctl is-enabled bluetooth-service
19. Delete duplicate strains in recordsdata
We are able to delete all consecutive duplicate strains in a file, for instance ostechnix.txt, utilizing command:
$ sed ‘$!N; /^(.*)n1$/!P; D’ ostechnix.txt
This command will delete all consecutive duplicate strains from the ostechnix.txt file.
20. Checklist display screen decision
To listing all resolutions supported by your X, use xrandr command like beneath:
To alter X’s decision on the fly:
$ xrandr -s 1024×760
We are able to additionally modify monitor brightness utilizing xrandr command. Extra particulars are within the following hyperlink.
21. Show crypto forex trade charges
To show all cryptocurrency trade charges in Terminal, run:
$ curl charge.sx
To show a particular forex charge, for instance BTC, run:
$ curl charge.sx/btc
22. Examine your CPU compatibility
To test your CPU compatibility i.e 32 bit or 64 bit, run:
$ lscpu | grep mode
Do you wish to know whether or not your system is 32 bit or 64 bit? Refer the next information.
23. Shortly copy or backup recordsdata
To rapidly copy or backup a file, use this command:
$ cp ostechnix.txt,.bak
This command will copy the file named “ostechnix.txt” to a file named “ostechnix.txt.bak”. This may be helpful for making backups of configuration recordsdata earlier than enhancing them.
24. Create recordsdata of particular permissions
To create recordsdata with particular permission on the fly, run:
$ set up -b -m 777 /dev/null file.txt
Right here, -b flag is used to take backup of the file if it already exists.
25. Enjoying multiplayer Tron sport in your Terminal
$ ssh sshtron.zachlatta.com
Use W, A, S, D keys for motion. It’s helpful to kill your boring time.
26. Show a sequence of numbers in Terminal
This command will show the numbers from 01 to 10.
27. Arch Linux information on Terminal
To show the newest Arch Linux information in your Terminal, use w3m textual content browser like beneath:
$ w3m https://www.archlinux.org/ | sed -n “/Newest Information/,/Older Information/p” | head -n -1
Be sure you have put in w3m textual content browser. w3m is offered within the default repositories of most Linux distributions.
28. Create encrypted (password-protected) file utilizing Vim
$ vim -x ostechnix.txt
Enter the encryption key twice.
To take away the password, open the file utilizing vim:
$ vim ostechnix.txt
Lastly sort :wq to save lots of and shut the file.
Additionally use CryptoGo utility to password-protect recordsdata.
29. Watch ASCII episode of Star Wars IV in Terminal
$ telnet towel.blinkenlights.nl
Please be aware that you would be able to’t pause, rewind as soon as the film begins. Be ready to observe your complete episode in a single sitting.
30. Checklist hidden recordsdata and directories first
$ ls -alv
31. Discover and delete particular sort of recordsdata
To search out and delete all recordsdata of sure sort, for instance “PDF”, run:
$ discover . -name ‘*.pdf’ | xargs rm -v
Double test earlier than you working this command. Chances are you’ll by accident run it in unsuitable listing and delete all information.
32. Show disk utilization in human readable format
Show disk utilization of all recordsdata and directories in human readable format:
$ du -ah
Show solely the entire disk utilization (abstract) of present listing:
$ du -sh
33. Find out how to use Vim editor if ESC secret’s damaged
To make use of vim editor on a system the place ESC key doesn’t work, use the next keyboard shortcut:
34. Reset and erase all characters in Terminal directly
To reset and erase all characters entered at Unix password immediate, press:
Earlier than I do know this tip, I hit BACKSPACE key repeatedly to erase the characters.
35. Checklist upgradble packages on DEB-based techniques
To view the listing of packages to be upgradable on Debian primarily based techniques, use:
$ apt-get listing –upgradable
36. Discover “ext” filesystem mount time
To search out when was an “ext” filesystem final mounted, run:
$ sudo tune2fs -l /dev/sdaX
The place “x” is the partition quantity like sda1, sda2
$ sudo tune2fs -l /dev/sda1
$ sudo tune2fs -l /dev/sda1 | grep “Final mount time”
You may as well use this command to test what number of instances the file system has been mounted and when was the file system created .
37. Helpful BASH shortcuts
Listed below are some helpful BASH shortcut keys.
CTRL+r : Search command historical past
CTRL+l : Clears the Terminal display screen. (Right here l is the letter L)
CTRL+c : Cancels the working command.
CTRL+z : Suspends the working command.
CTRL+u : Delete your complete line earlier than the cursor.
CTRL+ok : Delete your complete line after the cursor.
CTRL+t : Interchange the final two characters earlier than the cursor. helpful to right mistyped instructions.
CTRL+d : Shut the Terminal.
Extra Bash shortcuts are given within the following information.
That’s all for the primary half. Learn the second a part of this sequence within the hyperlink given beneath.
Thanks for stopping by!
Assist us that can assist you:
Have a Good day!!