Strictly Programming

Mini Linux FAQ

Posted in Linux by sqllyw on 12/05/2008

Count lines in a directory:
cat *.m |wc -l
cat *.h |wc -l

To count files in a directory:

Reference Link

Simplest one might be:
ls | wc

Something like “ls -R | wc” will also do. This performs a recursive directory listing. The output is piped to wc, a utility that counts the number of words and lines.(Tested and works, be sure to type the command instead of copy and paste, the pipe should not be the broken one if paste )

This works too:

find -f *.txt |wc
find -f *.jpg |wc

following seems not working, will test later:

If all you want is a total file count
find . -type f | wc -l
find [period] [dash]type f [pipe] wc [dash][el]

Get total size of disk or directory
Reference Link

get file/directory sizeļ¼š

du -ch |grep total // this works in OS X to return the total size

Shared directory among users
Reference Link
For impatients, here is the faster version:
you have two users, rey and john, under rey’s home directory you have ‘data’ and you want john to be able to access it as well:

  1. Add john to rey’s group: usermod -a -G rey john
  2. chmod -R 2775 /home/rey/data/
  3. That’s it.
    Related blog

Adding global environment variables
you can update /etc/profile to include the variables. to effect the change:
. /etc/profile

%d bloggers like this: