common unix commands
TRANSCRIPT
-
7/27/2019 Common Unix Commands
1/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 1 in 7
Common Unix Commands
1. ls lists files or directories.
For example: $ls
lists all contents in the current directory.
2. cp copies files or directories.
For example: $cp src dest
copies the file src and renames the new file as dest.
3. rm deletes files or directories.
For example: $rm abc
deletes the files abc.
4. mv changes the file names or move files.
For example: $mv abc ../bcd
moves the file abc from the current directory to the upper-level
directory and renames the new file as bcd.
5. man displays the manual pages.
For example: $man ls
displays the manual pages about ls.
6. who shows who is logged on.
For example: $who
shows who is logged on to the system.
7. mkdir makes directories.
For example: $mkdir newdir
makes a subdirectory named newdir in the current directory.
8. rmdir removes directories.
For example: $rmdir dir1
deletes a subdirectory dir1 from the current directory. The
subdirectory dir1 must be empty. Otherwise, use rm -fr dir1 to
forcibly delete it.
-
7/27/2019 Common Unix Commands
2/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 2 in 7
9. chmod changes files access permissions.
For example: $chmod 700 abc
changes permission of the file abc to the 700 mode, that is, only the
file owner can read, write and run this file.
10. chown changes file owner and group.
For example: $chown omc abc
changes owner of the file abc to omc.
11. chgrp changes group ownership.
For example: $chgrp omc abc
changes the group ownership of the file abc to omc.
12. pwd prints name of the current directory.
For example: $pwd
prints name of the current directory.
13. tail outputs the last part of files.
For example: $tail -f abc
lists the last part of the files abc and monitors the change of this file.
If the file changes, new contents will be displayed immediately.
For example: $tail -100 abc
lists the last 100 lines of the file abc.
14. ps reports process status.
For example: $ps -U omc
reports all processes of the user omc. U stands for user.
15. cat shows content of a file.
For example: $cat abc
shows the content of the file abc on the screen.
16. date shows or modifies the system time.
For example: $date
shows the current system time as follows:
2003-12-10 Wen 14:02:41 CST
-
7/27/2019 Common Unix Commands
3/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 3 in 7
$date 091812002001
sets the current time to 12:00, Sep. 18, 2001
17. dfreports filesystem disk space usage.
For example: $df -k
reports the filesystem disk space usage by the unit of Kilobytes.
18. du reports directory or file space usage.
For example: $du -ks dir1
reports the space usage of directory dir1 by the unit of Kilobytes.
19. tar packages or unpackages directories or files. The tar file name
extension is .tar.
For example: $tar -cvf a.tar dir1 dir2 file1
packages two directories dir1 and dir2, and the file file1 into a file
a.tar. The command tar only packages or unpackages but does not
compress them.
For example: $tar -xvf a.tar
unpackages the file a.tar to generate two directories dir1 and dir2,
and a file file1.
20. gzip/gunzip compresses/decompresses files. The gzip file name
extension is .gz.
For example: $gzip a.tar
compresses the file a.tar into a file named a.tar.gz. Note: After the
compression, the original file a.tar will be automatically deleted.
For example: $gunzip a.tar.gz
decompresses the file and generate a file named a.tar. Note: After
the decompression, the original file a.tar.gz will be automatically
deleted.
21. compress/uncompress compresses/decompresses files. The
compress file name extension is .Z.
For example: $compress a.tar
compresses the file a.tar and generate a file named a.tar.Z. Note:
After the decompression, the original file a.tar will be automatically
deleted.
-
7/27/2019 Common Unix Commands
4/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 4 in 7
For example: $uncompress a.tar.Z
decompresses the file and generate a file named a.tar. Note: After
the decompression, the original file a.tar.Z will be automatically
deleted.
22. su runs a shell with substitute user and group IDs.
For example: $su oracle
switches to the user oracle. Password is required. If there is no user
name behind su, then it will switch to the user root.
23. kill terminates a process.
For example: $kill -9 1033
terminates the process whose process number is 1033. The process
numbers can be queried through the ps command. -9 means to
forcibly terminate a process.
24. shutdown restarts the system.
For example: $/usr/sbin/shutdown -y -g 0 -i 6
restarts the system.
25. reboot restarts the system.
For example: $reboot
restarts the system. Compared with shutdown, reboot means forcible
restart and some processes may fail to save the data. Therefore, it is
recommended to use shutdown to restart the system.
26. stop+a stops the system from running.
For example: Okstop+a
In any case, stop+a will stop the Solaris operating system from
running and show the OK prompt.
27. boot boots up the system.
For example: OKboot cdrom
executes the above command in the OK prompt and boots up the
system.
28. id prints real and effective UIDs and GIDs.
For example: $id
-
7/27/2019 Common Unix Commands
5/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 5 in 7
uid=1005(omc) gid=10(staff)
prints UID and GID of the current user.
29. passwd changes the users password.
For example: $passwd omc
changes the password of the user omc. It is required to input the old
password of the user omc, and then type the new password twice to
confirm it.
30. ln creates a link to a file or directory.
For example: $ln s /net/138.1.1.1$OMCHOME/tmp/ftp $OMCHOME
/tmp/ftp
links the directory $OMCHOME/tmp/ftp of 138.1.1.1 to the local
directory $OMCHOME/tmp/ftp.
31. touch changes file timestamps.
For example: $touch test
If the file test exists, the command will replace its timestamp with
the current time. If the file test does not exist, the command will
create a file named test.
32. groupadd creates a group.
For example: $groupadd g 1000 staff
creates a group staff whose id is 1000.
33. useradd creates a user.
For example: $useradd d /export/home/oracle m g oinstall oracle
creates a user oracle that belongs to the group oinstall and sets the
directory /export/home/oracle as the home directory of the user
oracle.
34. ldd prints shared library dependencies.
For example: $ldd amp
prints all dependencies of the executable file amp.
35. format is for disk partitioning and maintenance.
For example: $format
-
7/27/2019 Common Unix Commands
6/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 6 in 7
displays the format menu for the user to make corresponding
operations.
36. The combination of prtvtoc and fmthard copies a partition table
from one disk to another.
For example: $ prtvtoc h /dev/rdsk/c0t0d0s2 | fmthard -s -
/dev/rdsk/c0t1d0s2
copies the partition table from c0t0d0s2 to c0t1d0s2.
37. metainit creates a mirror for a file system.
For example: $ metainit -f d10 1 1 c0t0d0s0
$metainit -f d20 1 1 c0t1d0s0
$metainit d30 -m d10
creates respective one-to-one cascade for c0t0d0s0 and c0t1d0s0.
dxx means the device number and xx can be any value. Then the
metadevice is created and d10 is added to d30.
38. metaroot updates the files /etc/vfstab and /etc/system.
For example: $ metaroot d30
After metainit has been executed, it is required to use the metaroot
command to update files. The operator cannot edit these two files
manually.
39. lockfs changes or reports file system locks.
For example: $lockfs fa
$init 6
flushes the data and allows the system to mount mirrors.
40. metattach attaches metadevice to a mirror or trans device, or attach
space (blocks) to a soft partition to grow the soft partition.
For example: $metattach d30 d20
adds the second submirror to the mirror. The disk data will be
synchronized from the boot disk to the new submirror.
41. metadb creates replicas of the state database.
For example: $metadb -a -f -
c2 /dev/dsk/c0t0d0s3 /dev/dsk/c0t1d0s3
-
7/27/2019 Common Unix Commands
7/7
Internal Use Only
All Rights reserved, No Spreading abroad without Permission of ZTE Page 7 in 7
creates a replica of the state database.
42. newfs constructs a UFS file system.
For example: $newfs -i 8192 -c 256 /dev/md/rdsk/d7
constructs a UFS file system.
For more and detailed information, see related Solaris system
manuals.