Home > Unix > UNIX – Lesson 008 – find and umask commands

UNIX – Lesson 008 – find and umask commands


find
The “find” command utility recursively descends the directory hierarchy for each path seeking files that match a boolean expression.
Syntax :
find path “expression”

Key argument :

  • -atime n           True if the file was accessed n days ago
  • -ctime n           True if the file’s status was changed n days ago
  • -mtime n          True if the file’s data was modified n days ago
  • -group “name”   True if the file belongs to the group “name”
  • -name pattern  True if pattern matches the current file name
  • -size n              True if the file is n bytes
  • -type x              True if the type of the file is x
  • -newer myfile    True if current file has been modified more recently than myfile
  • -print                 Always true; causes the pathname to be printed
  • -user uname      True if the file belongs to the user uname
  • -perm mode       Seek for files with permissions of type “mode”

Example:

$ find . –name “xarabas.txt”
./temp/home/xarabas.txt

$ find . –print
.
./Report.log
./Reports
./Reports/Report.log
./backup.sh

$ find . -perm u=rwx,g=rx,o=rx
./Report.log
./Reports
./backup.sh

$ find /tmp -name “ct*” -print
/tmp/ctn368

$ find /usr/local -type d -print
/usr/local
/usr/local/bin
/usr/local/bin/sge_arch
/usr/local/bin/plugins
/usr/local/bin/tkcvs_7_1_2
/usr/local/bin/tkcvs_7_1_2/bitmaps
/usr/local/bin/tkcvs_7_1_2/tkcvs
/usr/local/bin/tkcvs_7_1_2/tkdiff
/usr/local/bin/sparcv7
/usr/local/bin/sparcv9
/usr/local/bin/mgdiff_dir

================================================================================
umask
The “umask” utility sets the file mode creation mask of the current shell execution environment to the value specified by the mask operand. This mask affects the initial value of the file permission bits of subsequently created files. The value of each specified digit is subtracted from the corresponding “digit” specified by the system for the creation of a file.
Syntax :
umask ###

Without set umask, files are created with 666 permission (rw-rw-rw-) an the directories with
777 permission (rwxrwxrwx).
With umask 022 files are created with 644 permission (rw-r–r–) and directories with 755
permission (rwxrw-rw-).

666 – 022 = 644
777 – 022 = 755

Example:
$ umask 000
Reset the mask permission to 666

$ umask
0
Now the umask is set to 666

$ touch test
$ ls -la test-rw-rw-rw- 1 xarabas admins 0 Feb 21 14:22 test

$ umask 022
Now we set the permission to 644

$ touch test2
$ ls -la test2
-rw-r–r– 1 xarabas admins 0 Feb 21 14:23 test2

Advertisements
Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: