Sei sulla pagina 1di 28

What is Unix ?

The UNIX operating system is a set of programs that act as a link between the computer and the user. The computer programs that allocate the system resources and coordinate all the details of the computer's internals is called the operating system or kernel. Users communicate with the kernel through a program known as the shell. The shell is a command line interpreter; it translates commands entered by the user and converts them into a language that is understood by the kernel. Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. Unix and BSD are few examples. Linux is also a flavour of Unix which is freely available. lled a multiuser system. multitasking. Unix Architecture: Here is a basic block diagram of a UNIX system:

The main concept that unites all versions of UNIX is the following four basics: Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of the tasks like memory management, tash scheduling and file management. Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are most famous shells which are available with most of the Unix variants. Commands and Utilities: There are various command and utilities which you would use in your day to day activities. cp, mv, cat and grep etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various optional options. Files and Directories: All data in UNIX is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the filesystem. 2. Features of UNIX: The UNIX Operating System is available on machines with a wide range of computing power, from microcomputers to mainframes, and on different manufacture's machines. No other operating system can make this claim. We see the reasons of popularity and success of UNIX. The reasons are Portability: The system is written in high-level language making it easier to read, understand, change and, therefore move to other machines. The code can be changed and complied on a new machine. Customers can then choose from a wide variety of hardware vendors without being locked in with a particular vendor. Machine-independence: The System hides the machine architecture from the user, making it easier to write applications that can run on micros, mins and mainframes. Multi-User Operations: UNIX is a multi-user system designed to support a group of users simultaneously. The system allows for the sharing of processing power and peripheral resources, white at the same time providing excellent security features. Hierarchical File System: UNIX uses a hierarchile file structure to store information. This structure has the maximum flexibility in grouping information in a way that reflects its natural state. It allows for easy maintenance and efficient implementation. UNIX shell: UNIX has a simple user interface called the shell that has the power to provide the services that the user wants. It protects the user from having to know the intricate hardware details. Pipes and Filters: UNIX has facilities called Pipes and Filters which permit the user to create complex programs from simple programs. Utilities: UNIX has over 200 utility programs for various functions. New utilities can be built effortlessly by combining existing utilities.

Software Development Tools: UNIX offers an excellent variety of tools for software development for all phases, from program editing to maintenance of software, 3. Directory related commands:A directory is a file whose sole job is to store file names and related information. All files, whether ordinary, special, or directory, are contained in directories.UNIX uses a hierarchical structure for organizing files and directories. This structure is often referred to as a directory tree . The tree has a single root node, the slash character ( /), and all other directories are contained below it. Pwd:short for print working directory the pwd command displays the name of the current working directory. Syntax:pwd Examples:pwd Mkdir: Short for make directory this command is used to create a new directory. Syntax:mkdir directory -m mode -p -v -Z Directory Set permission mode (as in chmod), not rwxrwxrwx - umask. No error if existing, make parent directories as needed. Print a message for each created directory (SELinux) set security context to CONTEXT The name of the directory that you wish to create.

Examples:mkdir mydir The above command creates a new directory called mydir. mkdir -m a=rwx mydir This next example would use the -m option to not only create the mydir directory but also set the permissions to all users having read, write, and execute permissions. Ls:Lists the contents of a directory. Syntax:ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o] [-p] [-q] [r] [-R] [-s] [-t] [-u] [-x] [pathnames] -a -A -b Shows you all files, even files that are hidden (these files begin with a dot.) List all files including the hidden files. However, does not display the working directory (.) or the parent directory (..). Force printing of non-printable characters to be in octal \ddd notation.

-c -C -d -f

Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n). Multi-column output with entries sorted down the columns. Generally this is the default option. If an argument is a directory it only lists its name not its contents. Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory. Mark directories with a trailing slash (/), doors with a trailing greaterthan sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=). Same as -l except the owner is not printed. For each file, print the i-node number in the first column of the report. Shows you huge amounts of information (permissions, owners, size, and when last modified.) If an argument is a symbolic link, list the file or directory the link references rather than the link itself. Stream output format; files are listed across the page, separated by commas. The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the associated character strings. The same as -l, except that the group is not printed. Displays a slash ( / ) in front of all directories. Force printing of non-printable characters in file names as the character question mark (?). Reverses the order of how the files are displayed. Includes the contents of subdirectories. Give size in blocks, including indirect blocks, for each entry. Shows you the files in modification time. Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option). Displays files in columns. Print one entry per line of output.

