In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to clean up files and environmental variables in the Linux system". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to clean up files and environment variables in the Linux system.
Use the Find command to help you find files that need to be cleaned up
One problem that haunts almost all file systems-- including Unix and others-- is the constant accumulation of files. Few people want to take the time to clean up files and organize file systems that they no longer use. As a result, files become messy, it's hard to find useful things, and it's going to be a lasting challenge to make them work well, maintain backups, and be easy to manage.
One solution I have seen is to suggest that users use all the data fragments to create a summary report or "overview" of a collection of files to report data such as the number of files; the oldest, newest, and largest files; and count who owns these files and other data. If someone saw a folder containing half a million files five years ago, they might delete those files-or at least archive and compress them. The main problem is that too large folders can make people worry about mistakenly deleting something important. If there is a way to describe the folder to help show the nature of the file, then you can clean it up.
When I prepare to do a summary of the Unix file system, several useful Unix commands can provide some very useful statistics. To count the number of files in the directory, you can use such a find command.
The code is as follows:
$find. -type f | wc-l
187534
Although it is complicated to find the oldest and latest files, it is quite convenient. In the following command, we use the find command to find the file again, sorted by file time and displayed in year-month-day format, and the one at the top of the list is obviously the oldest.
In the second command, we do the same, but print the last line, which is the latest.
The code is as follows:
$find-type f-printf'% T +% p\ n'| sort | head-n 1
2006-02-03-02-02-40-40-30-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-03-02-02-03-02-02-03-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02-02 /
$find-type f-printf'% T +% p\ n'| sort | tail-n 1
2015-07-19 July 14 20 history 16. / .bash _ Bash
The printf command outputs% T (file date and time) and% P (file name with path) parameters.
If we look up the home directory, we will no doubt find that history files (such as .bash _ history) are up-to-date, which is of no use. You can use "un-grepping" to ignore these files, or you can ignore them. The file at the beginning, as shown in the following figure.
The code is as follows:
$find-type f-printf'% T +% p\ n'| grep-v "\. /\. | sort | tail-n 1
2015-07-19 May 13 isPrime 02Rose 12. /
Find the largest file using the% s (size) parameter, including the file name (% f), because that's what we want to show in the report.
The code is as follows:
$find-type f-printf'% s% f\ n'| sort-n | uniq | tail-1
20183040 project.org.tar
The owner of the statistics file, using u (owner)
The code is as follows:
$find-type f-printf'% u\ n'| grep-v "\. /\. | sort | uniq-c
180034 shs
7500 jdoe
It would also be useful if the file system could record the date of the last visit, to see if the file had been accessed, for example, not in two years. This will enable you to clearly distinguish the value of these documents. This last access (% a) parameter is used as follows:
The code is as follows:
$find-type f-printf'% a +% p\ n' | sort | head-n 1
Fri Dec 15 03:00:30 2006 +. / statreport
Of course, if most of the recently accessed files are also from a long time ago, it looks like you need to work with more files.
The code is as follows:
$find-type f-printf'% a +% p\ n' | sort | tail-n 1
Wed Nov 26 03:00:27 2007 +. / my-notes
To be hierarchical, you can create a summary report for a file system or large directory, showing the date range of the files, the largest files, the file owners, the oldest files, and the latest access time. It can help file owners determine which folders are important and which need to be cleaned up.
How to temporarily empty the Bash environment variable before running a command on Linux
How do I display the current environment?
Open the terminal application and enter one of the following commands:
The code is as follows:
Printenv
Or
The code is as follows:
Env
Sample output:
Statistics on the number of environmental variables
Enter the following command:
The code is as follows:
Env | wc-l
Printenv | wc-l # or
Sample output:
The code is as follows:
twenty
Run programs in a clean bash/ksh/zsh environment
The syntax is as follows:
The code is as follows:
Env-I your-program-name-here arg1 arg2...
For example, you want to run the wget program without using http_proxy and / or any other environment variables. Temporarily clear all bash/ksh/zsh environment variables and run the wget program:
The code is as follows:
Env-I / usr/local/bin/wget www.cyberciti.biz
Env-I wget www.cyberciti.biz # or
This is useful when you want to run commands by ignoring any environment variables that have been set. I use this command several times a day to ignore http_proxy and other environment variables I set.
Example: using http_proxy
The code is as follows:
$wget www.cyberciti.biz
-- 2015-08-03 2314 20Rose 23muri-http://www.cyberciti.biz/
Connecting to 10.12.249.194:3128... Connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'
Index.html [] 36.17K 87.0KB/s in 0.4s
2015-08-03 23:20:24 (87.0 KB/s)-'index.html' saved [37041]
Example: ignore http_proxy
The code is as follows:
$env-I / usr/local/bin/wget www.cyberciti.biz
-- 2015-08-03 23pur25Rose 17muri-http://www.cyberciti.biz/
Resolving www.cyberciti.biz... 74.86.144.194
Connecting to www.cyberciti.biz | 74.86.144.194 |: 80. Connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html.1'
Index.html.1 [] 36.17K 115KB/s in 0.3s
2015-08-03 23:25:18 (115 KB/s)-'index.html.1' saved [37041]
The-I option causes the env command to completely ignore the environment it inherits. However, it does not prevent your commands (such as wget or curl) from setting new variables. At the same time, note the side effects of running bash/ksh shell:
The code is as follows:
Env-I env | wc-l # # empty # #
# now run bash # #
Env-I bash
# # bash sets a new environment variable # #
Env | wc-l
Example: set an environment variable
The syntax is as follows:
The code is as follows:
Env var=value / path/to/command arg1 arg2...
# # or # #
Var=value / path/to/command arg1 arg2...
For example, set http_proxy:
The code is as follows:
Env http_proxy= "http://USER:PASSWORD@server1.cyberciti.biz:3128/" / usr/local/bin/wget www.cyberciti.biz
At this point, I believe you have a deeper understanding of "how to clean up files and environment variables in the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
1. Enable SNMP2 and view the API OID
© 2024 shulou.com SLNews company. All rights reserved.