Quote:
Originally Posted by maxwell2k19
1. how can i know how many files and directories this dir2 has.
|
To count the objects in that directory, you could use
ls -a | wc -l. To count all objects in that directory and all its subdirectories, one method is
find . | wc -l.
wc stands for "word count" and can be used to count characters, words or lines. In this case, it counts lines.
Quote:
2. How many files in the dir2 have above 10MB and less than 10MB
|
Modify your find command for 10MB and pipe it into
wc -l.
Quote:
3. how can i know the files which have been modified in last 7 days in dir2.
|
The
find command has an option
-mtime, which stands for "modification time".
Quote:
4. i want to keep the files of last 7 days which includes modified files and delete the rest of the files in dir2. how can i delete.
|
The
rm command deletes files. You can use the
-exec option to perform an action on each file that
find finds, for example:
Code:
find -mtime +7 -exec rm {} +
Note that this will delete everything in subdirectories, not only the current directory. Use the
-maxdepth option to change this behaviour. Also, it is your responsibility to test this command. Use it at your own risk.
Quote:
5. To know the OS version will the command cat /etc/os-release give me OS version in RHEL,Centos,SUSE linux?
|
The question is what you mean by "OS version".
os-release is part of systemd and therefore available on those distros. It tells you the distro version, but not the kernel version. To know the kernel version that is currently running, use
uname -r.