Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands commonly used by Linux intermediate users

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the commands commonly used by Linux intermediate users", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "what commands are commonly used by Linux intermediate users".

21. Command: Find

Search for files in the specified directory, starting with the parent directory, and then search for subdirectories.

Root@tecmint:~# find-name *. Sh. / Desktop/load.sh. / Desktop/test.sh. / Desktop/shutdown.sh. / Binary/firefox/run-mozilla.sh. / Downloads/kdewebdev-3.5.8/admin/doxygen.sh. / Downloads/kdewebdev-3.5.8/admin/cvs.sh. / Downloads/kdewebdev-3.5.8/admin/ltmain.sh. / Downloads/wheezy-nv-install.sh

Note: the `- name' option is case sensitive. You can use the `- iname' option so that case can be ignored in the search. (* is a wildcard and can search all files; '.sh' you can use the file name or part of the file name to define the output.)

Root@tecmint:~# find-iname * .SH (find-iname * .Sh / find-iname * .sH). / Desktop/load.sh. / Desktop/test.sh. / Desktop/shutdown.sh. / Binary/firefox/run-mozilla.sh. / Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh. / Downloads/kdewebdev-3.5.8/admin/doxygen.sh. / Downloads/kdewebdev-3.5.8/admin/cvs.sh. / Downloads/kdewebdev- 3.5.8/admin/ltmain.sh. / Downloads/wheezy-nv-install.sh root@tecmint:~# find-name * .tar.gz / var/www/modules/update/tests/aaa_update_test.tar.gz. / var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz. / home/server/Downloads/drupal-7.22.tar.gz. / home/server/Downloads/smtp-7.x-1.0.tar.gz. / home/server/Downloads/noreqnewpass-7.x-1.2.tar.gz. / usr/share/gettext/archive.git.tar.gz. / usr/share/doc/apg/php.tar.gz. / usr/share/doc/festival/examples/speech_pm_1.0.tar.gz. / usr/share/doc/argyll/examples/spyder2.tar.gz. / usr/share/usb_modeswitch/configPack.tar.gz

Note: the above command looks for all files that contain 'tar.gz' in the root directory and all folders and subdirectories of the loaded device.

For more details on the find' command, please refer to 35 Find Command Examples in Linux

twenty-two。 Command: grep

The 'grep' command searches for lines in the specified file that contain a given string or word. Give an example to search for 'tecmint' in' / etc/passwd' file

Root@tecmint:~# grep tecmint / etc/passwd tecmint:x:1000:1000:Tecmint,:/home/tecmint:/bin/bash

Use the'- i' option to ignore case.

Root@tecmint:~# grep-I TECMINT / etc/passwd tecmint:x:1000:1000:Tecmint,:/home/tecmint:/bin/bash

Use the'- r 'option to recursively search for all self-contained strings "127.0.0.1". It's okay.

Root@tecmint:~# grep-r "127.0.0.1" / etc/ / etc/vlc/lua/http/.hosts:127.0.0.1 / etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1" / etc/mysql/my.cnf:bind-address = 127.0.0.1 / etc/apache2/mods-available/status.conf: Allow from 127.0.0.1:: 1 / etc/apache2 / mods-available/ldap.conf: Allow from 127.0.0.1:: 1 / etc/apache2/mods-available/info.conf: Allow from 127.0.0.1:: 1 / etc/apache2/mods-available/proxy_balancer.conf:# Allow from 127.0.0.1:: 1 / etc/security/access.conf:#+: root: 127.0.0.1 / etc/dhcp/dhclient.conf:#prepend domain-name-servers 127.0.0.1 / etc/dhcp/dhclient.conf:# option domain-name-servers 127.0.0.1; / etc/init/network-interface.conf: ifconfig lo 127.0.0.1 up | | true / etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). / etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost | 127.0.0.1 / etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1). / etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost | 127.0.0.1 / etc/hosts:127.0.0.1 localhost

Note: you can also use the following options:

-w search word (egrep-w 'word1 | word2' / path/to/file).

-c is used to count the rows that meet the requirements (i.e., total number of times the pattern matched) (grep-c 'word' / path/to/file).

-color color output (grep-color server / etc/passwd).

23. Command: man

'man' is the system help page. Man provides online documentation of all options and usage of the command. Almost all commands have their help pages, such as:

Root@tecmint:~# man man MAN (1) Manual pager utils MAN (1) NAME man-an interface to the on-line reference manuals SYNOPSIS man [- C file] [- d] [- D] [--warnings [= warnings]] [- R encoding] [- L locale] [- m system [ [- M path] [- S list] [- e extension] [- I |-I] [--regex |-- wildcard] [--names-only] [- a] [- u] [--no-subpages] [- P pager] [- r prompt] [- 7] [- E encoding] [--no-hyphenation] [--no-justification] [- p string] [- t] [- T] Device]] [- H [browser]] [- X [dpi]] [- Z] [[section] page...]. Man-k [apropos options] regexp... Man-K [- w |-W] [- S list] [- I |-I] [--regex] [section] term... Man-f [whatis options] page... Man-l [- C file] [- d] [- D] [--warnings [= warnings]] [- R encoding] [- L locale] [- P pager] [- r prompt] [- 7] [- E encoding] [- p string] [- t] [- T [device]] [- H [browser]] [- X [dpi]] [- Z] file... Man-w |-W [- C file] [- d] [- D] page. Man-c [- C file] [- d] [- D] page... Man [- hV]

Above is the system help page for the man command, similar to the help pages for cat and ls.

Note: the system help page is designed for command use and learning.

24. Command: ps

The ps command gives the status of a running process, and each process has a specific id that becomes a PID.

Root@tecmint:~# ps PID TTY TIME CMD 4170 pts/1 00:00:00 bash 9628 pts/1 00:00:00 ps

Use the'- A 'option to list all processes and their PID.

Root@tecmint:~# ps-A PID TTY TIME CMD 1? 00:00:01 init 2? 00:00:00 kthreadd 3? 00:00:01 ksoftirqd/0 5? 00:00:00 kworker/0:0H 7? 00:00:00 kworker/u:0H 8? 00:00:00 migration/0 9? 00:00:00 rcu_bh.

Note: the ps command is useful when you want to know which processes are running or need to know the PID of the process you want to kill. You can use it with 'grep' to query the specified output, for example:

Root@tecmint:~# ps-A | grep-I ssh 1500? 00:09:58 sshd 4317? 00:00:00 sshd

The ps command and the grep command can be split with pipe lines to get the results we want.

25. Command: kill

You may have guessed what to do from the name of the command, kill is used to kill processes that are irrelevant or unresponsive. It is a very useful command, not a very useful command. You may be familiar with the fact that in order to kill a process under Windows, you may need to restart the machine frequently because a running process cannot be killed in most cases, and even if you kill a process, you need to restart the operating system to take effect. But in the linux environment, this is not the case. You can kill a process and restart it instead of restarting the entire operating system.

To kill a process, you need to know its PID.

Suppose you want to kill the 'apache2' process that is no longer responding, run the following command:

Root@tecmint:~# ps-A | grep-I apache2 1285? 00:00:00 apache2

Search the 'apache2' process, find PID and kill it. For example, in this example, the PID of the 'apache2' process is 1285.

Root@tecmint:~# kill 1285 (to kill the process apache2)

Note: every time you rerun a process or start the system, each process generates a new PID. You can use the ps command to get the PID of the currently running process.

Another way to kill a process is:

Root@tecmint:~# pkill apache2

Note: kill requires PID as a parameter, and pkill can choose how to apply it, such as specifying the owner of the process.

twenty-six。 Command: whereis

The function of whereis is to locate the binary file\ resource\ or help page of the command. For example, get the binaries / resources and help pages for the ls and kill commands:

Root@tecmint:~# whereis ls ls: / bin/ls / usr/share/man/man1/ls.1.gz root@tecmint:~# whereis kill kill: / bin/kill / usr/share/man/man2/kill.2.gz / usr/share/man/man1/kill.1.gz

Note: it is useful when you need to know where the binaries are saved.

twenty-seven。 Command: service

The service' command controls the start, stop, and restart of a service, which allows you to enable the configuration to start, stop, or restart a service without restarting the entire system.

Start apache2 server on Ubuntu:

Root@tecmint:~# service apache2 start * Starting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName httpd (pid 1285) already running [OK]

Restart apache2 server:

Root@tecmint:~# service apache2 restart * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName... Waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [OK]

Stop apache2 server:

Root@tecmint:~# service apache2 stop * Stopping web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName... Waiting [OK]

Note: to use the service command, the script for the process must be placed at'/ etc/init.d', and the path must be in the specified location.

If you want to run "service apache2 start", you actually execute "service / etc/init.d/apache2 start".

twenty-eight。 Command: alias

Alias is a system-built shell command that allows you to specify aliases for commands with long names or frequently used commands.

I often use the'ls-l 'command, which has five characters (including spaces). So I created an alias'l' for it.

Root@tecmint:~# alias l='ls-l'

See if it works:

Root@tecmint:~# l total 36 drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Music drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Public drwxr-xr-x 2 Tecmint tecmint 4096 May 7 16:58 Templates drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Videos

To remove the'l' alias, use the unalias command:

Root@tecmint:~# unalias l

Try again:

Root@tecmint:~# l bash: l: command not found

As a joke, designate the alias of an important command as another important command:

Alias cd='ls-l' (set alias of ls-l to cd) alias su='pwd' (set alias of pwd to su).... (You can create your own).

Think about how interesting it is. Now if your friend types in the 'cd' command, he sees a list of directory files instead of changing the directory; when he tries to use the' su' command, he enters the current directory. You can then remove the alias and explain the above situation to him.

twenty-nine。 Command: df

Report the disk usage of the system. It is useful for both ordinary users and system administrators in tracking disk usage. 'df' works by checking the directory size, but this value is updated only when the file is closed.

Root@tecmint:~# df Filesystem 1K-blocks Used Available Use% Mounted on / dev/sda1 47929224 7811908 37675948 18% / none 4 040% / sys/fs/cgroup udev 1005916 4 10059121% / dev tmpfs 202824 816 202008 1% / run none 5120 05120 1013492 / run/lock none 1014120 628 1% / run/shm none 102400 44 102356 1% / run/user / dev/sda5 184307 79852 94727 46% / boot / dev/sda7 95989516 61104 91045676 1% / data / dev/sda8 91953192 57032 872185281% / personal

For more examples of the df' command, see 12 df Command Examples in Linux.

thirty。 Command: du

Estimate the space footprint of the file. Count files layer by layer (for example, recursively) and output a summary.

Root@tecmint:~# du 8. / Daily Pics/wp-polls/images/default_gradient 8. / Daily Pics/wp-polls/images/default 32. / Daily Pics/wp-polls/images 8. / Daily Pics/wp-polls/tinymce/plugins/polls/langs 8. / Daily Pics/wp-polls/tinymce/plugins/polls/img 28. / Daily Pics/wp-polls/tinymce/plugins/polls 32. / Daily Pics/wp-polls/tinymce/plugins 36. / Daily Pics/wp-polls/tinymce 580. / Daily Pics/wp-polls 1456. / Daily Pics 36. / Plugins/wordpress-author-box 16180. / Plugins 12. / May Articles 2013/Xtreme Download Manager 4632. / May Articles 2013/XCache

Note: 'df' only displays the usage statistics of the file system, but' du' counts the directory contents. For more details on the du' command, see 10 du (Disk Usage) Commands.

thirty-one。 Command: rm

'The rm' standard remove command. Rm can be used to delete files and directories.

Delete the directory:

Root@tecmint:~# rm PassportApplicationForm_Main_English_V1.0 rm: cannot remove `PassportApplicationForm_Main_English_V1.0': Is a directory

Rm' cannot delete a directory directly. You need to add the corresponding'- rf' parameter.

Root@tecmint:~# rm-rf PassportApplicationForm_Main_English_V1.0

Warning: the rm-rf command is a destructive command if you accidentally delete the wrong directory. Once you use'rm-rf''to delete a directory, all files in the directory, including the directory itself, will be deleted, so use this command very carefully.

thirty-two。 Command: echo

The function of echo, as its name suggests, is to print a piece of text based on standard output. It has nothing to do with shell, and shell does not read what is printed through the echo command. In an interactive script, however, echo passes information to the user through the terminal. It is a command that is often used in scripting and interactive scripting languages.

Root@tecmint:~# echo "Tecmint.com is a very good website" Tecmint.com is a very good website

Create a short interactive script

1. Create a new file on your desktop and name it interactive_shell.sh' (remember that you must have the extension '.sh').

two。 Copy and paste the following script code to make sure it is consistent with the following.

#! / bin/bash echo "Please enter your name:" read name echo "Welcome to Linux $name"

Next, set the execution permissions and run the script.

Root@tecmint:~# chmod 777 interactive_shell.sh root@tecmint:~#. / interactive_shell.sh Please enter your name: Ravi Saive Welcome to Linux Ravi Saive

Note:'#! / bin/bash' tells shell that this is a script, and it's a good habit to write this on the first line of the script. . 'read' reads the given output.

thirty-three。 Command: passwd

This is a very important command, and it is useful to change your password in the terminal. Obviously, for security reasons, you need to know the current password.

Root@tecmint:~# passwd Changing password for tecmint. (current) UNIX password: * Enter new UNIX password: * Retype new UNIX password: *

Password unchanged [indicates that the password has not changed, for example: new password = old password]

