The other day I was doing some cleaning on my Linux server and I noticed that over time people had created and left empty files. Druhý deň som robil nejaké čistenie na svojom serveri Linux, a všimol som si, že časom ľudia stvoril a nechal prázdne súbory. So I decided to create a shell script that would run through the system and let me know how many files like this existed, along with their path. Tak som sa rozhodol vytvoriť skript, ktorý by bežal cez systém a dajte mi vedieť, koľko súborov podobného existuje, spolu s ich cesty.
Here's a simple command that will allow you to run a similar search: Tu je jednoduchý príkaz, ktorý vám umožní spustiť podobný vyhľadávania:
# find -L /home/stewiegriffin -maxdepth 1 -type f -size 0 # Find-L / home / stewiegriffin-maxdepth 1-type f-veľkosť 0
/home/stewiegriffin/temp.log / Home / stewiegriffin / temp.log
/home/stewiegriffin/brainstorm_notes.txt / Home / stewiegriffin / brainstorm_notes.txt
/home/stewiegriffin/mail.log / Home / stewiegriffin / mail.log
/home/stewiegriffin/niptuck.html / Home / stewiegriffin / niptuck.html
What the above shown command does is that it searches for files that have a size of 0 . Aké vyššie uvedenej príkaz je, že vyhľadáva súbory, ktoré majú veľkosť 0. By default, the find command excludes symbolic files, so we use the -L option to include them. V predvolenom nastavení je nájsť príkaz vylučuje symbolické súbory, takže použijeme-L možnosť zahrnúť je. The option maxdepth tells the command to search only in the main directory and not go into sub directories. type -f tells the command to only look at regular files. Možnosť maxdepth povie príkaz na hľadanie len v hlavnom adresári a nie ísť do čiastkových adresárov. Typu-f hovorí príkaz pozrieť len na obyčajné súbory.
If you run the same command without the maxdepth 1 option it will search for empty files in all the directories inside of /home/stewiegriffin . Ak spustíte rovnaký príkaz, bez maxdepth 1 možnosť, že bude hľadať prázdne súbory vo všetkých adresároch vnútorný / home / stewiegriffin. You can also play with the options maxdepth and mindepth if you want to regulate the depth of the search. Môžete tiež hrať s možnosťou maxdepth a mindepth ak chcete regulovať hĺbku vyhľadávanie. This is really very helpful if you have a lot of levels of directories and a lot of files to go through. To je naozaj veľmi užitočné, ak máte veľa úrovní adresárov a mnoho súborov prejsť.
Of course, if you want you can also reverse this search and ask the command to look for all non-empty files. Samozrejme, ak chcete, môžete aj zvrátenie tohto hľadania a opýtajte sa príkaz k pohľadu pre všetky non-prázdne súbory. All you need to do is use the above command and add an exclamation mark in the size parameter: Všetko, čo musíte urobiť, je použiť vyššie uvedeného príkazu a pridať výkričník vo veľkosti parametra:
# find -L /home/stewiegriffin -maxdepth 1 -type f ! # Find-L / home / stewiegriffin-maxdepth 1-type f! -size 0 -veľkosť 0
/home/stewiegriffin/apache.log / Home / stewiegriffin / apache.log
/home/stewiegriffin/how_to_log_your_actions.txt / Home / stewiegriffin / how_to_log_your_actions.txt
/home/stewiegriffin/maillog.log / Home / stewiegriffin / maillog.log
/home/stewiegriffin/niptuck01.html / Home/stewiegriffin/niptuck01.html
/home/stewiegriffin/index.html / Home / stewiegriffin / index.html
/home/stewiegriffin/test.php / Home / stewiegriffin / test.php
Just be careful while running this. Len si dajte pozor pri behu to. It may return many, many results. To sa môže vrátiť veľa, veľa výsledkov.























0 Responses 0 Odpovede
Stay in touch with the conversation, subscribe to the Zostať v kontakte s konverzácia, prihláste sa RSS feed for comments on this post RSS kanál pre komentáre k tomuto príspevku . .