Linux operation notes

1. Close the dead end program

[root@node3 ~]# ps -aux | grep fire root 2105 0.0 0.0 112660 964 pts/0 S+ 15:10 0:00 grep –color=auto fire root 10620 0.0 0.1 1215096 239328 ? SL January 11 19:02 /usr/lib64/firefox/firefox [root@node3 ~]# kill -9 10620

2. Dynamic display

Dynamically track the growth of the file (output attached data as the file growth). Tail will check whether the file adds new content every second. If so, it will be appended and displayed after the original output. However, in this case, it must be ensured that the file already exists when the tail command is executed [root@webServer logs]# tail -f catalina.out

3.Ubuntu uninstall software

Delete software and its configuration files apt-get –purge remove Delete useless dependent packages apt-get autoremove

kylin@Ubuntu:~$ sudo apt-get remove --purge ant
kylin@Ubuntu:~$ sudo apt-get autoremove --purge ant

4.tar decompression and compression

Extract to current directory: [root@webServer ~]# tar -zxvf xxx.tar.gz Extract to the specified directory: [root@hadron ~]# tar -zxvf xxx.tar.gz -C /opt Pack and compress command: [root@hadron ~]# tar -zcvf xxx.tar.gz xxx/

Meaning of parameters

  • c Create a new archive.
  • t List the contents of an archive.
  • x Extract the contents of an archive.
  • f The archive file name is given on the command line (required whenever the tar output is going to a file)
  • M The archive can span multiple floppies.
  • v Print verbose output (list file names as they are processed).
  • u Add files to the archive if they are newer than the copy in the tar file.
  • z Compress or decompress files automatically. encryption and decryption

Encryption, enter the password twice

[root@hadron ~]# zip -re data
Enter password: 
Verify password: 
  adding: data/ (stored 0%)
  adding: data/ (stored 0%)
  adding: data/ (stored 0%)
  adding: data/ (stored 0%)
  adding: data/ (stored 0%)

Unzip and enter the password

[root@hadron ~]# unzip 
   creating: data/
[] data/ password: 
 extracting: data/          
 extracting: data/       
 extracting: data/     
 extracting: data/ 

6.CentOS7 set shortcut keys for screenshots

1) Location of screenshot tool: applications - Utilities - screenshot 2) Location of shortcut key settings: applications - system tools - Settings - Keyboard 3) Switch to the Shortcut tab: shortcuts, find screenshots, click the item you want to set on the right, and press the shortcut you want to set (no input). For example, I often use the screenshot of an area to pictures (Save a screenshot of an area to Pictures), and the shortcut key I use most is the screenshot shortcut key of QQ (Ctrl+Alt+A)


Hosts file is a computer file used to store the information of each node in the computer network. This file is responsible for mapping the host name to the corresponding IP address. The hosts file is usually used to supplement or replace the function of DNS in the network. Unlike DNS, computer users can directly control the hosts file. The locations of hosts files are different in different operating systems (even different Windows versions):

  • Windows system Generally, it is in the directory C:\WINDOWS\system32\drivers\etc
  • Linux system In / etc directory


8.1 running SSH without option parameters

By default, ssh will try to connect with the current user as the user name.

[root@hadron ~]# ssh
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is ac:f1:e0:63:72:f7:1c:70:a5:4f:65:2b:ab:0d:9f:12.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (ECDSA) to the list of known hosts.
root@'s password: 
Last login: Wed Mar 15 00:39:04 2017 from
[root@cnode0 ~]# exit
 Log out
Connection to closed.

In this example command, ssh will try to log in to the server as root

8.2 designated login user

Because is an Ubuntu server, you can't log in with root user. At this time, you can specify the user to log in.

[root@hadron ~]# ssh kylin@
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is b2:34:8c:09:32:d2:1a:cb:cf:c2:60:ed:ad:d9:d7:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (ECDSA) to the list of known hosts.
kylin@'s password: 
Welcome to YHKylin 4.0-1D (GNU/Linux 3.14.57-20160128.kylin.4.server.generic+ aarch64)
Last login: Tue Mar 15 09:00:09 2016 from

9 scp

9.1 copying documents

Command format 1: scp local_file remote_username@remote_ip:remote_folder perhaps scp local_file remote_username@remote_ip:remote_file

