A Summary of Some Useful UNIX Commands

Total Page:16

File Type:pdf, Size:1020Kb

A Summary of Some Useful UNIX Commands

CS 350 Spring 2002 2/17/02

A summary of some useful UNIX commands:

The following are useful UNIX commands with suggested or sample flags. Run the “man” command against these commands for full meaning (the items in <...> are arguments, all file names and directory names may need to be prefixed by a path name to uniquely identify them: man ... gives detailed on-line help on command “cmd”. Cmd may be any UNIX command or the name of a system or standard library call. For example: man mv, man fork, or man printf chmod xyz , where x, y, and z are octal numbers whose three bit encoding represents the permissions “read”, “write”, “execute” for the file. x is the permissions for you the owner of the file and would be private to all others. y is the permissions for a workgroup you define (default is you have no work group). z is permissions you grant to the outside world. Suggested permissions are 600 for a file you may want to change and keep private, 400 for a file you want to be read-only and to keep private, and 700 for an executable file you want to keep private and modifiable or erasable. Examples: If you want a file to be read-write for yourself and private use: chmod 600 . If you want to share a file as read-only with the outside world and make if read-write for yourself use: chmod 644 . If you want a file to be executable and read-only and also private, use: chmod 500 pwd ... gives current directory tree cp ... copies file1 to file1 cat ... displays (dumps) file1 to screen - no pausing

| more ... displays the output of the command one page at a time or more ... Displays file1 on screen one page at a time For both uses of more: space bar for next page, enter key for next line mv ... moves or renames file1 to file2 rm ... erases file1 rm -rf will remove a directory tree starting with . the "-r" tells rm to go through all subdirectories, "-f" tells it not to ask for prompts. CAREFUL: this will zap out and all of its subdirectories - even if the directory has files in it. mkdir ... creates directory dirname rmdir ... removes directory dirname ... must be empty cd ... change current directory to dirname ls -l -d -a ... lists files and directories (like dir in dos) All flags are optional -l ... gives full information (long) -d ... lists directories without giving contents -a ... lists “all” files including “hidden files” beginning with a dot You can also add a name or partial name with wild card “*” in it after the flags. logout ... logs user off session passwd ... allows user to change password ps -aef ... list processes (includes pid and names) kill ...... kills or removes process id “pid.” will ask the process to exit ... use the ps command to get the process id’s currently running kill -9 ...unconditionally kills or removes process id “pid.” without the processes consent ctrl-z ... interrupts a process ... may be continue the process by typing fg gcc -o ... compiles the C source file into executable file1 cc -o ... compiles the C source file into executable file1 g++ -o ... compiles the C source file into executable file1 ... in each case above the -o option is optional. If left out the executable will be a.out be default. ipcs … list all the system processor communication resources “loaned” out to the account. ipcrm -s semaphore id ipcrm -m shared memory id ipcrm -q msgqid

How to get rid of suspended or hung processes: First list all processes running under your user id (my_user_id), for example bf12345 ps -eaf | grep my_user_id examine the list for the hung process, suppose it is: 16309 now do: kill -9 16309 editors: pico emacs vi ... this one is un-intuitive!

Check out Barnes and Noble at the Town-Square mall for books on UNIX and C/C++. I found “UNIX Made Easy”, by Lurnix (Osborne, McGraw-Hill publ.) useful. There must be a book called “UNIX for Dummies” out there. An excellent book on C is: “The C Programming Language” by Kernighan and Ritchie (Prentice Hall). As I mentioned an excellent book on both C and UNIX is “An Introduction to ANSI C on UNIX”, by Paul Wang, Wadsworth Publishing Co.

Recommended publications