1. File and Directory Commands
1. View online help information
man command, for example: #man ls
info command, for example: #info cd
2. List file names and directory names in the current directory or a specified directory
ls [options] file or directory
Common [options] are as follows:
-a: Display all files, including hidden files starting with “.”.
-l: Long format output
-m: Wide-line output
-F: Use various symbols to indicate different file types
–color: Color output
-R: Recursive output
3. touch
Function: Modify a file’s creation date, or create an empty file using the current system date.
-d: Modify the file’s date.
#touch –d 20030123 test.txt
4. cp
Function: Copy files
Usage: cp [options] source file or directory target file or directory
Options:
a:
This option is usually used when copying directories. It preserves links and file attributes, and recursively copies directories. Its effect is equivalent to the combination of the dpR options.
– d Preserve links when copying.
– f Delete an existing target file without prompting.
– i
Opposite to the f option, this prompts the user for confirmation before overwriting the target file. If the answer is y, the target file will be overwritten; this is interactive copying.
– p
In this case, in addition to copying the contents of the source file, cp also copies its modification time and access permissions to the new file.
– r
If the given source file is a directory, cp will recursively copy all subdirectories and files under that directory. In this case, the target file must be a directory name.
5. mv
Function: Rename a file or directory, or move a file or directory to another directory
Usage: mv [options] source file or directory target file or directory
-i
Interactive operation. If the mv operation would overwrite an existing target file, the system asks whether to overwrite it and requires the user to answer y or n, which can prevent accidental overwriting of files.
– f
Disable interactive operation. When mv is about to overwrite an existing target file, no prompt is given. After this option is specified, the i option no longer takes effect.
6. rm
Function: Delete files or directories
Usage: rm [options] file…
– f Force deletion
– r
Instructs rm to recursively delete all directories and subdirectories listed in the parameters.
– i Perform interactive deletion
7. cd
Function: Change the working directory.
Syntax: cd [directory]
Usage:
#cd .. Return to the previous-level directory
#cd ~ Enter your home directory
8. pwd
Function: Display the current working directory
Usage: #pwd
9. mkdir
Function: create a directory (similar to the md command in MSDOS).
Syntax: mkdir [options] dir-name
– m
Set access permissions for the newly created directory. You can also use the chmod command to set them.
– p
It can be a path name. If some directories in the path do not yet exist,
after adding this option,
the system will automatically create those directories that do not yet exist, so multiple directories can be created at one time.
#mkdir –m a=rwx test
#mkdir –m u=rwx,g=rx,o=rx test1
#mkdir –m 755 test2
#mkdir –p test3/test4 (both test3 and test4 are new directories)
10. rmdir
Function: delete an empty directory.
Syntax: rmdir [options] dir-name
– p
Recursively delete the directory dirname. After a subdirectory is deleted, if its parent directory is empty, it will also be deleted.
11. file
Function: view the file type
Syntax: file filename
12. cat
Function: view the contents of a text file
Syntax: cat filename
13. more
Function: display the contents of a text file one screen at a time.
14. less
Function: display the contents of a text file; you can use pageup and pagedown to scroll up and down through the pages.
15. head
Function: view the beginning part of a file
Syntax: head [number of lines] filename
Usage: #head test.txt: displays the first 10 lines
#head -20 test.txt displays the first 20 lines.
16. tail
Function: view the ending part of a file.
Syntax: tail [number of lines] filename
The default number of lines is 10.
17. sort
Function: sort the lines in a text file
Usage: sort filename
Example: #sort 123.txt >456.txt
Sort 123.txt and redirect the output to the file 456.txt.
18. uniq
Function: remove duplicate lines from the output file, leaving only the unique instance of each record
Syntax: uniq filename
#uniq outputs 456.txt after removing duplicate lines
19. pr
Function: process files for printing and output to standard output
Syntax: pr [parameters] file list
[parameters]
-d: add a new blank line after each output line
-n: output line numbers
For example: #pr –n 123.txt
20, ln
Function: create link files
Syntax: ls [-s] source filename target filename
Description: Link files are divided into hard links and soft links. A hard link is equivalent to one data source having two filenames; if one file is deleted, the other remains unchanged, and if the contents of one file are modified, the contents of the other file change as well. Hard
links cannot be linked to another directory, nor can they be linked to files on other file systems. A soft link is equivalent to a shortcut and does not have the above restrictions; add the -s parameter to create a soft link.
21, wc
Function: count the number of lines, characters, and words in a file.
Syntax: wc [-lwc] filename
-l: display only the number of lines, -w: display only the number of words, -c: display only the total number of characters.
22, whatis
Function: display a description of the keyword entered after the command line in a single line.
Syntax: whatis keyword
Usage: #whatis find whereis
23, Whereis
Function: determine the location of the source program/binary program and manual section for the specified file.
Usage: #whereis ls
24, which
Function: display the path of an executable command and its alias.
Usage: #which ls
25, locate
Function: find the path of a specific file or command, and search for a specific string or substring
Usage: locate filename or keyword
26, du
Function: calculate the disk space used by files and directories
Syntax: du [-ask] filename or directory name
-a: display statistics for all files involved, not just directories
-s: print only the total
-k: display in kB
Find usage examples
find . -name ls.txt
find . -name ls.txt –print
find / -name ‘c??’ –print
find / -name ‘f*’ –print
find . -name ‘f*’ –exec ls –l {} /;
find . -name f/* –ok rm {} /; (interactive prompt)
find . -perm 644 –mtime 4
find . -name ‘c??’ –o -name ‘d??’
28, grep
Function: search for matching lines in a file and output them
Syntax: grep [parameters]<string to search for><original file>
-num: output num lines before and after each matching line
-A num: output num lines after each matching line
-B num: output num lines before each matching line
-i: ignore case differences
-v: display only those lines and files that do not include a certain string, the opposite of the default
II. File compression and archiving commands
1, gzip
Function: a compression program whose feature is that it can achieve the best compression ratio, but it is slower.
Syntax: gzip [-vd9] filename
-v: verbose option, can display the size of each file, etc.
-d: decompress
-9: produces the best compression effect, but at a slower speed.
2. gunzip
Function: can decompress compressed files back to their original state, and can decompress compressed files with extensions such as .gz, .z, .Z, and .tgz
Syntax: gunzip [-v] filename
-v: display verbose results for decompressed files
3. tar
Function: can archive multiple files and directories into a single .tar file, and can also extract a file or directory from an archive file.
Syntax: tar [-c][-r][-t][-x][-v][-z][f filename]
file and directory names
-c: create an archive file
-r: add files to the archive file
-t: view files in the archive file
-x: extract the archive file
-v: display verbose information
-z: perform compression and decompression
For example: #tar –cvf back.tar file1 directory1 file2
#tar –rvf back.tar file3
#tar –tf back.tar
#tar –xvf back.tar
#tar –czvf back.tar.gz file1 directory1 file2
#tar –xzvf back.tar.gz
4. Install software provided in rpm format
Rpm(the red hat package
manager) is an open package management system.
Function: can install and uninstall software in RPM packages
#rpm –ivh *.rpm install an RPM package;
#rpm –ivh –force *.rpm
force installation again on top of the original installation;
#rpm –Uvh *.rpm upgrade an rpm package
#rpm –qa find and list all installed rpm packages in the system
#rpm –q sendmail: view information about the sendmail package
#rpm –ql sendmail: view the installation location of sendmail
#rpm –e *.rpm uninstall an rpm package
#rpm – qlp name.rpm view what files are in name.rpm
#rpm – qf name.rpm
view which rpm package an already installed file belongs to
#rpm2cpio filename.rpm use “rpm2cpio” to extract files from an RPM document
5. Install software provided in source code form
(1) Unpack and decompress:
#tar –xzvf *.tar.gz
After unpacking and decompressing, a subdirectory will be created in the current directory, such as xxxx
(2) #cd xxxx
(3) #./configure
(4) #make
(5) #make install
III. System status commands
1. dmesg
Function: displays the status information shown by the kernel during boot
#dmesg |grep -4
“eth0” displays the 4 lines before and after the content related to eth0 in the status information
2. uname
Function: displays current system information
#uname -a
3. uptime
Function: displays the current time, how long the system has been running since the last reboot, how many users are connected to the server, and the system load information for the past 1, 5, and 15 minutes.
4. who (explained in detail later)
Function: displays information about users currently logged in to the system.
-r: view the system run level
-w: displays a character after the login account to indicate the user’s information status:
+: writing messages is allowed; -: writing messages is not allowed; ?: terminal device cannot be found
5. w
Function: view other logged-in users (enhanced version of who)
First line output: current time, time since system startup, number of logged-in users, and the system average load over the last 1, 5, and 15 seconds
Second line output: login account, terminal name, remote host name, login time, idle time, JCPU, PCPU, and the command line of the currently running process.
*JCPU time refers to the time consumed by all processes connected to that terminal (tty)
*PCPU time refers to the time consumed by the current process (that is, the process shown in the WHAT field)
6. whoami
Function: displays the current username
7. hostname
Function: displays the system hostname
8. cal [month] [year]
Function: displays the calendar
9. bc
Function: calculator; use quit to exit
10. date
Function: displays or modifies the date and time.
11. df
Function: reports file system disk space usage
Syntax: df[parameters]
[parameters]
-h: displays sizes in a human-readable format (for example: 1K, 23M, 2G, etc.)
-t: displays only the specified type of file system
12. free
Function: view current memory and swap space usage
IV. Network Commands
1. write
Function: sends a message to another user; use Ctrl+D to end. Messages sent by ordinary users are affected by mesg status.
Syntax: write <username>
2. wall
Function: broadcasts a message to all users; ordinary users are affected by mesg status.
Syntax: wall [message]
3. mesg
Function: displays or sets whether to accept messages sent by other users.
Syntax: mesg [parameters]
[parameters]
y: accept messages sent by other users
n: do not accept messages sent by other users
#mesg
Displays whether messages from other users are currently being accepted
4. ping
Function: confirms network connectivity by checking response information from other hosts on the network.
Syntax: ping [parameters] hostname (or IP address)
Parameters:
-c count: sends a total of count messages.
-R: displays detailed routing table information
5. telnet
Function: remote login
Syntax: telnet [<hostname>][:port number]
6. ifconfig
Function: configure network interfaces
Syntax:
ifconfig [interface] [up][down][netmask mask]
#ifconfig
#ifconfig eth0 192.168.0.3 netmask 255.255.255.0 up
7. netstat
Function: display the network connection status of the local system
Syntax: netstat [-a][-r][-c][-i]
-a: display all network connections in the local system
-r: display the routing table
-c: display continuous network connection status
-i: display all network interface information.
8. ftp
Function: file transfer
Syntax: ftp [<hostname>]
Subcommands:
?: list all FTP commands;
pwd: display the current directory on the remote host
lcd: switch to and display the current directory on the local host
ls: list the contents of the current directory on the remote host
!dir: list the contents of the current directory on the local host
cd: switch the directory on the remote host
get: download a file
mget: download files in batches
put: upload a file
mput: upload files in batches
prompt: whether to use interactive prompting when using mget and mput
bye: terminate an FTP connection
open: open an FTP connection
close: close an FTP connection
binary: transfer in binary mode
ascii: transfer in ascii mode
type: view the transfer mode
V. Others
passwd
1. Purpose
The passwd command is used to change the login password of an account, and all users have permission to use it.
2. Format
passwd [options] account name
3. Main parameters
-l: lock the named account; only users with superuser privileges may use this option.
-u: unlock the account; only users with superuser privileges may use this option.
-x,
–maximum=DAYS: maximum password lifetime (days); only users with superuser privileges may use this option.
-n,
–minimum=DAYS: minimum password lifetime (days); only users with superuser privileges may use this option.
-d: delete the user’s password,
only users with superuser privileges may use this option.
-S: check the password authentication type of the specified user,
only users with superuser privileges may use this option.
4. Application examples
$ passwd
Changing password for user cao.
Changing password for cao
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
As can be seen above, using the passwd command requires entering the old password first, and then entering the new password twice.
su
1.Function
The function of su is to switch to another user’s identity. Except for the superuser, you need to enter that user’s password.
2.Format
su [options]… [-] [USER [ARG]…]
3.Main parameters
-f, –fast: No need to read startup files (such as csh.cshrc
and others); only used with the csh or tcsh Shell.
-l,
–login: After adding this parameter, it is as if you are logging in again as that user. Most environment variables
(such as HOME, SHELL, and USER) will be based on that user (USER), and the working directory will also change. If USER is not specified, the default is root.
-m, -p
,–preserve-environment: Do not change environment variables when executing su.
-c
command: Switch the account to USER, execute the command, and then switch back to the original user.
USER: The user account to switch to; ARG passes parameters to the new Shell.
4.Application example
Switch the account to the superuser, and restore the original user after executing the df command. su -c df
root
umask
1.Function
umask sets the default file creation mask value for user files and directories. If this command is placed in the profile file, it can control the access permissions of files subsequently created by that user. It tells the system who should not be granted access permissions when creating files. It can be used by all users.
2.Format
umask [-p] [-S] [mode]
3.Parameters
-S: Determine the current umask setting.
-p: Modify the umask setting.
[mode]: Modify the value.
4.Description
The traditional Unix umask value is 022, which prevents other users in the same group and users in other groups from modifying that user’s files. Since each
user owns and belongs to a private group of their own, this “group protection mode” is no longer needed. Strict permission settings form the foundation of Linux security, and mistakes in permissions are fatal. It should be
noted that the umask command is used to set the read and write permissions of files created by a process. The safest value is 0077, which disables read and write permissions for all processes other than the one creating the file, shown as -rw—
—-. Adding the command umask
0077 to ~/.bash_profile can ensure that each time the Shell starts, the process’s
umask permissions are correctly set.
5.Application example
umask -S
u=rwx,g=rx,o=rx
umask -p 177
umask -S
u=rw,g=,o=
The above 5 lines of commands first display the current status, then change the umask value to 177. As a result, only the file owner has permission to read and write the file, and other users cannot access it. This is obviously a very secure setting.
chgrp
1.Function
chgrp means changing the group ownership of one or more files or directories. Permission to use it is restricted to the superuser.
2.Format
chgrp [options]… group file…
or
chgrp [options]… –reference=reference file file…
Set the group ownership of each <file> to <group>.
3.Parameters
-c, –changes: Like
–verbose, but displays results only when changes are made.
–dereference: Affects the object pointed to by a symbolic link, rather than the symbolic link itself.
-h,
–no-dereference: Affects the symbolic link itself, rather than the destination pointed to by the symbolic link (this option is valid only on systems that support changing the owner of a symbolic link).
-f, –silent, –quiet: Suppresses most error messages.
–reference=reference file: Use the group ownership of <reference file> instead of the specified <group>.
-R, –recursive: Recursively process all files and subdirectories.
-v, –verbose: Display information when processing any file.
4.Application notes
This command changes the group ownership of the specified files. Here, group can be either a user group ID or the group name of a user group in the /etc/group file. The filenames are a space-separated list of files whose group ownership is to be changed, and wildcards are supported. If the user is not the owner of the file or the superuser, the user cannot change the file’s group.
5.Application example
Change the group ownership of all files under /opt/local
/book/ and its subdirectories to book. The command is as follows:
$ chgrp – R book /opt/local /book
chmod
Chmod usage format:
Chmod [parameters][mode]<file or directory>
Parameters: -R: Change the file permissions of a directory and all its subdirectories.
Example:
#chmod u+x inittab
#chmod ug+wx,o-x inittab
#chmod 0644 inittab
#chmod 0755 inittab
#chmod –R 700 ~
Additional notes on directory permissions:
1. Read-only access to a directory does not allow you to use cd to enter it; execute permission is required to enter.
2. With execute permission only, you can enter a directory but cannot see its contents. To see the filenames and directory names inside it, you need read permission.
3. Whether a file can be deleted mainly depends on whether the directory containing the file grants write permission to the user. If the directory does not grant write permission to the user, then none of the files under that directory can be deleted, except by the file owner.
Examples explaining special permission bits:
Operating on these special bits uses the same command as operating on file permissions, namely chmod.
There are two ways to do it. 1) chmod u+s temp:
adds the setuid flag to the temp file. (setuid applies only to files) chmod g+s
tempdir:
adds the setgid flag to the tempdir directory (setgid
applies only to directories) chmod o+t tempdir:
adds the sticky flag to the temp file (sticky applies only to directories)
2) Use octal notation. For ordinary files, flags are set using three groups of octal digits,
such as 666, 777, 644, etc. If these special flags are set,
then an additional group of octal digits is added before these numbers. For example, 4666, 2777, etc.
After setting these flags, you can use ls -l to check them. If these flags are present,
they will be displayed in the original execute-flag positions. For example, rwsrw-r–
indicates the setuid flag, rwxrwsrw- indicates the setgid flag, and rwxrw-rwt
indicates the sticky flag. So where did the original execute flag x go?
The system defines it this way: if there was originally an x in that position,
then these special flags are shown as lowercase letters (s, s, t). Otherwise,
they are shown as uppercase letters (S, S, T).
1. Function
The chmod command is very important. It is used to change the access permissions of files or directories. Users can use it to control access permissions for files or directories. Permission to use it belongs to the superuser.
2. Format
The chmod command has two forms of usage. One is the symbolic method using letters and operator expressions (relative permission setting); the other is the numeric method using numbers (absolute permission setting).
(1) Symbolic method
chmod [who] [+ | – | =] [mode] filename
◆The target object who can be any one of the following letters or a combination of them
u: represents the user, that is, the owner of the file or directory.
g: represents group users, that is, all users with the same group ID as the file owner.
o: represents other users.
a: represents all users; this is the system default.
◆Operators
+: adds a permission.
-: removes a permission.
=: assigns the given permission and removes all other permissions (if any).
◆The permissions for mode can be any combination of the following letters
r: readable.
w: writable.
x: executable.
X: add the x attribute only if the target file is executable for some users or if the target file is a directory.
s: when the file is executed, set the process owner or group ID to that of the file owner. The form “u+s” sets the user ID bit for the file, and “g+s” sets the group ID bit.
t: saves the program text on the swap device.
u: has the same permissions as the file owner.
g: has the same permissions as users in the same group as the file owner.
o: has the same permissions as other users.
filename: a space-separated list of files whose permissions are to be changed; wildcards are supported.
Multiple permission modes can be given in a single command line, separated by commas.
(2) Numeric method
The general form of the numeric method is: chmod [mode] filename
The numeric attribute format should be 3 octal digits from 0 to 7, in the order (u)(g)(o), followed by a space-separated list of files whose permissions are to be changed; wildcards are supported.
The meanings of permissions represented by numbers are as follows: 0001 is the owner’s execute permission; 0002 is the owner’s write permission; 0004 is the owner’s read permission;
0010 is the group’s execute permission; 0020 is the group’s write permission; 0040 is the group’s read permission; 0100 is others’ execute permission; 0200 is others’ write permission; 0400 is others’ read permission;
1000 is the sticky bit; 2000 means that if this file is an executable file, then the group ID bit is set; otherwise it is the file locking bit; 4000 means that if this file is an executable file,
then the user ID bit is set.
3. Example
If a system administrator creates a form (tem) for all users to fill out, then users must be granted read and write permissions for this file. You can use the command: #chmod
666 tem
In the code above, how is the number 666 calculated? 0002 is the owner’s write permission, 0004 is the owner’s read permission, 0020 is the
group’s write permission, 0040 is the group’s read permission, 0200 is others’ write permission, and 0400 is others’ read permission. Adding these 6 numbers gives 666 (note that the above numbers are all octal), as shown
in Figure 1.
Figure 1 Setting file permissions with the chmod numeric method
As can be seen from Figure 1, the permissions of the tem file are -rw-rw-rw-, meaning that users have read and write permissions for this file.
If character permissions are used instead, use the following command:
#chmod a =wx tem
chown
1. Function
Change the owner and group of one or more files or directories. Requires superuser privileges.
2. Format
chown [options] user or group file
3. Main parameters
–dereference: affects the object indicated by the symbolic link, not the symbolic link itself.
-h,
–no-dereference: affects the symbolic link itself, not the destination indicated by the symbolic link (this option is valid only when the system supports changing the owner of a symbolic link).
–from=current owner:current group changes the owner and group only when each file’s owner and group match those specified by the option. One of them may be omitted, and the omitted attribute does not need to match the original attribute.
-f, –silent, –quiet: suppress most error messages.
-R, –recursive: recursively process all files and subdirectories.
-v, –verbose: display information for every file processed.
4. Description
chown changes the owner of the specified file to the specified user or group. The user can be a username or user ID; the group can be a group name or group ID; the files are a space-
separated list of files whose permissions are to be changed, and wildcards are supported. System administrators often use the chown command so that after copying a file into another user’s directory, the user will have permission to use that file.
5. Application examples
1. Change the owner of the file shiyan.c to wan
$ chown wan shiyan.c
2. Change the owner of the directory /hi and all files and subdirectories under it to wan, and change the group to users.
$ chown – R wan.users /hi
chattr
1. Function
Modify ext2 and ext3 file system attributes, with superuser privileges required.
2.Syntax
chattr [-RV] [-+=AacDdijsSu] [-v version] file or directory
3.Main parameters
-R: Recursively process all files and subdirectories.
-V: Display the changes in detail and print the output.
-: Disable attributes.
+: Enable attributes.
= : Specify attributes.
A: Atime, tells the system not to modify the last access time of this file.
S: Sync, once an application performs a write operation on this file, the system immediately writes the modified result to disk.
a: Append
Only, the system allows data to be appended only after this file, and does not allow any process to overwrite or truncate this file. If a directory has this attribute, the system will only allow files to be created and modified in this directory, and will not allow any files to be deleted.
i: Immutable, the system does not allow any modifications to this file. If a directory has this attribute, then any process can only modify files under the directory, and is not allowed to create or delete files.
D: Check for errors in compressed files.
d: No
dump, when performing a file system backup, the dump program will ignore this file.
C: Compress, the system compresses this file transparently. When reading from this file, the returned data is the decompressed data; when writing data to this file, the data is first compressed before being written to disk.
s: Secure
Delete, when deleting this file, the system uses 0s to fill the area where the file is located.
u: Undelete, when an application requests deletion of this file, the system will retain its data blocks so that the deleted file can be recovered later.
4.Description
The chattr command is very powerful, and some of its functions are supported by the linux kernel version. If the Linux kernel version is lower than 2.2, then
many functions cannot be implemented. Likewise, the -D function for checking errors in compressed files requires kernel version 2.5.19 or above. In addition, modifying attributes with the chattr command can improve system security,
but it is not suitable for all directories. The chattr command cannot protect the /, /dev, /tmp, and /var directories.
5.Application examples
1.Restore the /root directory, that is, all files in its subdirectories
# chattr -R +u/root
2.Use the chattr command to prevent a critical file in the system from being modified
Under Linux, some configuration files (passwd
,fatab) are not allowed to be modified by anyone. To prevent accidental deletion or modification, you can set the file’s “immutable bit (immutable)” with the following command:
# chattr +i /etc/fstab
sudo
1.Function
sudo is a command based on restricting commands in the configuration file, granting users usage for a limited time and recording it in logs; its permissions apply to all users.
2.Syntax
sudo [-bhHpV] [-s <shell>] [-u <user>]
[command]
sudo [-klv]
3.Main parameters
-b: Execute the command in the background.
-h: Display help.
-H: Set the HOME environment variable to the HOME environment variable of the new identity.
-k: End the password validity period, so a password will be required next time.
-l: List the commands the current user can use.
-p: Change the prompt symbol used when asking for a password.
-s <shell>: Execute the specified shell.
-u
<user>: Use the specified user as the new identity; if omitted, the default is root.
-v: Extend the password validity period by 5 minutes.
4. Description
The configuration for the sudo command is in the /etc/sudoers file. When a user uses sudo, they must enter a password to verify their identity. For a period of time afterward,
they can use the predefined commands. If a command not included in the configuration file is used, an alert will be recorded. sudo is a program used by system administrators to allow certain users to run part or all
of the system commands as root. One obvious use is that it enhances site security. If you need to do some routine work every day as the superuser and frequently execute a fixed set of commands that only the superuser can run,
then sudo is very suitable.
ps
1. Function
ps displays the dynamic status of processes at a given moment, and all users have permission to use it.
2. Format
ps [options] [–help]
3. Main parameters
ps has a great many parameters; only a few commonly used ones are listed here.
-A: List all processes.
-l: Display a long listing.
-m: Display memory information.
-w: Widen the display to show more information.
-e: Display all processes.
a: Display all processes on the terminal, including those of other users.
-au: Display more detailed information.
-aux: Display all processes, including those belonging to other users.
4. Description
To monitor and control processes, you must first understand the current state of processes, which means viewing the current processes. The ps command is the most basic and also a very powerful
process-viewing command. Using this command, you can determine which processes are running, their running status, whether a process has ended, whether there are zombie processes, which processes are using too many resources, and so on. Figure 2 provides a detailed explanation of the ps-aux
command. Most information can be obtained by executing this command. The three most commonly used parameters are u, a, and x. Below, the function of the ps command is explained in detail together with these three parameters: ps
aux
Figure 2 Detailed explanation of the ps-aux command
In the second line of code in Figure 2, USER indicates the process owner; PID indicates the process identifier; %CPU indicates CPU usage; %MEM indicates physical memory usage; VSZ
indicates the amount of virtual memory used; RSS is the amount of physical memory used by the process; TTY is the minor device number of the terminal.
STAT indicates the process status, where D means uninterruptible sleep (I/O operation); R means running; S means sleeping; T means stopped; Z means the process no longer exists, but cannot be removed temporarily; W means there is not
enough memory paging available for allocation; high-priority process; N low-priority process; L means memory pages are allocated and locked in memory
(real-time system or I/O). START is the
process start time. TIME is the execution time. COMMAND is the command being executed.
4. Application example
During system maintenance, it is common to encounter surprisingly high memory usage without knowing which process is consuming so much memory. In addition to using the top command to check memory usage, you can also use the following command:
ps aux | sort +5n
who
1. Function
who displays which users are logged into the system. The information shown includes the user ID, the login terminal being used, login time, idle time, CPU usage, and what they are doing.
All users have permission to use it.
2. Format
who – [husfV] [user]
3. Main parameters
-h: Do not display the title row.
-u: Do not display the user’s actions/work.
-s: Display in a short format.
-f: Do not display the user’s login location.
-V: Display the program version.
4. Description
This command is mainly used to view the users currently online. If a user wants to establish real-time communication with another user, such as by using the talk command, the first thing to confirm is that the other user is actually online; otherwise, the talk process cannot be established. Similarly, if the system administrator wants to monitor what each logged-in user is doing at any given moment, the who command must also be used. The who command is very simple to use and can provide a fairly accurate understanding of user status, so it is widely used.
- Upvote