10 Interesting Linux Command Line Tricks and Tips Worth Knowing
I passionately enjoy working with commands as they offer more control over a Linux system than GUIs(Graphical User Interfaces) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make Linux so easy and fun to operate, primarily from the terminal.
It is always thrilling when we discover new tricks or tips while 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, particularly the newbies who are still getting their way around this exciting operating system normally sets in.
Suggested Read: 10 Useful Linux Command Line Tricks for Newbies – Part 2
In this article, we will 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 way of 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 groups from accessing it as follows:
$ chmod 700 tecmint.info
OR
$ chmod go-rwx tecmint.info
To know more about Linux file permissions, read this article Managing Users & Groups, File Permissions & Attributes 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, when you run the ls command, it displays file permissions in rwx format, but to understand the equivalence of this format and the octal format, you can learn how to translate rwx permissions into Octal format in Linux.
3. How to Use ‘su’ When ‘sudo’ Fails
Although sudo command is used to execute commands with superuser privileges, there are moments when it fails to work as in the example below.
Here, I want to empty the contents of a large file named uptime.log but the operation has 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 switch to the root user account using su command to perform the operation like so:
$ 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 man pages for more guidelines:
$ man 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 may fail to work, you realize that 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 do not completely get deleted, they are simply stored and hidden on the hard disk and can still be recovered these files in Linux and viewed by another person.
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:
-z– adds a final overwrite with zeros to hide shredding.-u– helps to truncate and remove file after overwriting.-v– shows progress.
Delete File Permanently in Linux
Read through shred man page for additional usage instructions:
$ man 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 to .doc, here 's/\.pdf$/\.doc/' is the 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 's/\e.bak$//' is the 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 within the command line. Although it is not so effective and reliable, look is 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 is used to display manual entry pages of commands, when used with the -k 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 its output on fullscreen and alongside tail command which is used to view the last parts of a file, it is possible to watch the recording of log entries in a logfile.
In the example below, you will watch the system authentication logfile. Open two 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 is possible to watch the recording of log entries 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
10. 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 external 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 always come in handy and make learning and using Linux easy and fun especially for newbies.
You can as well share with us other useful and interesting command line tricks or tips in Linux that you have come across via the comment form below.
10 Interesting Linux Command Line Tricks and Tips Worth Knowing的更多相关文章
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- [笔记]The Linux command line
Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...
- 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令
Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...
- 《The Linux Command Line》 读书笔记02 关于命令的命令
<The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- Linux Command Line 解析
Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...
- Reso | The Linux Command Line 的中文版
http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...
- Linux Command Line(II): Intermediate
Prerequisite: Linux Command Line(I): Beginner ================================ File I/O $ cat > a ...
随机推荐
- $( document ).ready()&$(window).load()
$( document ).ready() https://learn.jquery.com/using-jquery-core/document-ready/ A page can't be man ...
- Flex data
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- javaWeb学习笔记
一. web.xml -------------------------------------------------------------------------------- ...
- java中String类、StringBuilder类和StringBuffer类详解
本位转载自http://www.cnblogs.com/dolphin0520/p/3778589.html 版权声明如下: 作者:海子 出处:http://www.cnblogs.com/dolp ...
- 不要滥用div,保持代码的整洁
这篇文章算是很基础的了.旨在介绍如何保证页面代码的整洁.以维护性.使用有语义的页面标签,减少标签的滥用. 1. 移除不必要的<div>标签 嵌套在<form><ul> ...
- 微价值:专訪《甜心爱消除》个人开发人员Lee,日入千元!
[导语]我们希望能够对一些个人开发人员进行专訪,这样大家更能显得接地气,看看人家做什么,怎么坚持.<甜心爱消除>作者Lee是三群的兄弟,也关注微价值.微价值的文章还是能够的,得到一些业内大 ...
- 64位ubuntu下装32位软件
本帖最后由 wuy069 于 2013-10-25 12:28 编辑 很多软件只有32位的,有的依赖32位库还挺严重的:从ubuntu 13.10已经废弃了ia32-libs,但可以使用多架构,安装软 ...
- .net+mssql制作抽奖程序思路及源码
近期一直在研究数据库,刚好有个项目要做抽奖程序,恩,拿来练练手吧. 抽奖程序: 思路整理,无非就是点一个按钮,然后一个图片旋转一会就出来个结果就行了,可这个程序的要求不是这样的,是需要从数据库中随机抽 ...
- openlayers3 在地图上叠加WFS查询矢量图层
随着终端设备计算能力的加强,用户在使用地图的时候也须要越来越多的交互效果. 比方如今非常火的室内导航,为了获得好的用户体验,就须要当用户单击某一商店的时候该商店的颜色能对应的变化.这就须要叠加矢量图层 ...
- 深入NGINX:我们如何设计它的性能和扩展性
为了更好地理解设计,你需要了解NGINX是如何工作的.NGINX之所以能在性能上如此优越,是由于其背后的设计.许多web服务器和应用服务器使用简单的线程的(threaded).或基于流程的 (proc ...