Summary of common commands under Linux

Source: Internet
Author: User

There are a lot of commands under Linux, but here are just a few of the things that are commonly used, and the ones that are useful when developing software.

1. ls command

[Email protected] test]$ ls-lR
.:
Total 8
Drwxrwxr-x 2 XBH xbh 4096 Nov 29 21:44 1
Drwxrwxr-x 2 XBH xbh 4096 Nov 29 21:44 2

./1:
Total 0
-rw-rw-r--1 xbh xbh 0 Nov 21:44 1.txt

./2:
Total 0
-rw-rw-r--1 xbh xbh 0 Nov 21:44 2.txt

Displays the file details of the current directory and subdirectories .

2. Find command

[[email protected] test]$ find. -name "*.txt"-exec ls-l {} \;
-rw-rw-r--1 xbh xbh 0 Nov 21:44./2/2.txt
-rw-rw-r--1 xbh xbh 0 Nov 21:44./1/1.txt

Find the file that ends with TXT in the current directory and list its details.

> Find. #列出当前目录的文件以及子目录下的相关信息.

3. grep command

-F parameter: Mandatory wildcard, such as invalid, this parameter should be memorized.

[[email protected] 1]$ grep ' www.*.com ' 1.txt
Www.baidu.com
www.google.com
Www.*.com
[[email protected] 1]$ grep- F ' www.*.com ' 1.txt
Www.*.com

-A parameter: The following lines of the keyword's row are also displayed synchronously;

[Email protected] 1]$ grep-a 1 ' Ed ' 1.txt
Ed
Www.baidu.com
[email protected] 1]$ cat 1.txt
A
B
C
D
Ed
Www.baidu.com
www.google.com
Www.*.com

-B parameter: Before several lines of the keyword's row are also displayed synchronously;

[Email protected] 1]$ grep-b 1 ' Ed ' 1.txt
D
Ed
[email protected] 1]$ cat 1.txt
A
B
C
D
Ed
Www.baidu.com
www.google.com
Www.*.com

-W parameter: Match only whole word

[[email protected] 1]$ grep ' d ' 1.txt
D
ED
Www.baiDu.com

[[email protected] 1]$ grep- w ' d ' 1.txt
D

-C Parameter: Count the number of occurrences of the keyword, in conjunction with the results of the-W query.

[Email protected] 1]$ grep-c ' d ' 1.txt
3
[Email protected] 1]$ GREP-WC ' d ' 1.txt
1

-N parameter: Display keywords in the row

[Email protected] 1]$ grep-n ' d ' 1.txt
4:D
5:eD
6:www.baiDu.com

4. Free command

[Email protected] 1]$ Free-m # #以M为单位展示系统内存当前情况
Total used free shared buffers Cached
mem:503 492 0 131 186
-/+ Buffers/cache: 175 328
swap:996 0 996
[[email protected] 1]$ Expr 131 + 186
317
[[email protected] 1]$ expr 492-317
175

The parameters of the second row are calculated as:

175 = 492-(131 + 196) indicates that the system is actually occupied memory

328 = 10 + (131 + 186) indicates system available memory, including buffer buffers and cache caches

5. lsof command

-I parameter: View process information for the specified port

[Email protected] xbh]# lsof-i:22
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
sshd 2276 root 3u IPv6 7164 TCP *:ssh (LISTEN)

On Redhat only the root user has permission to execute, SuSE on the ordinary user can.

-P parameter: queries the specified process load file according to the process number, which is often used to load the correct. So file in the Linux lookup process

[Email protected] ~]# Ps-fu XBH | grep test
XBH 25341 25261 0 22:22 pts/2 00:00:00/bin/sh./test.sh
[Email protected] ~]# lsof-p 25341
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
test.sh 25341 xbh cwd DIR 8,2 4096 2042485/home/xbh/test
test.sh 25341 xbh RTD DIR 8,3 4096 2/
test.sh 25341 xbh txt REG 8,3 735004 1849620/bin/bash
test.sh 25341 xbh mem REG 8,3 125736 2335717/lib/ld-2.5.so
test.sh 25341 xbh mem REG 8,3 1611564 2336488/lib/libc-2.5.so
test.sh 25341 xbh mem REG 8,3 16428 2336489/lib/libdl-2.5.so
...............
test.sh 25341 xbh 255r REG 8,2 2042498/home/xbh/test/test.sh
[Email protected] ~]# cat/home/xbh/test/test.sh
#!/bin/sh

While True
Do
echo "SSSs"
Sleep 3
Done

6. The awk command

The Linux command does not refer to awk,sed to explain or in the practiced hand phase, has not yet started.

-F parameter: Specifies the delimiter, field number starts from 1.

[Email protected] 1]$ CAT/ETC/PASSWD | Tail-n 1
vbird1: x:502:502::/home/vbird1:/bin/bash
[Email protected] 1]$ CAT/ETC/PASSWD | Tail-n 1 | Awk- F': ' {print ' Username: ' $ ' Shell: ' $7} '
Username:vbird1 Shell:/bin/bash

7. SED command

-N parameter: Do not display printing information,