-F

-g -i -l -L -m -n -o -p -q -r -R -s -t -u -x -1

Pathnames Examples ls -l

File or directory to list.

In the above example this command would list each of the files in the current directory and the files permissions, the size of the file, date of the last modification, and the file name or directory. Below is additional information about each of the fields this command lists. Permissions drwx-----drwxr-s---rw------Directories 2 35 1 Group users www users Size 4096 32768 3 Date Nov 2 19:51 Jan 20 22:39 Nov 25 02:58 Directory or file mail/ public_html/ test.txt

Below is a brief description of each of the above categories shown when using the ls -l command. Permissions - The permissions of the directory or file. Directories - The amount of links or directories within the directory. The default amount of directories is going to always be 2 because of the . and .. directories. Group - The group assigned to the file or directory Size - Size of the file or directory. Date - Date of last modification. Directory of file - The name of the file or file. Tip: Our favorite ls command, which lists files with permissions, shows hidden files, displays in a column format, and doesn't show the group. ls -1 | wc -l Count how many files and directories are in the current directory. To prevent any confusion, the above command reads ls <dash><the #1> <pipe> ls <dash><the letter l>. This command uses the ls command to list files in a bare format and pipes the output into the wc command to count how many files are listed. When done properly, the terminal should return a single number indicating how many lines were counted and then return you to the prompt. Tip: Keep in mind that this is also counting the ./ and ../ directories.

ls ~:List the contents of your home directory by adding a tilde after the ls command. ls /:List the contents of your root directory. ls ../:List the contents of the parent directory. ls */:List the contents of all sub directories. ls -d */:Only list the directories in the current directory. Cd:Changes the directory. Syntax:cd [directory] directory cd .. Name of the directory user wishes to enter. Used to go back one directory on the majority of all Unix shells. It is important that the space be between the cd and the .. When in a Korn shell to get back one directory used to go back one directory.

cd -

Examples:cd ../../:Next, the above example would go back two directories. Cd:Finally, typing just cd alone will move you into the home directory. If you're familiar with MS-DOS and how typing cd alone prints the working directory. Linux and Unix users can print the working directory by using the pwd command. Rmdir:Deletes a directory. Syntax:rmdir [OPTION]... DIRECTORY... Examples:rmdir mydirRemoves the directory mydir rm -rf directory/ Remove a directory, even if files existed within that directory. File handling and text processing utilities Cp: Copies files from one location to another.Syntax: cp source_file destination_file Rename:To change the name of a file use the mv command. Its basic syntax is: [amrood]$ mv old_file new_file

Following is the example which would rename existing file filename to newfile: [amrood]$ mv filename newfile [amrood]$ Rm: To delete an existing file use the rm command. Its basic syntax is: [amrood]$ rm filename Lp:The command lp or lpr prints a file onto paper as opposed to the screen display. Once you are ready with formatting using pr command, you can use any of these commands to print your file on printer connected with your computer. Your system administrator has probably set up a default printer at your site. To print a file named food on the default printer, use the lp or lpr command, as in this example: [amrood]$lp food request id is laserp-525 (1 file) [amrood]$ Ln:used to link 2 files/directories to eachother to access the data one file to another file.Examples:ln file1 file2 Cat: Allows you to look, modify or combine a file. cat file1.txt file2.txt > file3.txt Reads file1.txt and file2.txt and combines those files to make file3.txt. More: Displays text one screen at a time. Syntax:More filename Examples more +3 myfile.txt In the above example the command would begin displaying the file myfile.txt at line three. Pg:Files perusal filters for CRTs. Syntax:pg [-number] [-p string] [-c] [-e] [-f] [-n] [-r][-s] [+ linenumber] [+/ pattern /] [filename] -number An integer specifying the size (in lines) of the window that pg is to use instead of the default. (On a terminal containing 24 lines, the

default window size is 23). -p string pg uses string as the prompt. If the prompt string contains a %d, the first occurrence of %d in the prompt will be replaced by the current page number when the prompt is issued. The default prompt string is ``:''. Home the cursor and clear the screen before displaying each page. This option is ignored if clear_screen is not defined for this terminal type in the terminfo(4) data base. pg does not pause at the end of each file. Normally, pg splits lines longer than the screen width, but some sequences of characters in the text being displayed (for instance, escape sequences for underlining) generate undesirable results. The f option inhibits pg from splitting lines. Normally, commands must be terminated by a <new line> character. This option causes an automatic end of command as soon as a command letter is entered Restricted mode. The shell escape is disallowed. pg prints an error message but does not exit. pg prints all messages and prompts in the standard output mode (usually inverse video). Start up at linenumber. Start up at the first line containing the regular expression pattern. A path name of a text file to be displayed. If no filename is given, or if it is -, the standard input is read.