Command format 2: scp local_file remote_ip:remote_folder perhaps scp local_file remote_ip:remote_file

The command format 1 specifies the user name. After the command is executed, you need to enter the user password. The first command only specifies the remote directory, and the file name remains unchanged. The second command specifies the file name (you can customize the file name) For example:

[root@anode1 ~]# scp ReadFile.jar root@
root@'s password: 
ReadFile.jar                             100% 1248     1.2KB/s   00:00

Query on machine 81

[root@hadron ~]# ls |grep ReadFile2.jar

The command format 2 does not specify a user name. The default is "root" access by the current user

[root@anode1 ~]# scp ReadFile.jar
root@'s password: 
ReadFile.jar                             100% 1248     1.2KB/s   00:00    

Query on machine 81

[root@hadron ~]# ls |grep ReadFile.jar

9.2 copy directory

Command format: scp -r local_folder remote_username@remote_ip:remote_folder

perhaps scp -r local_folder remote_ip:remote_folder

10 clear history command record

You can view the previously executed commands through the history command

[root@hadron ~]# history
   18  sh ./a.out 
   19  ./a.out &
   20  ls
   21  ./a.out &
   22  ls
   23  cd source/
   24  ls
   25  cd 
   26  ls
   27  cd python/

Use the history -c command to clear the history

[root@hadron ~]# history -c
[root@hadron ~]# history
   25  history

11. Enter the command interface (text interface) by default when starting up

For CentOS7, use systemctl set default multi user Target command

[root@hadron ~]# systemctl set-default

Then restart the system

12 decompress rar

wget tar zxvf rarlinux-3.8.0.tar.gz cd rar make make install

[root@hadron opt]# wget
--2017-06-23 14:45:45--
 Resolving host (
 on connection (||:80... Connected.
Issued HTTP Request, waiting for response... 200 OK
 Length: 791915 (773K) [application/x-gzip]
Saving to: "rarlinux-3.8.0.tar.gz"

100%[==============================================================================================================>] 791,915      645KB/s Time 1.2s   

2017-06-23 14:45:46 (645 KB/s) - Saved“ rarlinux-3.8.0.tar.gz" [791915/791915])

[root@hadron opt]# tar -zxvf rarlinux-3.8.0.tar.gz
[root@hadron opt]# cd rar
[root@hadron rar]# make
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib
[root@hadron rar]# make install 
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib

Problems encountered

[root@hadron rar]# rar
bash: /usr/local/bin/rar: /lib/ bad ELF interpreter: There is no such file or directory

Because 32-bit programs are installed in 64 bit systems, there are two solutions Method 1

[root@hadron rar]# yum install glibc.i686
[root@hadron rar]# yum install libstdc++

Method 2

[root@hadron rar]# cp rar_static /usr/local/bin/rar
cp: Overwrite"/usr/local/bin/rar"? y

In this way, the rar command can be used

[root@hadron rar]# rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Usage:     rar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract\>

  a             Add files to archive
  c             Add archive comment
  cf            Add files comment
  ch            Change archive parameters
  cw            Write archive comment to file
  d             Delete files from archive
  e             Extract files to current directory
  f             Freshen files in archive
  i[par]=<str>  Find string in archives
  k             Lock archive
  l[t,b]        List archive [technical, bare]
  m[f]          Move to archive [files only]
  p             Print file to stdout
  r             Repair archive
  rc            Reconstruct missing volumes
  rn            Rename archived files
  rr[N]         Add data recovery record
  rv[N]         Create recovery volumes
  s[name|-]     Convert archive to or from SFX
  t             Test archive files
  u             Update files in archive
  v[t,b]        Verbosely list archive [technical,bare]
  x             Extract files with full path

13 file comparison diff

diff output format (default): n1 a n3,n4 means adding n3 to n4 after n1 line of file 1 n1, n2, D, n3 indicates that n3 rows are deleted between n1 and n2 rows n1,n2, C, n3,n4 means to replace lines N1 and N2 with lines N3 and N4 Letter a: indicates additional (add) Character c: indicates change Character d: indicates delete Before the letter is the source file and after the letter is the target file. Nx indicates the line number. The line beginning with "<" belongs to the first file, and the line beginning with ">" belongs to the second file.






diff command

[root@hadron diff]# diff a.txt b.txt
< ccccc
> cccc

The above "3c3" indicates that the content of the third line of a.txt is different from that of b.txt. The line beginning with "<" belongs to the first file (a.txt), and the line beginning with ">" belongs to the second file (b.txt).

14 md5

md5sum verifies the file content, regardless of the file name

root@kylin2:/opt# md5sum Manager-Kylin-20170814.tar.gz 
ebcf5491a121dc80bee069fa872ab71c Manager-Kylin-20170814.tar.gz
[root@hadron Kylin]# md5sum Manager-Kylin-20170814.tar.gz
ebcf5491a121dc80bee069fa872ab71c  Manager-Kylin-20170814.tar.gz
[root@hadron Kylin]# 

Two manager-kylin-20170814 can be determined tar. GZ files are the same.

[root@hadron Kylin]# md5sum web*
bc92d8103cbfb473c9854717f3e1677b  store.tar.gz
9067a8b723f5229b49eeef0ff46bc66d  store.bak
[root@hadron Kylin]# 

You know the store tar. GZ and store Bak content is different!

16 view disk space

The df command is used to display the disk usage statistics of the file system currently on the Linux system -h. – human readable uses a human readable format

[root@node3 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       147G  130G   18G  89% /
devtmpfs         63G     0   63G   0% /dev
tmpfs            63G  172K   63G   1% /dev/shm
tmpfs            63G  418M   63G   1% /run
tmpfs            63G     0   63G   0% /sys/fs/cgroup
/dev/sda3       271G   13G  258G   5% /data
tmpfs            13G   52K   13G   1% /run/user/0
/dev/loop2      7.8G  7.8G     0 100% /var/ftp/iso-home
[root@node3 ~]# df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       147G  130G   18G  89% /
[root@node3 ~]#

The du command is used to display the disk space occupied by the specified directory or file, -h or – human readable in K, M, G units to improve the readability of information.

[root@node3 ~]# du -h /tmp
0   /tmp/.ICE-unix
0   /tmp/.font-unix
0   /tmp/.X11-unix
0   /tmp/.Test-unix
0   /tmp/.XIM-unix
0   /tmp/.esd-0
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z/tmp
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq/tmp
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq
0   /tmp/ssh-5ip8dhXgZeo5
0   /tmp/ssh-zhmfU1HmgApU
14M /tmp
[root@node3 ~]#

17 sed command

sed -i can directly modify the contents of the file through option i. the syntax is as follows.

sed -i 's/String to be replaced/New string/g' filePath

Where s is the replacement command, the text contained in the slash after s is a regular expression, followed by the text to be replaced. Rows can be globally replaced by the g flag.

[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

If the replaced string or the new string contains /, you can use # to replace /. Examples are as follows

[root@master hadoop]# sed -i 's#export JAVA_HOME=${JAVA_HOME}#export JAVA_HOME=/usr/java/jdk1.8.0_144#' 

18 & and nohup

Ordinary processes are put into the background to run with the & symbol. If the console (Shell) that started the program exits, the process will be terminated immediately.

Nohup < program name >& If you run the program in this way, the process will continue to run after the console logout, playing the role of a daemon After using the nohup command, the standard output of the original program is automatically changed to nohup in the current directory The out file functions as a complete daemon.

19 count the number of files or directories in the directory

[root@node1 ~]# ls -l |grep "^-"|wc -l
[root@node1 ~]# ls -l |grep "^d"|wc -l
[root@ndoe1 ~]# 

explain: (1)ls -l : Lists the file information under the current folder (2)grep "^-" : "^ -" is a regular expression, and those starting with "-" represent files, that is, to find general files; If the lookup directory is ^ d, (3) wc -l : Count the number of rows of output information

20 find the number of files of a certain type in the current directory (including subdirectories)

[root@node1 ~]# find . -type f -name "*.rar" | wc -l
[root@node1 ~]#

Terminal display style

\33[0m close all attributes \33[1m set high brightness \33[7m reverse display

\33[30m – \ 33[37m set foreground color \33[40m – \ 33[47m set background color

[root@hadron ~]# echo -e "\033[1m something here \033[0m" something here [root@hadron ~]# echo -e "\033[7m something here \033[0m" something here [root@hadron ~]# echo -e "\033[41;36m something here \033[0m" something here [root@hadron ~]#

Posted by skbanta on Fri, 06 May 2022 13:44:58 +0300