Kết quả thông tin có thể trongcomplete.
Lsoft tries to handle all file systems. This warning appears because lsof encountered the GNOME Virtual file system (GVFS) system. This is a special case of the file system in user space (FUSE). It acts as a bridge between GNOME, API and kernel. No one, even root users, can access these file systems except the one who mounts it (in this case, GNOME). You can ignore this warning.
The output of lsof is very long and numerous. You can see the leftmost columns in the picture below:
The far right column:
Here are the full columns of lsoft command. Open files may not be full of columns, some will be empty.
Section column FD can be made up of three components: file descriptor, node character and lock character. Some common file descriptions are:
Node character:
Key characters:
More than 70 items may appear in the TYPE column. Some common items you will see are:
To see the process of opening a certain file, you need to provide the file name as a parameter for lsof. For example, to see the process of opening the kern.log file, use the following command:
sudo lsof /var/log/kern.log
Lsof returns by displaying a single process, rsyslogd is started by the syslog user.
To see files opened from a library and the process of opening them, provide the directory name for lsof as a parameter. You must use the + D option.
To view all open files in / var / log directory / use the following command:
lsof returns a list of all open files in that directory.
To view all files opened from the / home directory, use the following command:
sudo lsof + D / home
You will see all the files opened in the / home directory. With short descriptions in some columns, the entire list will be narrowed.
To view files opened by a specific process, use the -c option. Note, you can provide multiple search terms for lsoft at the same time.
sudo lsof -c ssh -c init
Lsoft provides a list of files opened by processes in the command line.
To limit the display of files opened by specific users, you should use the -u option. In this example, we will find the files opened by the process of ownership or launch instead of Mary users.
sudo lsof -u mary
All files opened by Mary users will be listed. It includes files opened in the desktop environment or simply the result of Mary logging into the system.
To exclude files opened by users, use the ^ operator to exclude users from the list. This will help you find information more easily. You must use the -u option and add the ^ character to the username.
sudo lsof + D / home -u ^ mary
You will see a list of / home directories without any files opened by Mary users.
To list the file due to the open process, use the -p option and provide the process ID as the parameter.
sudo lsof - p 4610
All files opened by the process ID you provide are listed in the image below.
To view the process ID for a specific file, use the -t option and provide the file name for the command line.
sudo lsof -t /usr/share/mime/mime.cache
The process ID is displayed in a simple list.
As mentioned above, you can use multiple search terms in the command line. For example, to find files opened by Mary users and related to the SSH process use the following command:
sudo lsof -u mary -c ssh
Below is the output of the above command, something is not right here because there are output items that start with root.
When providing multiple lsoft search terms, it will return any file that matches the first, second, third search term, etc. In other words, it does an OR search.
To make lsoft perform an AND search, use the -a option. That means only files matching the first and second conditions are listed.
sudo lsof -u mary -c ssh -a
Now, all files in the list are opened by or on behalf of Mary and are related to the SSH command.
We can use the + | -r option to put lsof into repeat mode. You can use the repeat option in two ways + r or -r . You need to add the number of seconds you want lsof to wait before refreshing the result.
Use the repeat option with one of the two formats that lsoft displays as normal, but it adds a broken line to the bottom of the screen. It will wait for the number of seconds you provided in the command line and then refresh the screen with a new set of results.
With the -r option it will continue to repeat the process, want to stop, press Ctrl
+ C
With the + r format, it will continue until no results are displayed or press Ctrl
+ C
sudo lsof -u mary -c ssh -a -r5
Note, the dashed line at the end of the data split list is displayed when the output is refreshed.
The -i option allows you to view files opened by network related processes and the Internet.
lsof -i
All files are opened due to internet connection and the network is displayed.
To view files opened by a process related to an Internet connection using a specific process ID, add the -p option and -a option.
We will find the files related to the Internet connection or the network opened by the 606 process ID.
sudo lsof -i -a -p 606
All files opened by the ID 606 process associated with the Internet and the network are displayed.
We can use the -c (command) option to search for files opened by specific processes. To find files opened with processes related to Internet connection or networks associated with the ssh process, use the following command:
lsof -i -a -c ssh
All files are opened because the ssh process is listed.
Lsoft can report files opened by Internet connection and network on specific port. To do that, use the character : following the port number.
Below lsoft lists the files opened by network connection or Internet using port 22.
lsof -i: 22
All files are opened by the process related to port 22 (this is the default port for SSH connection).
You can request lsof to display the file opened by the process related to network and Internet connection, using specific protocol. You can choose from TCP, UDP and SMTP. Here we find the file using TCP protocol.
sudo lsof -i tcp
This is the output that is opened by processes using TCP protocol.
Here are some ways to use lsoft command you can use to search files on Linux.
I wish you all success!