Today we had a problem related with a number of files in a directory. We needed to find directories with a biggest number of files / directories in it. Here is a small shell script that will list directories and a number of files/directories in each directory.
find . -type d|awk {'print "echo -n "$1".\"\t\"; ls "$1"|wc -l"'} > /tmp/do; . /tmp/do|sort -k 2 -n -r |more
Explaining it a little bit:
"find . -type d" - find all directories bellow current directory
"awk {'print "echo -n "$1".\"\t\"; ls "$1"|wc -l"'} > /tmp/do" - generate a script that will print a directory name (echo -n), make ls in this directory and count a number of lines from ls (wc -l)
". /tmp/do" - execute generated script
"sort -k 2 -n -r" - sort the result using second column (-k 2) as numerical (-n) and in reverse order (-r)
Monday, December 19, 2011
Find directory with biggest number of files / directories
Posted by
Unknown
at
10:07 PM
0
comments
Sunday, November 8, 2009
VMware crashes after updating (upgrading) of host OS (to CentOS 5.4)
Posted by
Unknown
at
2:38 AM
0
comments
Tuesday, July 7, 2009
VMware troubles
Well, I'm not a hardware guru, but from my experience I figured out the following:
Posted by
Unknown
at
10:32 AM
0
comments
Monday, May 25, 2009
"Network Connection Closed Unexpectedly" error while using svn+ssh
If you got a "Network Connection Closed Unexpectedly" error while using svn+ssh (here is a nice HOWTO) then you should comment (or remove) "mesg y" in /etc/bashrc or in $HOME/.bashrc
Posted by
Unknown
at
8:26 PM
5
comments
Tuesday, May 13, 2008
List number of file handles (open files) for each process
Here is a simple script that will show you a number of file handles (open files) used by each process on your Linux system:
Posted by
Unknown
at
10:40 AM
2
comments
Labels: Linux
Tuesday, April 8, 2008
Cent OS 5.1 + Oracle 10g
Apart of modifying /etc/redhat-release to "redhat-4", there are a couple of packages that you will need to install in order to make Oracle 10g work with Cent OS 5.1:
Posted by
Unknown
at
10:12 AM
1 comments
Wednesday, February 13, 2008
Leopard terminal and Midnight Commander
If you use mc while connected to some linux server and you need to select some files - use Ctrl+T
Posted by
Unknown
at
7:03 PM
0
comments
Thursday, January 31, 2008
Perl: CPAN or RPM packages?
Posted by
Unknown
at
1:20 AM
0
comments
Labels: Linux
Wednesday, January 16, 2008
Reverse tunnel with SSH
When you need to create a reverse tunnel with SSH, just use the following:
Posted by
Unknown
at
8:33 PM
0
comments
Labels: Linux
More comfortable environment
After installing new Linux or Unix system I like to edit /etc/profile or $HOME/.bash_profile and add following lines:
Posted by
Unknown
at
3:55 PM
0
comments
Labels: Linux
Rebooting linux without reboot command
Just a sample of how you can reboot or shutdown linux without issuing reboot command, so called hard reboot. That means that system will just make a reset as if you pressed a reset button, without running any shutdown scripts, etc. A kind of dangerous staff, but can be helpful in some occasions.
Posted by
Unknown
at
1:52 PM
3
comments
Labels: Linux