-c

-e -f

-n

-r -s +linenumber |/pattern/ filename

Examples:pg myfile.txt.Execute and display the file myfile.txt. Head:Displays the first ten lines of a file, unless otherwise stated. Syntax:head [-number | -n number] filename -number -n number filename The number of the you want to display. The number of the you want to display. The file that you want to display the x amount of lines of.

Examples:head -15 myfile.txt Display the first fifteen lines of myfile.txt.

Tail:Delivers the last part of the file. Syntax:tail file name Examples:tail myfile.txt The above example would list the last 10 (default) lines of the file myfile.txt. Sort: Sorts the lines in a text file. Syntax: sort [-b] [-d] [-f] [-i] [-m] [-M] [-n] [-r] [-u] [+fields] filename [-o outputfile] -b -d -f -i -m -M -n -r -u +fields Filename -o outputfile Ignores spaces at beginning of the line. Uses dictionary sort order and ignores the punctuation. Ignores caps Ignores nonprinting control characters. Merges two or more input files into one sorted output. Treats the first three letters in the line as a month (such as may.) Sorts by the beginning of the number at the beginning of the line. Sorts in reverse order If line is duplicated only display once Sorts by fields , usually by tabs The name of the file that needs to be sorted. Sends the sorted output to a file.

Examples:sort -r file.txt Sort the file, file.txt in reverse order. Grep:Finds text within a file. Syntax:grep [options] PATTERN [FILE...] Egrep: Search a file for a pattern using full regular expressions. Syntax: egrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list ] [-f file ] [ strings ] [ file]

-b -c -h -i -l

Precede each line by the block number on which it was found. This can be useful in locating block numbers by context (first block is 0). Print only a count of the lines that contain the pattern. Suppress printing of filenames when searching multiple files. Ignore upper/lower case distinction during comparisons. Print the names of files with matching lines once, separated by NEWLINEs. Does not repeat the names of files when the pattern is found more than once. Precede each line by its line number in the file (first line is 1). Work silently, that is, display nothing except error messages. This is useful for checking the error status. Print all lines except those that contain the pattern. Consider only input lines that use all characters in the line to match an entire fixed string or regular expression to be matching lines. Search for a pattern_list (full regular expression that begins with a -). Take the list of full regular expressions from file. Specify a pattern to be used during the search for input. A path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used.

-n -s -v -x -e pattern_list -f file Strings File

Examples:egrep "support|help|windows" myfile.txt Search for patterns of support help and windows in the file myfile.txt. Fgrep:Search a file for a fixed-character string. Syntax fgrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list] [-f pattern-file] [pattern] [ file] -b -c -h -i -l Precede each line by the block number on which it was found. This can be useful in locating block numbers by context (first block is 0). Print only a count of the lines that contain the pattern. Suppress printing of files when searching multiple files. Ignore upper/lower case distinction during comparisons. Print the names of files with matching lines once, separated by new-

lines. Does not repeat the names of files when the pattern is found more than once. -n -s -v -x -e pattern_list -f pattern-file Pattern File Precede each line by its line number in the file (first line is 1). Work silently, that is, display nothing except error messages. This is useful for checking the error status. Print all lines except those that contain the pattern. Print only lines matched entirely. Search for a string in pattern-list (useful when the string begins with a -). Take the list of patterns from pattern-file. Specify a pattern to be used during the search for input. A path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used.

Examples:fgrep "support" myfile.txt.Search for support in the file myfile.txt. Cut:Cut out selected fields of each line of a file. Syntax:cut [-b] [-c] [-f] list [-n] [-d delim] [-s] [file] -b list The list following -b specifies byte positions (for instance, -b1-72 would pass the first 72 bytes of each line). When -b and -n are used together, list is adjusted so that no multi-byte character is split. If -b is used, the input line should contain 1023 bytes or less. The list following -c specifies character positions (for instance, -c172 would pass the first 72 characters of each line). The list following -f is a list of fields assumed to be separated in the file by a delimiter character (see -d ); for instance, -f1,7 copies the first and seventh field only. Lines with no field delimiters will be passed through intact (useful for table subheadings), unless -s is specified. If -f is used, the input line should contain 1023 characters or less. A comma-separated or blank-character-separated list of integer field numbers (in increasing order), with optional - to indicate ranges (for instance, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short for third through last field)). Do not split characters. When -b list and -n are used together, list is adjusted so that no multi-byte character is split.

-c list -f list

List

-n

-d delim

The character following -d is the field delimiter (-f option only). Default is tab. Space or other characters with special meaning to the shell must be quoted. delim can be a multi-byte character. Suppresses lines with no delimiter characters in case of -f option. Unless specified, lines with no delimiters will be passed through untouched. A path name of an input file. If no file operands are specified, or if a file operand is -, the standard input will be used.

-s

File

Examples:name=`who am i | cut -f1 -d' '` Set name to current login name. Paste:Merge corresponding or subsequent lines of files. Syntax:paste [-s] [-d list] file -s Concatenate all of the lines of each separate input file in command line order. The NEWLINE character of every line except the last line in each input file will be replaced with the TAB character, unless otherwise specified by the -d option. Unless a backslash character (\) appears in list, each character in list is an element specifying a delimiter character. If a backslash character appears in list, the backslash character and one or more characters following it are an element specifying a delimiter character as described below. These elements specify one or more delimiters to use, instead of the default TAB character, to replace the NEWLINE character of the input lines. The elements in list are used circularly; that is, when the list is exhausted the first element from the list is reused. When the -s option is specified:

-d list

The last newline character in a file will not be modified. The delimiter will be reset to the first element of list after each file operand is processed.

When the option is not specified:


The NEWLINE characters in the file specified by the last file will not be modified. The delimiter will be reset to the first element of list each time a line is processed from each file.

If a backslash character appears in list, it and the character following it will be used to represent the following delimiter characters: \n \t \\ \0 Newline character. Tab character. Backslash character. Empty string (not a null character). If \0 is immediately followed by the character x, the character X, or any character defined by the LC_CTYPE digit keyword, the results are unspecified.

If any other characters follow the backslash, the results are unspecified. File A path name of an input file. If - is specified for one or more of the file s, the standard input will be used; the standard input will be read one line at a time, circularly, for each instance of -. Implementations support pasting of at least 12 file operands.

Examples The below example would take the input from ls and paste that input into four columns. ls | paste - - - join: The join command forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. Syntaxjoin [-a filenumber | -v filenumber ] [ -1 fieldnumber ] [ -2 fieldnumber ] [ -o list ] [ -e string ] [ -t char ] file1 file2 join [ -a filenumber ] [ -j fieldnumber ] [-j1 fieldnumber ] [ -j2 fieldnumber ] [ -o list ] [-e string ] [ -t char ] file1 file2 -a filenumber In addition to the normal output, produce a line for each unpairable line in file filenumber, where filenumber is 1 or 2. If both -a 1 and -a 2 are specified, all unpairable lines will be output. Instead of the default output, produce a line only for each unpairable line in filenumber, where filenumber is 1 or 2. If both -v 1 and -v 2 are specified, all unpairable lines will be output. Join on the fieldnumberth field of file 1 . Fields are decimal integers starting with 1. Join on the fieldnumberth field of file 2. Fields are decimal integers

-v filenumber

-l fieldnumber -2 fieldnumber

starting with 1. -j fieldnumber Equivalent to -1fieldnumber -2fieldnumber.

-j1 fieldnumber Equivalent to -1fieldnumber. -j2 fieldnumber Equivalent to -2fieldnumber Fields are numbered starting with 1. -o list Each output line includes the fields specified in list. Fields selected by list that do not appear in the input will be treated as empty output fields. (See the -e option.) Each element of which has the either the form filenumber.fieldnumber, or 0, which represents the join field. The common field is not printed unless specifically requested. Replace empty output fields with string. Use character char as a separator. Every appearance of char in a line is significant. The character char is used as the field separator for both input and output. With this option specified, the collating term should be the same as sort without the -b option. File name or directory and file name of the files being joined

-e string -t char

file1 file2

Tee:Read from an input and write to a standard output and file. Syntax:tee [OPTION]... [FILE]... -a --append -i --help --version Examples ls *.txt | wc -l | tee /dev/tty count.txt In the above example the ls command would list all .txt files in the current directory, take a word count (wc) by the amount of lines (-l) and the output displayed to the /dev/tty (terminal) will be sent to the count.txt. Note: Because the above example did not take advantage of the -a or append option if the count.txt file already existed it would have been overwritten. Append to the given FILEs, do not overwrite. ignore interrupt signals. Display the help screen. Display the version.

