Ten little-known Linux commands - [4]

32. strace Command

strace is a debugging tool and is mainly used for troubleshooting Linux. It may not be installed by default on your system. You may need apt or yum to install the package you need.

Track the execution of a command using the strace command.

root@tecmint [~]# strace pwd

Example output

execve("/bin/pwd", ["pwd"], [/* 29 vars */]) = 0
brk(0)                                  = 0x728000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0df2000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=38427, ...}) = 0
mmap(NULL, 38427, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f29b0de8000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY)      = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\355\1I;\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1922152, ...}) = 0
mmap(0x3b49000000, 3745960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3b49000000
mprotect(0x3b4918a000, 2093056, PROT_NONE) = 0
mmap(0x3b49389000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x189000) = 0x3b49389000
mmap(0x3b4938e000, 18600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3b4938e000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de7000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de6000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29b0de5000
....

The strace command has a large number of parameters and options, please refer to the man page for details.

33. disown-a & & exit command

Most system administrators use screen command Control the operation in the background of the terminal. Let's assume that if you have a long-running job and want to detach it from the terminal, you can do so with the screen command. But if you don't know how to use screen, then disown can be used for emergency treatment.

The disown command can continue running tasks in the background even if you close the terminal session. The grammar of the disown command is:

root@tecmint [~]# Command; disown -a && exit

In order to get rid of a long-running task in the terminal again, use the job command to find the task number, and then use disown% n, where% n is the job number. To verify that the job is actually running, use ps or top command . The nohup command is also an alternative to the disown command.

34. getconf LONG_BIT command

Can the above command show that your machine architecture is 32 bits or 64 bits?

root@tecmint [~]# getconf LONG_BIT

32

35. Date displayed on terminal

The following command is a collection of several commands, or rather a script. For people working under a shell or terminal, it's tedious to see the current system date without a GUI interface. You can use the'date'command to see today's date.

Just type the following command after the prompt and you will see the date and time in the upper right corner of the terminal.

root@tecmint [~]# while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &

Display the date under the terminal

36. convert command

When writing tutorials, I often need to generate output, often in image format. The above command set does not suit me. Suppose I need the output of the tree command in image format (for the / etc/x11 directory).

root@tecmint:/etc/X11# tree | convert label:@- /home/avi/tree.png

The output of the above command can be seen in a specific location (here is my home directory), and the file name is tree.png.

37. watch -t -n1 "date +%T|figlet"

Remember the "figlet" command in our earlier articles“ 20 Funny Commands of Linux ” Description in. This command is very cool. This time we'll export it to'figlet'via a pipeline and display an animated electronic clock on the terminal.

Check it out for yourself, and remember that you have to install figlet s on your system and install the packages you need with apt or yum.

root@tecmint [~]# watch -t -n1 "date +%T|figlet"

Example output

 _  ___    ____   ___    _____ _  _                                                                                             Fri Nov 29 10:29:34 GMT 
/ |/ _ \ _|___ \ / _ \ _|___ /| || |
| | | | (_) __) | (_) (_) |_ \| || |_
| | |_| |_ / __/ \__, |_ ___) |__   _|
|_|\___/(_)_____|  /_/(_)____/   |_|

38. host and dig commands

Although the "host" and "dig" commands are less well known, they are still rarely used. The host command is a DNS query tool.

root@tecmint [~]# host www.google.com

www.google.com has address 173.194.66.147
www.google.com has address 173.194.66.105
www.google.com has address 173.194.66.99
www.google.com has address 173.194.66.104
www.google.com has address 173.194.66.106
www.google.com has address 173.194.66.103
www.google.com has IPv6 address 2a00:1450:400c:c03::68

In fact, I think the dig command is the most powerful. Since dig came into being, I no longer need nslookup.

root@tecmint [~]# dig www.google.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<

39. dstat command

Dstat is a multi-purpose tool that generates statistics based on system resources. By default, your system may not have'dstat'installed. Use apt or yum to install before using this color generator to describe system information.

root@tecmint [~]# dstat

dstat command

40. Bid-p command

'bind-p'shows all the shortcuts available to BASH shell s.

root@tecmint [~]# bind -p

"\C-g": abort 
"\C-x\C-g": abort 
"\e\C-g": abort 
"\C-j": accept-line
"\C-m": accept-line 
# alias-expand-line (not bound) 
# arrow-key-prefix (not bound) 
# backward-byte (not bound) 
"\C-b": backward-char 
"\eOD": backward-char 
"\e[D": backward-char 
"\e!": complete-command 
"\e/": complete-filename 
"\e@": complete-hostname 
"\e{": complete-into-braces 
"\e~": complete-username 
"\e$": complete-variable 
# copy-backward-word (not bound)
# copy-forward-word (not bound) 
# copy-region-as-kill (not bound)
....
....

41. touch /forcefsck

The following command creates an empty folder'forcefsck'in the root directory. This forces the Linux system to check the file system at the next boot.

root@tecmint [~]# touch /forcefsck

Today these are all.

Tags: Google Linux yum shell

Posted on Wed, 11 Sep 2019 23:12:05 -0700 by theverychap