Sort files in shell

Asked

Viewed 83 times

2

I’m a beginner in programming and I’m stuck in a code here.

Through shell I have to search inside directories and subdirectories all files that are of format .py and have the bookstore datetime included. And after that I have show the largest file on that list. The first two parts came out, but I have no idea how to show their biggest file:

find . -name '*.py' -type f exec -grep "import datetime" {} -lirw \;

This code is working well to fetch all python files that have the library datetime.

I appreciate the help

2 answers

1

Commando:

find . -name '*.py' -type f | xargs du -a | sort -n -r | head -n 1

0

You can use:

find . -iname '*.py' -type f -print0 | xargs -0 ls -lS

Completing:

find . -iname "*.py" -exec sh -c 'procura=$(grep "SHAZAM" {}); if [ $? -eq 0 ]; then echo {};fi' \; | xargs ls -lS

Search the archives .py and run the following script: If you find the string in that file print its name, then pass as default input to the ls -lhS which sorts by file size and prints at high level.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.