W: Displays information about the users currently on the machine, and their processes. The header shows, in this order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. Syntax:w [-husfVo] [user] -h -u -s -f Don't print the header. Ignores the username while figuring out the current process and cpu times. To demonstrate this, do a "su" and do a "w" and a "w -u". Use the short format. Don't print the login time, JCPU or PCPU times. Toggle printing the from (remote hostname) field. The default as released is for the from field to not be printed, although your system administrator or distribution maintainer may have compiled a version in which the from field is shown by default. Display version information. Old style output. Prints blank space for idle times less than one minute. Show information about the specified user only.

-V -o User

Examples:w:-Would display information similar to the below example. 18:31:58 up 156 days, 5:16, 64 users, load average: 0.27, 0.27, 0.27 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT Chgrp:For system V, changes the group that has access to a file or directory. Syntax:chgrp newgroup filenames [-f] [-h] newgroup filenames -f -h Specifies the new group that you wish to allow access to. Specifies the files that the newgroup has access to. Force. Do not report errors. If the file is a symbolic link, change the group of the symbolic link. Without this option, the group of the file referenced by the symbolic link is changed. Recursive. chgrp descends through the directory, and any subdirectories, setting the specified group ID as it proceeds. When a symbolic link is encountered, the group of the target file is changed (unless the -h option is specified), but no recursion takes place.

-R

Examples:chgrp hope file.txt Change the group to hope for the file file.txt if present and the group hope is valid. Chmod:Changes the permission of a file. Syntax:chmod [OPTION]... MODE[,MODE]... FILE... Permissions u - User who owns the file. g - Group that owns the file. o - Other. a - All. r - Read the file. w - Write or edit the file. x - Execute or run the file as a program. Numeric Permissions: CHMOD can also to attributed by using Numeric Permissions: 400 read by owner 040 read by group 004 read by anybody (other) 200 write by owner 020 write by group 002 write by anybody 100 execute by owner 010 execute by group 001 execute by anybody Examples:The above numeric permissions can be added to set a certain permission, for example, a common HTML file on a Unix server to be only viewed over the Internet would be: chmod 644 file.htmThis gives the file read/write by the owner and only read by everyone else (-rw-r--r--). Files such as scripts that need to be executed need more permissions. Below is another example of a common permission given to scripts.chmod 755 file.cgi:This would be the following 400+040+004+200+100+010+001 = 755 where you are giving all the rights except the capability for anyone to write to the file.cgi file(-rwxr-xr-x). chmod 666 file.txt:Finally, another common CHMOD permission is 666, as shown below, which is read and write by everyone. Chown :Command for system V that changes the owner of a file. Syntax:chown [-R] newowner filenames

-R newowner filenames

Change the permission on files that are in the subdirectories of the directory that you are currently in. The alias/username of the new owner of the file. The file that you are changing the rights to.

Examples:chown chope file.txt Give permissions as owner to user chope for the file file.txt. chown -R chope work Give chown permissions to chope for all files in the work directory. Related commands Find:Finds one or more files assuming that you know their approximate filenames. Syntax:find path expressions Examples:find -name 'mypage.htm'In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory. find / -name 'mypage.htm'In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root. find -name 'file*'In the above example the system would search for any file beginning with file in the current directory and any subdirectory. find -name '*' -size +1000kIn the above example the system would search for any file that is larger then 1000k. find . -size +500000 -printNext, similar to the above example, just formatted differently this command would find anything above 500MB. Cmp: Compares two files and tells you what line numbers are different. Syntax:cmp file1 file2 Examplescmp file1.txt file2.txtCompares file1 to file2 and outputs results. Below is example of how these results may look. file.txt file2.txt differ: char 1011, line 112 Diff: Displays two files and prints the lines that are different. Syntax:diff file1 file2

Examples:diff help dir2 Compares the directory named help with the directory named dir2. Below is an example of the output when typing this command. Only in help: tab2.gif Only in help: tab3.gif Only in help: tab4.gif Only in help: tape.htm Only in help: tbernoul.htm Only in help: tconner.htm Only in help: tempbus.psd Uniq: Report or filter out repeated lines in a file. Syntax:uniq file1 file2 Examplesuniq myfile1.txt > myfile2.txt - Removes duplicate lines in the first file1.txt and outputs the results to the second file. Tr: Translate characters. Syntax:tr [-c] [-d] [-s] [string1] [string2] -c -d -s string1 string2 Complement the set of characters specified by string1. Delete all occurrences of input characters that are specified by string1. Replace instances of repeated characters with a single character. First string or character to be changed. Second string or character to change the string1.

Examples:echo "12345678 9247" | tr 123456789 computerhThis example takes an echo response of '12345678 9247' and pipes it through the tr replacing the appropriate numbers with the letters. In this example it would return computer hope. tr -cd '\11\12\40-\176' < myfile1 > myfile2 This example would take the file myfile1 and strip all non printable characters and take that results to myfile2. Disk utilities, backup and other utilities: Du: Tells you how much space a file occupies.

Syntax: du [-a] [-k] [-s] [-d] [-L] [-o] [-r] [-x] directories -a -k -s -d -L -o Displays the space that each file is taking up. Write the files sizes in units of 1024 bytes, rather than the default 512-byte units. Instead of the default output, report only the total sum for each of the specified files. Do not cross filesystem boundaries. For example, du -d / reports usage only on the root partition. Process symbolic links by using the file or directory which the symbolic link references, rather than the link itself. Do not add child directories' usage to a parent's total. Without this option, the usage listed for a particular directory is the space taken by the files in that directory, as well as the files in all directories beneath it. This option does nothing if -s is used. Generate messages about directories that cannot be read, files that cannot be opened, and so forth, rather than being silent (the default). When evaluating file sizes, evaluate only those files that have the same device as the file specified by the file operand. Specifies the directory or directories.

-r -x directories

Examples:du -s *.txt - Would report the size of each txt file in the current directory. Below is an example of the output. 8 8 10 2 8 8 file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt

du -ch *.txt - Display the size of the txt files in a friendly size format listing as well as the total capacity of all the files combined. Df:Report how much free disk space is available for each mount you have. Syntax:df [OPTION]... [FILE]... -a, --all -B, --block-size=SIZE include dummy file systems use SIZE-byte blocks

-h, --human-readable -H, --si -i, --inodes -k -l, --local --no-sync -P, --portability --sync -t, --type=TYPE -T, --print-type

print sizes in human readable format (e.g., 1K 234M 2G) likewise, but use powers of 1000 not 1024 list inode information instead of block usage like --block-size=1K limit listing to local file systems do not invoke sync before getting usage info (default) use the POSIX output format invoke sync before getting usage info limit listing to file systems of type TYPE print file system type

-x, --exclude-type=TYPE limit listing to file systems not of type TYPE --version Examples: Df:In the above example when performing just the df command with no additional switches or specification of the file or directory you would get a listing of all file systems and their used and available space. df h:The above command is one of the most commonly used commands as it displays the sizes in an easy to read format as shown in the below example. Filesystem /dev/hda2 tmpfs Tmpfs /dev/hda1 /dev/hda3 nfs6:/home mirrors:/mirrors /dev/mapper/big-phat mailstore:/var/mail df -b public_html Size 28G 252M 252M 464M 8.3G 520G 1.4T 77G 9.9G Used Avail Use% Mounted on 7.6G 0 0 37M 19G 29% / /lib/init/rw /dev/shm /boot /var /home /mirrors /space /var/mail output version information and exit

252M 0% 252M 0% 403M 9% 6% 89%

429M 7.5G 461G 60G 1.1T 36G 4.8G

233G 83% 42G 4.7G 46% 51%

In the above example this command would display the amount of free space in the public_html directory. Below is an example of the output may display when performing this command. Filesystem avail nfs.computerhope.com:/home 10068252 mount and unmount Mount or unmount file systems and remote resources. Syntax: mount [-p | -v ] mount [ -F FSType ] [ generic_options ] [-o specific_options ] [ -O ] special | mount_point mount [ -F FSType ] [ generic_options ] [-o specific_options ] [ -O ] special mount_point mount -a [ -F FSType ] [ -V ] [ current_options ] [-o specific_options ] [ mount_point ... ] umount [ -V ] [ -o specific_options ] special |mount_point umount -a [ -V ] [ -o specific_options ] [ mount_point... ] -p -v -F Print the list of mounted file systems in the /etc/vfstab format. Must be the only option specified. Print the list of mounted file systems in verbose format. Must be the only option specified. Used to specify the FSType on which to operate. The FSType must be specified or must be determin able from /etc/vfstab, or by consulting /etc/default/fs or /etc/dfs/fstypes. Mount the file system without making an entry in /etc/mnttab. Mount the file system read-only. Specify FSType-specific options in a comma separated (without spaces) list of suboptions and keyword-attribute pairs for interpretation by the FSType-specific module of the command. Overlay mount. Allow the file system to be mounted over an existing mount point, making the underlying file system inaccessible. If a mount is attempted on a pre-existing mount point without setting this