Enter new UNIX password:# Retype new UNIX password:#

thirty-four。 Command: lpr

This command is used to print the specified file on the specified printer on the command line.

Root@tecmint:~# lpr-P deskjet-4620-series 1-final.pdf

Note: the "lpq" command allows you to check the status of the printer (whether it is on or off) and the status of work (files) waiting to be printed.

thirty-five。 Command: cmp

Compare two files of any type and output the results to standard output. If the two files are the same, 'cmp' returns 0 by default; if different, different bytes and different locations at * * will be displayed.

Take the following two files as examples:

File1.txt root@tecmint:~# cat file1.txt Hi My name is Tecmint file2.txt root@tecmint:~# cat file2.txt Hi My name is tecmint [dot] com

Compare the two files to see the output of the command.

Root@tecmint:~# cmp file1.txt file2.txt file1.txt file2.txt differ: byte 15, line 1

thirty-six。 Command: wget

Wget is a free tool for non-interactive (such as background) downloading files. Supports HTTP, HTTPS, FTP protocols and HTTP proxies.

Download ffmpeg using wget

View sourceprint? Root@tecmint:~# wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2-2013-05-22 18 Resolving downloads.sourceforge.net 54 Resolving downloads.sourceforge.net 52 Resolving downloads.sourceforge.net (downloads.sourceforge.net). 216.34.181.59 Connecting to downloads.sourceforge.net (downloads.sourceforge.net) | 216.34.181.59 |: 80. Connected. HTTP request sent, awaiting response... 302 Found Location: http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 [following]-- 2013-05-22 18 Resolving kaz.dl.sourceforge.net 54 following-http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 Resolving kaz.dl.sourceforge.net (kaz.dl.sourceforge.net). 92.46.53.163 Connecting to kaz.dl.sourceforge.net (kaz.dl.sourceforge.net) | 92.46.53.163 |: 80. Connected. HTTP request sent, awaiting response... 200 OK Length: 275557 (269K) [application/octet-stream] Saving to: 'ffmpeg-php-0.6.0.tbz2' 75557 67.8KB/s in 4.0s 2013-05-22 18:55:00 (67.8KB/s) -' ffmpeg-php-0.6.0.tbz2' saved [275557 ffmpeg-php-0.6.0.tbz2' saved 275557]

37 Command: mount

Mount is a very important command for mounting file systems that cannot be mounted automatically. You need root permission to mount the device.

After plugging in your file system, first run the "lsblk" command to identify your device, and then write down the assigned device name.

Root@tecmint:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk ├─ sda1 8:1 0 923.6G 0 part / ├─ sda2 8:2 0 1K 0 part └─ sda5 8:5 0 7.9G 0 part [SWAP] sr0 11:0 1 1024M 0 rom sdb 8:16 1 3.7G 0 disk └─ sdb1 8:17 1 3.7G 0 part

From this output, it is obvious that I plugged in the 4GB flash drive, so "sdb1" is the file system to be mounted. Operate as the root user, then change to the / dev directory, which is where all file systems are mounted.

Root@tecmint:~# su

Password:

Root@tecmint:~# cd / dev

Create a directory with any name, but * is related to references.

Root@tecmint:~# mkdir usb

Now mount the "sdb1" file system to the "usb" directory.

Root@tecmint:~# mount / dev/sdb1 / dev/usb

You can now access files from the terminal to / dev/usb or from the mount directory through the X window system.

It's time for programmers to see how rich the Linux environment is!

thirty-eight。 Command: gcc

Gcc is the built-in compiler of C language in Linux environment. The following is a simple C program that is saved as Hello.c on the desktop (remember that there must be a'.c 'extension).

# include int main () {printf ("Hello world\ n"); return 0;}

Compile:

Root@tecmint:~# gcc Hello.c

Run:

Root@tecmint:~#. / a.out Hello world

Note: when compiling a C program, the output is automatically saved to a new file called "a.out", so the "a.out" of the compiled C program is modified each time. Therefore, during compilation, * * defines the output file name, so there is no risk of overwriting the output file.

Compile in this way:

Root@tecmint:~# gcc-o Hello Hello.c

Here the'- o 'writes the output to the' Hello' file 'instead of' a.out'. Run it again.

Root@tecmint:~#. / Hello Hello world

thirty-nine。 Command: Gmail +

Gmail + is the built-in compiler for C++. The following is a simple C++ program that is saved as Add.cpp on the desktop (remember that you must have a '.cpp' extension).

# include using namespace std; int main () {int a; int b; cout a; cout b; cin.ignore (); int result = a + b; cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report