Interesting Linux Command line Tricks and Tips Worth knowing

Source: Internet
Author: User
Tags builtin

I passionately enjoy working with commands as they offer + control over a Linux system than GUIs (graphical User Interfa CES) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make Linux operate, primarily from the terminal.

It's always thrilling when we discover new tricks or tips and using Linux especially a command line geek like myself.

suggested Read: 5 interesting Command line Tips and Tricks in Linux–part 1

And the feeling of wanting to share newly learned practices or commands with millions of Linux users out there, particular Ly the newbies who is still getting their it around this exciting operating system normally sets in.

suggested Read: useful Linux Command line Tricks for Newbies–part 2

In this article, we'll review a number of useful command line tricks and tips that can significantly enhance your Linux Usage skills.

1. Lock or Hide a File or Directory in Linux

The simplest-locking a file or directory is by using Linux file permissions. In case your the owner of a file or directory, you can block (remove read, write and execute privileges) other users and G Roups from accessing it as follows:

$ chmod tecmint.infoor$ chmod go-rwx tecmint.info

To know more on Linux file permissions, read this article managing Users & Groups, file Permissions & Attribute s in Linux.

To hide the file/directory from other system users, rename it with a at the start of the (.) file or directory:

$ mv filename. tecmint.info
2. Translate rwx Permissions into octal Format in Linux

By default, if you run the LS command, it displays file permissions rwx in format, but to understand the equivalence O F This format and the octal format, you can learn how to translate rwx permissions into octal format in Linux.

3. How to use the ' su ' when ' sudo ' fails

Although sudo command is used to execute commands with Superuser privileges, there was moments when it fails to work as in The example below.

Here, I want to empty the contents of a large file named but the uptime.log operation have failed even when I used sudo.

$ cat/dev/null >/var/log/uptime.log $ sudo cat/dev/null >/var/log/uptime.log

Empty Large File Content in Linux

In such as case, you need to the root of the user account using the SU command to perform the operation:

$ su$ sudo cat/dev/null >/var/log/uptime.log$ cat/var/log/uptime.log

Switch to Super User

Try to understand the difference between Su and sudo, in addition, read through their mans pages for more guidelines:

$ mans sudo$ man Su
4. Kill a Process in Linux

Sometimes when you want to terminate a process using kill or Killall or Pkill commands, it could fail to work and you realize t Hat the process still continues to run on the system.

In order to destructively kill a process, send the -KILL siganl to it.

First determine its process ID and then kill it like so:

$ pidof vlc$ sudo kill-kill 10279

Find and Kill Process in Linux

Check the KILL command for additional usage options and information.

5. Delete File permanently in Linux

Normally, we use the RM command to delete files from a Linux system, however, these files does not completely get deleted, t Hey is simply stored and hidden on the hard disk and can still being recovered these files in Linux and viewed by another PE Rson.

To prevent this, we can use the Shred command which overwrites the file content and optionally deletes the file as well.

$ Shred-zvu Tecmint.pdf

The options used in the above command:

    1. -z–adds a final overwrite with zeros to hide shredding.
    2. -u–helps to truncate and remove file after overwriting.
    3. -v–shows progress.

Delete File permanently in Linux

Read through Shred Mans page for additional usage instructions:

$ mans Shred
6. Rename multiple Files in Linux

You can rename multiple files in Linux on the go by invoking the Rename command.

It renames the filenames supplied according to a rule specified in the first argument.

The command below renames all .pdf files .doc to, this is the ‘s/\.pdf$/\.doc/‘ rule:

$ Rename-v ' s/\.pdf$/\.doc/' *.pdf

Rename multiple Files in Linux

The next example renames all files matching "*.bak" to strip the extension, where is the ‘s/\e.bak$//‘ rule:

7. Check for spelling of Words in Linux

The look command displays lines beginning with a given string, it can help you to check for the spelling of Word from with In the command line. Although it is not so effective and reliable, look was still a useful alternative to other powerful spelling-checkers:

$ look linu$ look docum

Spell Checking in Linux

8. Search for Description of Keyword in Manual Page

The man command was used to display manual entry pages of commands, when used with -k the switch, it searches the short Descriptions and manual page names for the keyword printf (such as adjust, Apache and PHP in the commands below) as regular Expression.

$ man-k adjust$ man-k apache$ man-k php

Show Description of Keyword in Manual Pages

9. Watch Logs in real-time in Linux

With watch command, you can run another Linux command periodically while displaying it output on fullscreen and alongside Tail command which is used to view the last parts of a file, it's possible to watch the recording of logs entries in a Lo Gfile.

In the example below, you'll watch the system authentication logfile. Open terminal windows, display the logfile for watching in real-time in the first window like so:

$ sudo watch Tail/var/log/auth.log

You can also use tail command which shows the last parts of a file. Its -f flag enables watching changes in a file in real-time, therefore it's possible to watch the recording of log ent Ries in a logfile.

$ sudo tail-f/var/log/auth.log

and run the commands below in the second terminal as you observe the logfile content from the first window:

$ sudo mkdir-p/etc/test$ sudo rm-rf/etc/test
List All Shell builtin Commands

A shell builtin is a command or a function, called from within and executed directly in the shell itself, instead of an ex ternal executable program which, the shell would load from the hard disk and execute.

To list all shell builtins and their usage syntax, run:

$ help

As a concluding remark, command line tricks and tips all come in handy and make learning and using Linux easy and fun E Specially for newbies.

You can as well share with us other useful and interesting command line tricks or tips in Linux so you have come across Via the comment form below.

Interesting Linux Command line Tricks and Tips Worth knowing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.