[email protected] 1]$ cat 1.txt
Www.baidu.com
www.google.com
Www.*.com
[Email protected] 1]$ sed- n 's#Baidu#Chinese#p' 1.txt

Www.chinese.com

Where the P parameter is the printing of the current match information, the S flag is the replacement

-I parameter: persist the modifications to the file

[Email protected] 1]$ sed- i ' s#Baidu#Chinese# ' 1.txt
[email protected] 1]$ cat 1.txt
Www.chinese.com
www.google.com
Www.*.com

8.ipcs command

-M parameter: Shows only shared memory-related information.

[Email protected] 1]$ ipcs-m

------Shared Memory Segments--------
Key shmid owner perms bytes nattch Status
0x00000000 65536 xbh 393216 2 dest
0x00000000 98305 xbh 393216 2 dest
0x00000000 131074 xbh 393216 2 dest
0x00000000 163843 xbh 393216 2 dest
0x00000000 196612 xbh 393216 2 dest
0x00000000 229381 xbh 393216 2 dest
0x00000000 262150 xbh 393216 2 dest
0x00000000 294919 xbh 393216 2 dest
0x00000000 327688 xbh 393216 2 dest
0x00000000 360457 xbh 393216 2 dest
0x00000000 393226 xbh 393216 2 dest

-P parameter: Show shared memory related process information

[Email protected] 1]$ IPCS-MP

------Shared Memory Creator/last-op--------
Shmid owner cpid lpid
65536 xbh 2770 21373
98305 XBH 2772 2822
131074 XBH 2772 2822
163843 XBH 2803 2599
196612 XBH 2805 2599
229381 XBH 2863 2599
262150 XBH 2875 2599

Cpid is the process number that creates the shared memory, Lpid is the last PID, which is the process number that was recently attach to shared memory.

9. IPCRM command

-M parameter: Forces the deletion of shared memory according to Shmid.

[Email protected] 1]$ ipcs-m

------Shared Memory Segments--------
Key shmid owner perms bytes nattch Status
0x00000000 65536 xbh 393216 2 dest
0x00000000 98305 xbh 393216 2 dest
0x00000000 131074 xbh 393216 2 dest
0x00000000 163843 xbh 393216 2 dest
0x00000000 196612 xbh 393216 2 dest
0x00000000 229381 xbh 393216 2 dest
0x00000000 262150 xbh 393216 2 dest
0x00000000 294919 xbh 393216 2 dest
0x00000000 327688 xbh 393216 2 dest
0x00000000 360457 xbh 393216 2 dest
0x00000000 393226 xbh 393216 2 dest

The key is 0x00000, which indicates that the shared memory has been freed, but the process is not released because there is still attach to the shared memory on the system that has not exited. When all attach processes are exited, the shared memory is freed.

Nattch is the number of processes that are attach.

[[email protected] 1]$ Ipcrm- m 65536

Ten. Mount command

> mount-t cifs-o username=administrator,password=1//192.168.1.107/users/root/sne

Format: mount-t cifs-o usernmae=domainname/username,password=***** windows_dir linux_dir

Mount sometimes reported Alloc memory failed, this is because the files mounted in the Windows directory is too large, windows7 can not handle the reasons, need to modify the Win7 configuration, here do not describe.

One. Umount command

Umount The first case of failure : There are other endpoints occupying the directory to be unloaded

[Email protected] xbh]# Umount/root/sne
Unmount error = Device or resource busy
Refer to the Umount.cifs (8) manual page (mans 8 Umount.cifs)
Unmount error = Device or resource busy
Refer to the Umount.cifs (8) manual page (mans 8 Umount.cifs)
[Email protected] xbh]# fuser /root/sne
/root/sne: 5936C
[Email protected] xbh]# Ps-ef | grep 5936
Root 5936 5933 0 12:44 pts/1 00:00:00-bash

[Email protected] xbh]# kill-9 5936

Use the Fuser command to view the occupier process number of the Unload directory, and then use the PS command to get the corresponding process name, confirming that you can kill the process using the KILL command after you have deleted it directly.

The second scenario in which the uninstallation fails:

[Email protected] xbh]# Umount/root/sne
Unmount error = Device or resource busy
Refer to the Umount.cifs (8) manual page (mans 8 Umount.cifs)
Unmount error = Device or resource busy
Refer to the Umount.cifs (8) manual page (mans 8 Umount.cifs)
[Email protected] xbh]# Fuser/root/sne
[Email protected] xbh]# pwd
/root/sne/xbh

[[Email protected] xbh]# CD
[Email protected] ~]# pwd
/root

[Email protected] ~]# Umount/root/sne
[Email protected] ~]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda3 9.5G 3.3G 5.8G 37%/
/dev/sda2 9.5G 156M 8.9G 2%/Home
/DEV/SDA1 99M 12M 83M 12%/boot
Tmpfs 252M 0 252M 0%/dev/shm
/DEV/HDC 2.8G 2.8G 0 100%/media/rhel_5.4 i386 DVD

Continue to uninstall still error, use fuser do not see the occupation process, and then use the PWD command to see the directory in the Unload directory when the command is executed.

CD to the directory that is not the Unload directory, execute the umount command again successfully, and use Df-h to verify that the uninstallation was successful.

Summary of common commands under Linux

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.