Unix Command Summary

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Unix Command Summary as PDF for free.

More details

  • Words: 955
  • Pages: 4
General apropos command Locate commands by keyword lookup. exit Terminate your current session, or shell. man command Display the Unix manual page describing a given Unix command. File System Navigation Cd Return to your home directory. Cd directory Change directory to make directory your current directory. file files Determine file type. Ls List the contents of the current directory. ls names List the contents of the directories; names can name files and/or directories: ls -l . . . in a long format, showing permissions, owner, size, and other file info. ls -a . . . all files, including “hidden” files (file names that begin with a dot “.”) . ls -R . . . recursively, for all subdirectories. ls -t . . . in time order (when modified, newest to oldest) rather than name order. pwd Display the name of the current directory, or “print working directory.” File/Directory Manipulation compress files Reduces the size of a file. uncompress files Restores compressed files to their original form. cp file1 file2 Copy file(s). cp files directory Copy file(s) into a directory. Frequently Used Unix Commands 2 of 3 cp -r dir1 dir2 Copy a directory and, recursively, its subdirectories. mkdir directory Create, or “make” a directory. mv file1 file2 Move a file or, if file1 and file2 are in the same directory, rename a file. mv files directory Move files into a directory. mv dir1 dir2 If directory dir2 exists, move dir1 into dir2; otherwise, rename dir1 as dir2. rm files Remove (erase) file(s). rm -r names Remove files, directories, and recursively, any subdirectories. rmdir directory Remove directory (directory must be empty).

TCS Internal

Data Manipulation cat files Concatenate file(s); you can use cat to display the contents of a file (this is not advisable if the file is a binary file). grep “pattern” files Display all lines in the files that match a pattern. more files Display contents of files one screen at a time. sort files Order the lines in a file or files alphabetically (this command does not alter the file or files—it merely displays the sorted output to the screen): sort -r files . . . in reverse order. sort -n files . . . numerically (puts 2 before 10 instead of after). Networking/Communications finger [email protected] Displays information about a U-M user from the U-M Online Directory. ssh hostname Connect to remote host using Secure Shell. telnet hostname Connect to a remote host using the telnet protocol. talk user Initiate a conversation with another user (end conversation with Control-C); talk works only between machines of the same architecture Miscellaneous !! Repeat last shell command. !string Repeat last shell command that began with string (for example, type “!m” to repeat the last command that began with “m”). cal Display a calendar of the current month. cal month year Display a calendar of the given month and year. Note that the year must be fully qualified, for example, “2003” and not “03.” clear Clears terminal screen. date Display the current local date and time. who Display a list of users currently logged in. % echo this this % echo $EDITOR /usr/local/bin/emacs % echo $PRINTER b129lab1

grep Use this command to search for information in a file or files. For example, suppose that we have a file dict whose contents are

TCS Internal

red rojo green verde blue azul white blanco black negro

Then we can look up items in our file like this; % grep red dict red rojo % grep blanco dict white blanco % grep brown dict %

Notice that no output was returned by grep brown. This is because "brown" is not in our dictionary file. Grep can also be combined with other commands. For example, if one had a file of phone numbers named "ph", one entry per line, then the following command would give an alphabetical list of all persons whose name contains the string "Fred". % grep Fred ph | sort Alpha, Fred: 333-6565 Beta, Freddie: 656-0099 Frederickson, Molly: 444-0981 Gamma, Fred-George: 111-7676 Zeta, Frederick: 431-0987

The symbol "|" is called "pipe." It pipes the output of the grep command into the input of the sort command. For more information on grep, consult % man grep

head Use this command to look at the head of a file. For example, % head essay.001

displays the first 10 lines of the file essay.001 To see a specific number of lines, do this: % head -20 essay.001

This displays the first 20 lines of the file. Use rm to remove files from your directory. % rm foo remove foo? y % rm letter* remove letter1? y

TCS Internal

remove letter2? y remove letter3? n %

sort Use this commmand to sort a file. For example, suppose we have a file dict with contents red rojo green verde blue azul white blanco black negro

Then we can do this:

% sort dict black negro blue azul green verde red rojo white blanco Here the output of sort went to the % sort dict >dict.sorted

screen. To store the output in file we do this:

You can check the contents of the file dict.sorted using cat , more , or emacs .

wc Use this command to count the number of characters, words, and lines in a file. Suppose, for example, that we have a file dict with contents red rojo green verde blue azul white blanco black negro

Then we can do this % wc dict 5 10

56 tmp

This shows that dict has 5 lines, 10 words, and 56 characters. The word count command has several options, as illustrated below: % wc -l dict 5 tmp % wc -w dict 10 tmp % wc -c dict 56 tmp

TCS Internal

Related Documents

Unix Command Summary
November 2019 9
Unix Command Summary
April 2020 7
Unix Command
November 2019 26
Unix Command
August 2019 26
Short Command Unix
May 2020 6
Unix Command Dictionaries
October 2019 13