Home Linux Some Random One-liner Linux Commands [Part 4]

Some Random One-liner Linux Commands [Part 4]

By sk
Published: Last Updated on 359 views

This is the fourth part in the series of "random one-liner Linux commands" tutorial. In this part, you will learn about the random one-liner Linux commands, in no particular order or category, which we shared via image templates in our social and professional networks. Just in case, if you had missed the previous two parts, you can read them in the below links.

Now, let us see this month one-liner commands.

One-liner Linux Commands - Part 4

  1. To run a N'th command, for example 4th command,  from the history, run this command:
$ !4

Here, we use "!" followed by a number to recall that particular command in our BASH history. Similarly, we can run the N'th with with sudo privileges like below.

$ sudo !4

Please be mindful that this command can be destructive if that particular command was a deadly command, for example "rm -fr <some-file-or-directory>". So, be very cautious while using this command.

  1. To temporarily lock an user account, run:
$ sudo passwd <username> -l

This can be very useful when managing systems that are being accessed by many users.

To unlock the user, just do:

$ sudo passwd <username> -u

Also read:

  1. Display the status of an user account, for example ostechnix:
$ passwd -S ostechnix

Sample output:

ostechnix P 03/29/2018 0 99999 7 -1

As you see in the above screenshot, the status information consists of 7 fields.

  1. ostechnix - It is the first that displays the username.
  2. P - It is the 2nd field that indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P).
  3. 03/29/2018 - It is the third field. It indicates the date of the last password change.
  4. 0 - This fourth filed indicates minimum password age.
  5. 99999 - It is the fifth field which tells us maximum password age.
  6. 7 - The sixth fields indicates the warning period before the password expires.
  7. -1 - This is the seventh and last field that indicates inactivity period for the password. All these ages are expressed in days.
  1. Find out all information of a command:
$ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls

As you see, we can find out whether "ls" command is an alias, file, function, built-in command and the path of ls command.

  1. To install all .DEB files stored in a directory in Debian-based systems, use this command:
$ sudo dpkg -iR Downloads/

This command will install all .deb packages stored in the Downloads directory.

  1. To put all characters in each paragraph in a file in single line:
$ fmt file.txt

Let us say you have a file named ostechnix.txt with following contents.

abc
def
fgh
ijk

Now, run this command to put all these characters in a single line.

$ fmt ostechnix.txt
abc def fgh ijk

To put only a width of 10 characters in a single line, use -w flag.

$ fmt -w 10 ostechnix.txt
  1. To list all PCI hardware details, run:
$ lspci

To display more details, use -v flag.

$ lspci -v

To display even more details, use double -v flag.

$ lspci -vv
  1. To view the password expiration details of an user, for example ostechnix, run:
$ sudo chage -l ostechnix
Password: 
Last password change : Mar 31, 2018
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
  1. To find if your system supports virtualization technology (VT), run:
$ egrep "(svm|vmx)" /proc/cpuinfo

If you get "vmx" in the output, your system supports Intel-VT technology and if it is “svm” it means that your system has AMD-V support.

For more details, refer the following link.

  1. To start directly editing file on 'N'th line using Vi, use this command:
$ vi +5 file.txt

This command is used to begin editing the file.txt on 5th line using Vi editor.

  1. List the contents of a a zip file. for example ostechnix.zip, without extracting it, run:
$ unzip -l ostechnix.zip

Refer the following guide to know more about zip/unzip command usage in Linux.

  1. To archive a directory into multiple smaller parts, for example 100MB each, run:
$ zip -r -s 100m archive.zip ostechnix/

The above command will create an multiple smaller archives of the directory ostechnix with size 100MB each. This will be useful when you wanted to send a really big directory or file via Internet. Just divide the archive into multiple smaller parts and send them one by one.

  1. Convert a given string or URL into an ASCII QR code, run:
$ curl qrenco.de/OSTechNix

Sample output:

These all are the list of one-liner Linux commands that we shared via image templates in our social and professional networks . For more details, refer the man pages of the respective command. I hope some of these commands will help you.

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More