-m -r -o

-O

flag, the mount will fail, producing the error "device busy". -a Perform mount or umount operations in parallel, when possible. If mount points are not specified, mount will mount all file systems whose /etc/vfstab "mount at boot" field is "yes". If mount points are specified, then /etc/vfstab "mount at boot" field will be ignored. If mount points are specified, umount will only umount those mount points. If none is specified, then umount will attempt to umount all filesystems in /etc/mnttab, with the exception of certain system required file systems: /, /usr, /var, /proc, /dev/fd, and /tmp. -V Echo the complete command line, but do not execute the command. umount generates a command line by using the options and arguments provided by the user and adding to them information derived from /etc/mnttab. This option should be used to verify and validate the command line.

Examples Mount a local disk: mount /dev/usr /usr Mount a MS-DOS floppy: mount -F dos /dev/rdsk/fds0d2.3.5 /floppy Mount a Macintosh HFS floppy: mount -F hfs /dev/rdsk/fds0d3.3.5hi /floppy Mount a HFS CD-ROM: mount -F hfs /dev/rdsk/dks0d7vol /cdrom Mount an ISO 9660 CD-ROM: mount -F iso9660 /dev/rdsk/dks0d7vol /cdrom Unmount floppy: umount /dev/fd0 Umask: by default setting the user permission Syntax:umask [-S] [000] [mask] -S Produce symbolic output. The default output style is unspecified, but will be recognized on a subsequent invocation of umask on the same system as a mask

operand to restore the previous file mode creation mask. 000 Examples Umask:Running umask alone will display the current umask environment settings. umask 000:The above example allows any permissions. This does not actually set permissions just allows permissions to be set. Tar:Create Tape ARchives (TAR) and add or extract files. Syntax:tar [options][tarfilename][dir] Examples: Note: A ".tar" file is not a compressed files, it is a collection of files within a single file uncompressed. If the file is a .tar.gz ("tarball") or ".tgz" file it is a collection of files that is compressed. If you are looking to compress a file you would create the tar file then gzip the file. Creating a tar file: tar -cvwf file.tar myfile.txt In the above example, the system would create a tar named file.tar in the directory you currently are in. Wildcards could also be used in this command, for example: tar -cvwf file.tar *.txt would archive all txt files in the current directory. tar -cvwf home.tar home/ In the above example command the system would create a tar file named home.tar containing the home directory and place that file in the current directory. Extracting the files from a tar file: tar -xvwf myfile.tar In the above example command the system would unarchive (untar) the myfile.tar file into the current directory. tar -xvwzf myfile.tar.gz In the above example command the system would unarchive (untar) the myfile.tar.gz file in the current directory. Any three octal digits used for permissions.

