Unix Commands
--------------
1. man - manual pages
Ex: man ls (displays the help for the command ls)
2. passwd - changing passwords
3. date - system date
4. who - lists all users logged in
5. whoami - lists who you are.
6. cal - displays the calendar Ex: cal 1990 cal 6 1994
7. pwd - print working directory
8. cd [dir] - change directory
Ex:
cd ../ (moves back one directory)
cd (goes to your default directory)
9. ls [options] [names] - list contents
Ex:
ls -l (long listing)
ls -lg (long listing including group)
ls -a (list all files including dot files)
ls -lt (sort files by timestamp)
ls -l raj.txt (displays long listing for the file raj.txt)
10. more - displays a file a screenful at a time
Ex: more tempfile Note: On many att machines you may have to use pg instead
11. cat - displays/types an entire file Ex: cat -b file1
12. mkdir - make a new directory Ex: mkdir -p /tmp/usr1/fred (create intermediate directories also)
13. mv [options] sources target - move a file
Ex:
mv -i (prompt in case you are overwriting a file)
14. cp - copy a file
Ex:
cp -i (prompt in case you are overwriting a file)
cp -r (recursive copy for directories)
15. rm - remove a file
Ex:
rm -i (prompt before deletion)
rm -r (remove files recursively)
16. rmdir - remove a directory. Ex: rmdir tempdir
17. chmod - change the permission of a file.
Ex:
chmod +x tempfile (add execute permission)
chmod u+x tempfile (add execute for user only)
chmod 4755 oracle (set the setuid bit on)
18. grep - search a file for a string or expression.
Ex:
grep -n (print line numbers)
grep -i (ignore case sensitivity)
19. find - search for files.
Ex:
find . -name sqlplus -print (find the full pathname of sqlplus starting from the current directory)
find . -name '*sql*' -print (find the full pathname of file where 'sql' is in its name)
20. wc - word count
Ex:
wc -l (line count)
wc -w (word count)
wc -c (character count)
21. ps - display process status
Ex: ps -aux (ucb) ps -ef (att)
22. kill - send a signal to terminate a process.
Ex: kill -9 (signal will always be caught)
23. id - print name, ID, group and group ID.
24. df - disk space on file systems.
25. du - disk usage.
26. lpr - send a job to the printer
27. uname - prints o/s release information
Ex: uname -a (list all info)
28. nm - print symbol name list for object files
29. ar - create library archives, add or extract files
Ex:
ar d (delete archive)
ar x (extract archive)
ar t (list contents of archive)
30. ranlib - makes table of contents for an archive
31. ipcs - interprocess communication facilities status
Ex:
ipcs -s (print semaphore information)
ipcs -m (print shared memory information)
ipcs -b (print size information)
32. ipcrm - delete ipc facilities
Ex:
ipcrm -s
ipcrm -m
33. chown - change ownership of a file
Ex:
chown joe myfile (make joe the owner of myfile)
chown -R joe mydir (recursive change owner)
34. chgrp - change group
35. newgrp - new group
newgrp dba (Add a new group called dba)
36. file - lists file type. Note: the type of file may be misleading.
37. ln - links (ln -s: create a soft link - saves space)
38. su - super-user or set user
39. dd - file conversion and copy utility Ex: dd if=myfile of=newfile conv=ucase (converts to uppercase)
40. diff - file differences.
41. umask - sets default permission for new files and directories
42. stty - terminal settings
Ex:
stty erase h (resets erase character to 'h')
stty -a (list all current settings)
43. tty - lists terminal
44. cpio - copy file archives
Ex: cpio -icBdvmu < /dev/rmt0
45. tar - tape archives Ex: tar xvt /dev/rmt0
46. telnet - use TELNET protocol to access another machine
47. rlogin - remote login
48. echo - echo command
49. ulimit - (att) - defines the max size of files on some systems.
50. vmstat - report virtual memory statistics
51. pstat - do determine resource such as swap etc ..
52. make - this is a command generator.
53. env - list environment variables (printenv on some machines.)
54. logname - lists login id from env variable LOGNAME.
55. hostname - lists host name
65. pstat -s reports system swap area (BSD) swap -l reports system swap area (AT&T)
can -n - prints with the line number to the standard output.
Getting Help
---------------
whatis echo = To learn more about the program
man echo = Help pages of echo
man -k echo = To find the appropriate command similar to (apropos echo)
History
----------
history = will list the last 500 commands used
!-3 = To run the 3rd command from the last
!144 = To run the 144 command
To set a variable at the command prompt
$VAR123=100 to set permanently set it in .profile
Regular Expressions and Wildcards
Many Linux commands use the wildcards * and ? to match any number of characters or any single character respectively; regular pattern-matching expressions utilize a period (.) to match any single character except "new line." Both use square brackets ([ ]) to match sets of characters in addition to *. The *, however, has a similar but different meaning in each case: Although it will match one or more characters in the shell, it matches zero or more instances of the preceding character in a regular expression. Some commands, like egrep and awk, use a wider set of special characters for pattern matching.
$ umask 022
This would result in a default file permission of 755 for all new files created by the user.
Renaming Files
Two popular ways to give a file more than one name are with links and the alias command. Alias can be used to rename a longer command to something more convenient such as:
$ alias ll='ls -l'
$ ll
Error messages are redirected and appended with 2> and 2>> using the format:
$ command 2> name_of_error_file
To avoid unintentionally overwriting an existing file, use the BASH built-in command set:
$ set -o noclobber
Grep, fgrep and egrep all print lines matching a pattern. All three commands search files for a specified pattern, which is helpful if you can't remember the name of a needed file. The basic format is:
grep [options] PATTERN [FILE...]
$ grep -r 'Subject' nsmail
Perhaps the most useful option with grep is -s. If you search through system files as anything other than root, error messages will be generated for every file to which you do not have access permission. This command suppresses those messages.
Fgrep, also invoked as grep -F, looks only for fixed strings, rather than the regular expressions that grep accepts. While egrep accepts patterns containing a wider selection of special characters, such as |, which signifies the conditional OR operator.
One of the most powerful search tools is the -exec action used with grep:
$ find . -name '*.html' -exec grep 'mailto:foo@yahoo.com' {} \;
Here we have asked find to start in the current directory,
Next Steps
Download Oracle Database 10g for Linux
Visit and bookmark the Linux Technology Center
., look for an html file, *.html, and execute -exec the grep command on the current file, {}. When using the -exec action, a semicolon, ;, is required, as it is for a few other actions when using find. The backslash, \, and quotes are needed to ensure that BASH passes these terms through so they are interpreted by the command rather than the shell.
A better approach is to make the permissions similar to those of another file. This command makes the permissions of file2 the same as file1:
chmod --reference file1 file2
File Types
When you see a file, how do you know what type of file it is? The command file tells you that. For instance
# file -z initTESTAUX.ora.Z = to find the file types of compressed files
To check the linked file types
# file spfile+ASM.ora.ORIGINAL
spfile+ASM.ora.ORIGINAL: symbolic link to
/u02/app/oracle/admin/DBA102/pfile/spfile+ASM.ora.ORIGINAL
This is useful; but what type of file is that is being pointed to? Instead of running file again, you can use the option -l:
# file -L spfile+ASM.ora.ORIGINAL
spfile+ASM.ora.ORIGINAL: data
ere is an example:
# cmp -s file3 file4
# echo $?
0
The special variable $? indicates the return code from the last executed command. In this case it’s 0, meaning the files file1 and file2 are identical.
# cmp -s file1 file2
# echo $?
1
# md5sum file1 file2 > f1f2
Later, when you want to verify that the files are still untouched:
# md5sum --check f1f2
file1: OK
file2: OK
--------------
1. man - manual pages
Ex: man ls (displays the help for the command ls)
2. passwd - changing passwords
3. date - system date
4. who - lists all users logged in
5. whoami - lists who you are.
6. cal - displays the calendar Ex: cal 1990 cal 6 1994
7. pwd - print working directory
8. cd [dir] - change directory
Ex:
cd ../ (moves back one directory)
cd (goes to your default directory)
9. ls [options] [names] - list contents
Ex:
ls -l (long listing)
ls -lg (long listing including group)
ls -a (list all files including dot files)
ls -lt (sort files by timestamp)
ls -l raj.txt (displays long listing for the file raj.txt)
10. more - displays a file a screenful at a time
Ex: more tempfile Note: On many att machines you may have to use pg instead
11. cat - displays/types an entire file Ex: cat -b file1
12. mkdir - make a new directory Ex: mkdir -p /tmp/usr1/fred (create intermediate directories also)
13. mv [options] sources target - move a file
Ex:
mv -i (prompt in case you are overwriting a file)
14. cp - copy a file
Ex:
cp -i (prompt in case you are overwriting a file)
cp -r (recursive copy for directories)
15. rm - remove a file
Ex:
rm -i (prompt before deletion)
rm -r (remove files recursively)
16. rmdir - remove a directory. Ex: rmdir tempdir
17. chmod - change the permission of a file.
Ex:
chmod +x tempfile (add execute permission)
chmod u+x tempfile (add execute for user only)
chmod 4755 oracle (set the setuid bit on)
18. grep - search a file for a string or expression.
Ex:
grep -n (print line numbers)
grep -i (ignore case sensitivity)
19. find - search for files.
Ex:
find . -name sqlplus -print (find the full pathname of sqlplus starting from the current directory)
find . -name '*sql*' -print (find the full pathname of file where 'sql' is in its name)
20. wc - word count
Ex:
wc -l (line count)
wc -w (word count)
wc -c (character count)
21. ps - display process status
Ex: ps -aux (ucb) ps -ef (att)
22. kill - send a signal to terminate a process.
Ex: kill -9 (signal will always be caught)
23. id - print name, ID, group and group ID.
24. df - disk space on file systems.
25. du - disk usage.
26. lpr - send a job to the printer
27. uname - prints o/s release information
Ex: uname -a (list all info)
28. nm - print symbol name list for object files
29. ar - create library archives, add or extract files
Ex:
ar d (delete archive)
ar x (extract archive)
ar t (list contents of archive)
30. ranlib - makes table of contents for an archive
31. ipcs - interprocess communication facilities status
Ex:
ipcs -s (print semaphore information)
ipcs -m (print shared memory information)
ipcs -b (print size information)
32. ipcrm - delete ipc facilities
Ex:
ipcrm -s
ipcrm -m
33. chown - change ownership of a file
Ex:
chown joe myfile (make joe the owner of myfile)
chown -R joe mydir (recursive change owner)
34. chgrp - change group
35. newgrp - new group
newgrp dba (Add a new group called dba)
36. file - lists file type. Note: the type of file may be misleading.
37. ln - links (ln -s: create a soft link - saves space)
38. su - super-user or set user
39. dd - file conversion and copy utility Ex: dd if=myfile of=newfile conv=ucase (converts to uppercase)
40. diff - file differences.
41. umask - sets default permission for new files and directories
42. stty - terminal settings
Ex:
stty erase h (resets erase character to 'h')
stty -a (list all current settings)
43. tty - lists terminal
44. cpio - copy file archives
Ex: cpio -icBdvmu < /dev/rmt0
45. tar - tape archives Ex: tar xvt /dev/rmt0
46. telnet - use TELNET protocol to access another machine
47. rlogin - remote login
48. echo - echo command
49. ulimit - (att) - defines the max size of files on some systems.
50. vmstat - report virtual memory statistics
51. pstat - do determine resource such as swap etc ..
52. make - this is a command generator.
53. env - list environment variables (printenv on some machines.)
54. logname - lists login id from env variable LOGNAME.
55. hostname - lists host name
65. pstat -s reports system swap area (BSD) swap -l reports system swap area (AT&T)
can -n - prints with the line number to the standard output.
Getting Help
---------------
whatis echo = To learn more about the program
man echo = Help pages of echo
man -k echo = To find the appropriate command similar to (apropos echo)
History
----------
history = will list the last 500 commands used
!-3 = To run the 3rd command from the last
!144 = To run the 144 command
To set a variable at the command prompt
$VAR123=100 to set permanently set it in .profile
Regular Expressions and Wildcards
Many Linux commands use the wildcards * and ? to match any number of characters or any single character respectively; regular pattern-matching expressions utilize a period (.) to match any single character except "new line." Both use square brackets ([ ]) to match sets of characters in addition to *. The *, however, has a similar but different meaning in each case: Although it will match one or more characters in the shell, it matches zero or more instances of the preceding character in a regular expression. Some commands, like egrep and awk, use a wider set of special characters for pattern matching.
$ umask 022
This would result in a default file permission of 755 for all new files created by the user.
Renaming Files
Two popular ways to give a file more than one name are with links and the alias command. Alias can be used to rename a longer command to something more convenient such as:
$ alias ll='ls -l'
$ ll
Error messages are redirected and appended with 2> and 2>> using the format:
$ command 2> name_of_error_file
To avoid unintentionally overwriting an existing file, use the BASH built-in command set:
$ set -o noclobber
Grep, fgrep and egrep all print lines matching a pattern. All three commands search files for a specified pattern, which is helpful if you can't remember the name of a needed file. The basic format is:
grep [options] PATTERN [FILE...]
$ grep -r 'Subject' nsmail
Perhaps the most useful option with grep is -s. If you search through system files as anything other than root, error messages will be generated for every file to which you do not have access permission. This command suppresses those messages.
Fgrep, also invoked as grep -F, looks only for fixed strings, rather than the regular expressions that grep accepts. While egrep accepts patterns containing a wider selection of special characters, such as |, which signifies the conditional OR operator.
One of the most powerful search tools is the -exec action used with grep:
$ find . -name '*.html' -exec grep 'mailto:foo@yahoo.com' {} \;
Here we have asked find to start in the current directory,
Next Steps
Download Oracle Database 10g for Linux
Visit and bookmark the Linux Technology Center
., look for an html file, *.html, and execute -exec the grep command on the current file, {}. When using the -exec action, a semicolon, ;, is required, as it is for a few other actions when using find. The backslash, \, and quotes are needed to ensure that BASH passes these terms through so they are interpreted by the command rather than the shell.
A better approach is to make the permissions similar to those of another file. This command makes the permissions of file2 the same as file1:
chmod --reference file1 file2
File Types
When you see a file, how do you know what type of file it is? The command file tells you that. For instance
# file -z initTESTAUX.ora.Z = to find the file types of compressed files
To check the linked file types
# file spfile+ASM.ora.ORIGINAL
spfile+ASM.ora.ORIGINAL: symbolic link to
/u02/app/oracle/admin/DBA102/pfile/spfile+ASM.ora.ORIGINAL
This is useful; but what type of file is that is being pointed to? Instead of running file again, you can use the option -l:
# file -L spfile+ASM.ora.ORIGINAL
spfile+ASM.ora.ORIGINAL: data
ere is an example:
# cmp -s file3 file4
# echo $?
0
The special variable $? indicates the return code from the last executed command. In this case it’s 0, meaning the files file1 and file2 are identical.
# cmp -s file1 file2
# echo $?
1
# md5sum file1 file2 > f1f2
Later, when you want to verify that the files are still untouched:
# md5sum --check f1f2
file1: OK
file2: OK
Comments