AIX 基础笔记2

*Copying Files

cp source target

cp file1 file2 ... target_dir

# pwd

/tmp/test

# cp /ptc/sp/mvlogs.sh testmv

# ls

test001  test01   test02   test03   test04   testmv

# cp test01 test02 test03 test001

# cd test001

# ls

test01  test02  test03

# cp -i test01 test001

overwrite test001/test01? yes

# cp -R /tmp/test /tmp/test/test001

cp: 0653-441 /tmp/test/test001/test is a descendant of /tmp/test.

    Copying results in infinite loop(not copied.)

# cp -R test001 test002

# ls

test001  test002  test01   test02   test03   test04   testmv

# cd test002

# ls

test01  test02  test03  test04  testmv

 

*Moving and Renaming Files

mv source target

mv file1 file2 ... target_dir

# pwd

/tmp/test

# ls

test001  test01   test02

# mv test02 test001

# ls

test001  test01

# cd test001

# ls

test02

# cd ..

# ls

test001  test01

# mv test01 test03

# ls

test001  test03

# mv test03 test001/test01

# ls

test001

# touch test002

# mv -i test002 test001/test01

overwrite test001/test01? no

# ls

test001  test002

# cd test001

# ls

test01  test02

 

*Listing File Contents

cat file1 file2 ...                    //Display all lines

pg filename                          //Display the files one page at a time

more filename                    //Display continuous text one screen at a time. With <Enter> pressed, it displays an additional line, and <space bar> , the next screen of text.

wc [-c] [-l] [-w] filename   //-c:counts the number of bytes. -l:counts lines. -w:counts words.

# cp /ptc/sp/mvlogs.sh testmv

# ls

test01  test02  testmv

# cat testmv

#!/usr/bin/ksh

echo "delete old logs"

rm -R /pdmdata/logs/apache/*

rm -R /pdmdata/logs/tomcat/*

rm -R /pdmdata/logs/windchill/*

ymd=`date +"%y%m%d"`

echo "make new backup diectory"

mkdir /pdmdata/logs/apache/$ymd

mkdir /pdmdata/logs/tomcat/$ymd

mkdir /pdmdata/logs/windchill/$ymd

if [[ $? != 0 ]]

     then

     echo "error!Please check first."

     exit 1

fi

mv /ptc/Apache/logs/access_log /pdmdata/logs/apache/$ymd

mv /ptc/Apache/logs/error_log /pdmdata/logs/apache/$ymd

mv /ptc/Tomcat/logs/* /pdmdata/logs/tomcat/$ymd

mv /ptc/Windchill/logs/* /pdmdata/logs/windchill/$ymd#

# cat -n testmv                     //-n flag , with numbers displayed beside each

     1  #!/usr/bin/ksh

     2  echo "delete old logs"

     3  rm -R /pdmdata/logs/apache/*

     4  rm -R /pdmdata/logs/tomcat/*

     5  rm -R /pdmdata/logs/windchill/*

     6  ymd=`date +"%y%m%d"`

     7  echo "make new backup diectory"

     8  mkdir /pdmdata/logs/apache/$ymd

     9  mkdir /pdmdata/logs/tomcat/$ymd

    10  mkdir /pdmdata/logs/windchill/$ymd

    11  if [[ $? != 0 ]]

    12       then

    13       echo "error!Please check first."

    14       exit 1

    15  fi

    16  mv /ptc/Apache/logs/access_log /pdmdata/logs/apache/$ymd

    17  mv /ptc/Apache/logs/error_log /pdmdata/logs/apache/$ymd

    18  mv /ptc/Tomcat/logs/* /pdmdata/logs/tomcat/$ymd

    19  mv /ptc/Windchill/logs/* /pdmdata/logs/windchill/$ymd

# wc testmv

      18      53     592 testmv

# wc -clw testmv

      18      53     592 testmv

 

*Linking Files

ln source_file target_file

    Allows files to have more than one name in the directory structure

    Both files reference the same i-node

    Cannot be used with directories, cannot span file systems

ln -s source_file target_file

    Creates an indirect reference to a file (symbolic link)

    Name references the original file's name and path

    Can be used with directories and span file systems

# ls -li

total 0

73863 -rw-r--r--    1 root     system            0 Mar 23 16:42 test01

# ln test01 testln01

# ls -li

total 0

73863 -rw-r--r--    2 root     system            0 Mar 23 16:42 test01

73863 -rw-r--r--    2 root     system            0 Mar 23 16:42 testln01

# ln -s test01 testln02

# ls -li

total 0

73863 -rw-r--r--    2 root     system            0 Mar 23 16:42 test01

73863 -rw-r--r--    2 root     system            0 Mar 23 16:42 testln01

73864 lrwxrwxrwx    1 root     system            6 Mar 23 16:43 testln02 -> test   01

 

*Removing Files

rm file1 file2 file3 ...

# touch tet02

# ls

test01    testln01  testln02  tet02

# rm tet02

# ls

test01    testln01  testln02

# touch tet03

# rm -i tet03

rm: Remove tet03? yes

# ls

test01    testln01  testln02

# mkdir test001

# touch test001/testrm

# rm test001

rm: 0653-603 Cannot remove directory test001.

# rm -r test001

# ls

test01    testln01  testln02


*File Protection/Permissions

(1) Every file and directory on the system has file permissions associated with it.

(2) Three permission categories: owner, group, and other

(3) Three bits can be set for each category: read, write, execute (rwx)

 

*Changing Permissions (Symbolic Notation)

chmod mode filename

u = owner of the file

g = owner's group

o = other users on the system

a = all

+ : add permissions

-  : remove permissions

= : clears permissions and sets to mode specified

# touch newfile

# ls -l

total 0

-rw-r--r--    1 root     system            0 Mar 26 16:06 newfile

# chmod go+w newfile

# ls -l newfile

-rw-rw-rw-    1 root     system            0 Mar 26 16:06 newfile

# chmod a+x newfile

# ls -l newfile

-rwxrwxrwx    1 root     system            0 Mar 26 16:06 newfile

# chmod o-rwx newfile

# ls -l newfile

-rwxrwx---    1 root     system            0 Mar 26 16:06 newfile

 

*Changing Permissions (Octal Notation)

(1) File and directory permissions can be specified in the symbolic syntax or as an octal number:

                          User                Group                  Others

Symbolic          rwx                  rw-                       r--

Binary               111                 110                       100          

                           4+2+1            4+2+0                   4+0+0

Octal                 7                      6                           4

(2) To change permissions so the owner and group have read and write permissions and others read only:

# ls -l newfile

-rwxrwx---    1 root     system            0 Mar 26 16:06 newfile

# chmod 664 newfile

# ls -l

total 0

-rw-rw-r--    1 root     system            0 Mar 26 16:06 newfile

(3) The chart below may help in translating binary to octal for those who are unfamiliar with binary notation:


user



group



others


r

w

x

r

w

x

r

w

x

|

|

|

|

|

|

|

|

|

400

|

|

40

|

|

4

|

|


200

|


20

|


2

|



100



10



1

 

*Default File Permissions

(1) The default protections for newly created files and directories are:

File                  -rw-r--r--                644

Directory        drwxr-xr-x             755

(2) umask

The umask specifies what permission bits will be set on a new file or directory when created. It is an octal number that is used to determine what permission bits a file or directory is created with:

New Directory : 777 - 022 : 755 => rwxr-xr-x

New File:            666 - 022 : 644 => rw-r--r--

The default value of 022 is set in /etc/security/user. It can be changed for all users or for a specific user.


你可能感兴趣的:(source,infinite)