Tip: There is no "untar" Linux and Unix command. Creating a tarred file that is compressed with bzip tar -cjvf test.tbz home/ Adding the j option to the tar command enables tar to compress files and directories using bzip. In the above example the home directory and all its subdirectories are added to the compressed test.tbz file. Cpio:Creates and un-creates archived cpio files. And also is capable of copying files to things other than a hard disk. Syntax:cpio -3 flags Examples Find mca|cpio i>record Mail:One of the ways that allows you to read/send E-Mail. Syntax:Sending mail [-t] [-w] [ -m message_type ] recipient ... rmail [-t] [-w] [ -m message_type ] recipient ... Reading: mail [-e] [-h] [-p] [-P] [-q] [-r] [ -f file ] compress:Compacts a file so that it is smaller. When compressing a file it will be replaced with a file with the extension .Z, while keeping all the same ownership modes. Syntax compress [-c] [-f] [-v] filenames -c -f Write to the standard output; no files are changed and no .Z files are created. The behavior of zcat is identical to that of `uncompress -c'. When compressing, force compression of file , even if it does not actually reduce the size of the file, or if the corresponding file .Z file already exists. If the -f option is not given, and the process is not running in the background, prompt to verify whether an existing file .Z file should be overwritten. When uncompressing, do not prompt

for overwriting files. If the -f option is not given, and the process is not running in the background, prompt to verify whether an existing file should be overwritten. If the standard input is not a terminal and -f is not given, write a diagnostic message to standard error and exit with a status greater than 0. -v filenames Examples compress -v bigfile.exe Compress bigfile.exe and rename that file to bigfile.exe.Z. Gzip: Compress or expand files. Examples:gzip myfileCompresses the file myfile, making it myfile.gz. Note. When doing this the original file will no longer exist on the drive. gunzip -f myfile.gz:Uncompress the file myfile.gz and if the uncompressed file(s) already exist force an overwrite. When doing this the file myfile.gz will no longer be on the drive. gunzip -c myfile.gz > myfile.txt:Uncompress the file myfile.tz to the myfile.txt file, however, don't delete the .gz file. This is useful if you don't want to delete the .gz and keep it with the uncompressed file. zcat myfile:Uncompress the file myfile. Sed:Sort for Stream Editor sed allows you to use pre-recorded commands to make changes to text. Syntax:sed [ -n ] [ -e script ] ... [ -f script_file ] ... [ file ... ] -n -e script Suppress the default output. script is an edit command for sed . See USAGE below for more information on the format of script. If there is just one -e option and no -f options, the flag -e may be omitted. Take the script from script_file. script_file consists of editing commands, one per line. The sed commands to perform. A path name of a file whose contents will be read and edited. If Shows you how much the file shrank in size. The name of the file(s) that you wish to compress.

-f script_file commands file

multiple file operands are specified, the named files will be read in the order specified and the concatenation will be edited. If no file operands are specified, the standard input will be used Script: A script consists of editing commands, one per line, of the following form: [ address [ , address ] ] command [ arguments ] Zero or more blank characters are accepted before the first address and before command. Any number of semicolons are accepted before the first address. In normal operation, sed cyclically copies a line of input (less its terminating NEWLINE character) into a pattern space (unless there is something left after a D command), applies in sequence all commands whose addresses select that pattern space, and copies the resulting pattern space to the standard output (except under -n) and deletes the pattern space. Whenever the pattern space is written to standard output or a named file, sed will immediately follow it with a NEWLINE character. Some of the commands use a hold space to save all or part of the pattern space for subsequent retrieval. The pattern and hold spaces will each be able to hold at least 8192 bytes. sed Addresses: An address is either empty, a decimal number that counts input lines cumulatively across files, a $ that addresses the last line of input, or a context address, which consists of a /regular expression/. A command line with no addresses selects every pattern space. A command line with one address selects each pattern space that matches the address. A command line with two addresses selects the inclusive range from the first pattern space that matches the first address through the next pattern space that matches the second address. Thereafter the process is repeated, looking again for the first address. (If the second address is a number less than or equal to the line number selected by the first address, only the line corresponding to the first address is selected.) Typically, address are separated from each other by a comma (,). They may also be separated by a semicolon (;). Examples sed G myfile.txt > newfile.txt

In the above example using the sed command with G would double space the file myfile.txt and output the results to the newfile.txt. sed = myfile.txt | sed 'N;s/\n/\. /' The above example will use the sed command to output each of the lines in myfile.txt with the line number followed by a period and a space before each line. As done with the first example the output could be redirected to another file using > and the file name. sed 's/test/example/g' myfile.txt > newfile.txt Opens the file myfile.txt and searches for the word "test" and replaces every occurrence with the word "example". sed -n '$=' myfile.txt Above this command count the number of lines in the myfile.txt and output the results. Who: Displays who is on the system. Syntax:who Examples:who The general format for output is: name [state] line time [idle] [pid] [comment] [exit] where: name user's login name. state capability of writing to the terminal. line name of the line found in /dev. time time since user's login. idle time elapsed since the user's last activity. pid user's process id. comment comment line in inittab(4). Below is an example of what this may look like chope pts/0 Apr 23 10:43 (shell.computerhope.com)

mrhope pts/1 May 6 18:19 (shell.computerhope.com) Tip: If you're wanting to see who's been on use the last command. who -r Display the run-level of each user, as shown below. run-level 3 2010-10-15 12:43 last=S

tty: Print the file name of the terminal connected to standard input. Syntax:tty [OPTION]... -s, --silent, -quiet Examples:tty Running tty by itself will display the current tty session as shown below. /dev/pts/0 Print nothing, only return an exit status.

Potrebbero piacerti anche