Summary: I like to use commands very much, because they provide more control over the Linux system than GUI (graphical user interface) applications, so I've been looking for some interesting ways to make Linux easier and more fun, mostly based on terminal operations. When we find new techniques for using Linux, especially command-line geeks like me, we always feel very excited.
I like to use commands very much, because they provide more control over the Linux system than GUI (graphical user interface) applications, so I've been looking for some interesting ways to make Linux easier and more fun, mostly based on terminal operations.
When we find new techniques for using Linux, especially command-line geeks like me, we always feel very excited.
Suggested reading: 5 interesting Linux command-line tricks-Part I
And we would love to share new practices or commands with millions Linux users, especially those who are still working on this exciting operating system in their own way.
Suggested reading: 10 useful Linux command-line tricks for beginners-Part Two
In this article, we'll review a series of useful command-line tips that can significantly improve your Linux usage skills.
1. Lock or hide files or directories in Linux
The simplest way to lock a file or directory is to use Linux file permissions. If you are the owner of a file or directory, you can block other users and groups from accessing (deleting, reading, writing, executing) it as follows:
$ chmod 700 tecmint.info
或
$ chmod go-rwx tecmint.info
To learn more about Linux file permissions, read this article on managing users and Groups, file permissions, and properties in Linux.
In order to enable hidden files or directories from other users in the system, you can rename them by adding them at the beginning of the file or directory .
:
$ mv filename .tecmint.info
2. Convert rwx permissions to octal format in Linux
By default, when you run the LS command, it uses the rwx
format to display file permissions, and in order to understand the RWX format and octal format equivalence, you can learn how to convert rwx permissions to octal format in Linux.
3. When
sudo
How to use when command execution fails
su
Command
Although the sudo command is used to execute commands with superuser privileges, in some cases it will also fail, as shown below.
Here, I want to empty the contents of a large file, whose file name is uptime.log
, but even if I use the sudo command, it fails.
-
$ cat /dev/null >/var/log/uptime log
-
$ sudocat /dev/ null >/var/ Log/uptime.
Empty the contents of large files in Linux
In this case, you need to su
switch to the user with a command root
and then perform the purge operation like this:
$ 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, by reading their hand albums to learn more about the usage guide:
$ man sudo
$ man su
4. End a process in Linux
Sometimes, when you want to end a process with the kill, Killall, pkill commands, they might not work, and you might see that the process is still running on the system.
If you want to force the end of a process, you can send a -KILL
signal to the process.
Get the specified process ID first, and then end the process as follows:
$ pidof vlc
$ sudo kill -KILL 10279
Find and end processes in Linux
View the KILL command for more usage options and information.
5. Permanently delete files in Linux
In general, we rm
remove files from the Linux system by using commands. However, these files are not really deleted, they are still stored there and hidden on your hard drive, and other users can still recover deleted files and view them in Linux.
To prevent this from happening, we can use shred
commands to overwrite the contents of the file and choose to delete the file after the overwrite is complete.
$ shred -zvu tecmint.pdf
Description of the options used in the above command:
-z
– Last use 0 to overwrite to hide overwrite action.
-u
– Truncate and remove files after overwrite.
-v
– Show detailed procedures.
Permanently delete files in Linux
Read shred
the manual for more information about usage.
$ man shred
6. Renaming multiple files in Linux
You can rename rename
multiple files in Linux at any time by using commands.
rename
The command renames the specified file according to the rules in the first parameter.
The following command renames all .pdf
files to a .doc
file, using a rule that ‘s/\.pdf$/\.doc/‘
:
$ rename -v ‘s/\.pdf$/\.doc/‘ *.pdf
Renaming multiple files in Linux
In the following example, we will remove the extension name by renaming all matching "*.bak"
files, using the following rules ‘s/\e.bak$//‘
:
$ rename -v ‘s/\e.bak$//‘ *.bak
7. Check the spelling of the word in Linux
look
The command is used to display any row in the file prefixed with the specified string, and it can also help you check the spelling of a given word in the command line. Although it is not so effective and reliable, it is still a useful alternative to other powerful spell checker tools.
$ look linu
$ look docum
Check the spelling of a word in Linux
8. Search the manual page by keyword
man
The command is used to display the man page of the command, and when the option is used, it uses the keyword -k
printf
(or keywords in the following command, adjust
apache
,, php
) as a regular expression to search all matching pages of that name and to display its introduction.
$ man -k adjust
$ man -k apache
$ man -k php
Search by Keyword page
9. Real-time monitoring of logs in Linux
watch
command to execute another Linux command on a regular basis and display the result of the command in full screen. When the watch
command is used in conjunction with the Tail command (the Linux command used to view the end of the file), log file logging can be monitored.
In the following example, you will monitor the system authentication log file in real time. Open two terminal windows and monitor the log file in real time in the first window as follows:
$ sudo watch tail /var/log/auth.log
You can also -f
monitor file changes in real time using the tail command (which displays the Linux command at the end of the file). In this way, we can see the log generation in the log file.
$ sudo tail -f /var/log/auth.log
Next, run the following command in the Second terminal window, after which you can observe the contents of the log file in the first terminal window:
$ sudo mkdir -p /etc/test
$ sudo rm -rf /etc/test
10. List all shell built-in commands
The shell built-in command is a command or function that is invoked from within and executed directly in the shell, rather than from an external executable program loaded from the hard disk.
List all shell built-in commands and their syntax, and execute the following command:
$ help
As a closing point, command-line tricks can be useful and make learning and using Linux easier and more fun, especially for beginners.
Original Date: 2017-01-15
This article comes from the cloud community partner "Linux China"
Original link
10 Interesting Linux command-line tips you should know