Sie sind auf Seite 1von 16

cd command

Quick links About cd Syntax Examples Related commands Related Q&A Linux and Unix main page About cd Changes the directory. Syntax cd [directory] directory cd .. cd Examples cd hope The above example would go into the hope directory if it exists. cd ../home/users/computerhope The above example would go back one directory and then go into the home/users/computerhope directory. cd ../../ Next, the above example would go back two directories. 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.

Finally, typing just cd alone will move you into the home directory. If you're familiar with MSDOS and how typing cd alone prints the working directory. Linux and Unix users can print the working directory by using the pwd command.

ls command
Quick links About ls Syntax Examples Related commands Linux and Unix main page About 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 -c -C -d -f 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. 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 greater-than 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.)

-F

-g -i -l

-L -m -n -o -p -q -r -R -s -t -u -x -1 pathnames Examples ls -l

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. 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. Explanation of the ./ and ../ directories listed in the listing of files. ls -laxo 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. 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.

cp command
Quick links About cp Syntax Examples Additional information Related commands Linux and Unix main page About cp Copies files from one location to another. Syntax cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... --target-directory=DIRECTORY SOURCE... -a, --archive --backup[=CONTROL] -b --copy-contents -d --no-dereference -f, --force -i, --interactive -H -l, --link -L, --dereference -p same as -dpR make a backup of each existing destination file like --backup but does not accept an argument copy contents of special files when recursive same as --no-dereference --preserve=link never follow symbolic links if an existing destination file cannot be opened, remove it and try again prompt before overwrite follow command-line symbolic links link files instead of copying always follow symbolic links same as --preserve=mode,ownership,timestamps

-preserve the specified attributes (default: preserve[=ATTR_LIST] mode,ownership,timestamps), if possible additional attributes: links, all

--nopreserve=ATTR_LIST --parents -P -R, -r, --recursive --remove-destination --reply={yes,no,query} --sparse=WHEN --strip-trailing-slashes -s, --symbolic-link -S, --suffix=SUFFIX

don't preserve the specified attributes append source path to DIRECTORY same as '--no-dereference' copy directories recursively remove each existing destination file before attempting to open it (contrast with --force) specify how to handle the prompt about an existing destination file control creation of sparse files remove any trailing slashes from each SOURCE argument make symbolic links instead of copying override the usual backup suffix

--targetmove all SOURCE arguments into DIRECTORY directory=DIRECTORY -u, --update -v, --verbose -x, --one-file-system Examples cp file1.txt newdir Copies the file1.txt in the current directory to the newdir directory. cp /home/public_html/mylog.txt /home/public_html/backup/mylog.bak Copies the mylog.txt file in the public_html directory into the public_html/backup directory as mylog.bak. The files are identical however have different names. cp *.txt newdir Copy all files ending in .txt into the newdir directory. cp -r /home/hope/files/* /home/hope/backup Copies all the files, directories, and subdirectories in the files directory into the backup directory. copy only when the SOURCE file is newer than the destination file or when the destination file is missing explain what is being done stay on this file system

yes | cp /home/hope/files/* /home/hope/files2 Copies all the files and subdirectories in files into the files2 directory. If files with the same name exist or it's prompted to overwrite the file it answers yes.

mv command
Quick links About mv Syntax Examples Related commands Linux and Unix main page About mv Renames a file or moves it from one directory to another directory. Syntax mv [-f] [-i] oldname newname -f -i oldname mv will move the file(s) without prompting even if it is writing over an existing target. Note that this is the default if the standard input is not a terminal. Prompts before overwriting another file. The oldname of the file renaming.

newname The newname of the file renaming. filename The name of the file you want to move directory - The directory of were you want the file to go.

Examples mv myfile.txt newdirectory/ Moves the file myfile.txt to the directory newdirectory. mv myfile.txt ../ Moves the file myfile.txt back one directory (if available).

rm command
Quick links About rm Syntax Examples Related commands Linux and Unix main page About rm Deletes a file without confirmation (by default). Syntax rm [-f] [-i] [-R] [-r] [filenames | directory] -f Remove all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a writeprotected directory is attempted, this option will not suppress an error message. Interactive. With this option, rm prompts for confirmation before removing any files. It over- rides the -f option and remains in effect even if the standard input is not a terminal. Same as -r option. Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used. Symbolic links that are encountered with this option will not be traversed. If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message.

-i

-R -r

filenames A path of a filename to be removed. Examples rm myfile.txt Remove the file myfile.txt without prompting the user.

rm -r directory Remove a directory, even if files existed in that directory. Note that if you use rm to remove a file, it is usually possible to recover the contents of that file. If you want more assurance that the contents are truly unrecoverable, consider using shred.

chmod command
Quick links About chmod Syntax Examples Additional information Related commands Linux and Unix main page About chmod Changes the permission of a file. Syntax chmod [OPTION]... MODE[,MODE]... FILE... chmod [OPTION]... OCTAL-MODE FILE... chmod [OPTION]... --reference=RFILE FILE... -c, --changes --no-preserveroot --preserve-root -f, --silent, -quiet -v, verbose like verbose but report only when a change is made do not treat `/' specially (the default) fail to operate recursively on `/' suppress most error messages output a diagnostic for every file processed

-use RFILE's mode instead of MODE values reference=RFILE -R, --recursive --help --version change files and directories recursively display this help and exit output version information and exit

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.htm This 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.

ed and red command

Quick links About ed / red Syntax Examples Related commands Linux and Unix main page About ed Line oriented file editor. Below is a listing of know limitations of the ed editor:

64 characters per file name. 256 characters per global subcommand list. LINE_MAX characters per line (although there is currently a system-imposed limit of 255 characters per line entered from the keyboard). 128,000 character buffer size,

Syntax ed [-C] [-p string] [-s] [-] [-x] filename red [-C] [-p string] [-s | - ] [-x] filename

-C

Encryption option; the same as the -x option, except that ed simulates a C command. The C command is like the X command, except that all text read in is assumed to have been encrypted. Allows the user to specify a prompt string. By default, there is no prompt string. Suppresses the writing of character counts by e, r, and w commands, of diagnostics from e and q commands, and of the ! prompt after a !shell command. Encryption option; when used, ed simulates an X command and prompts the user for a key. The X command makes an educated guess to determine whether text read in is encrypted or not. The temporary buffer file is encrypted also, using a transformed version of the key typed in for the -x option. The name of the file that you wish to edit.

-p string -s or -x

filename Examples

Assuming the file myfile.txt has the following lines in it:

Hello world this is a test of the ed editor ed myfile.txt - Would open the file myfile.txt in the ed editor. Below is examples of how you could navigate with the ed command.

$ -

Reads the last line in this case "of the ed editor" Moves back one line. For example, if $ was typed, if - was entered would move up to "this is a test". A number can be added to move more than one line at a time. For example, if at the last line typing -2 would move back to the first line in this example. The + moves one line forward instead of back like the -. Like the - the + can have a number added after it, for example, +2 to move two lines instead of one line. Reads the first line in this case "Hello world" additional dots can be added to read other lines. Searches for the text typed in-between the forward slashes and displays the next line that has this text. For example, if we were at the first line "Hello world" and typed /test/ the line displayed would be "this is a test" Inserts text above the current line. Once you are done inserting text press CTRL + C to exit out of the insert option. Joins lines of text. Copies the line. Used to change text. For example, if our current line was "this is a test". Typing c would allow you to enter a new line. Typing "this is a tester" and then pressing CTRL + C would replace the previous line with this new line. Removes the specific line you are currently on. Allows you to skip to a line. For example, typing X and when asked to enter a key you enter 3 would display the line "of the ed editor"

+ /. /text/

i j t c

r X

Additionally many of the above options can be combined. For example, typing /test/i would insert a line before the first line that has test.

clear command
Quick links About clear Syntax Examples Additional information Linux and Unix main page About clear Clears the screen. Syntax clear Examples clear Clear the screen.

Das könnte Ihnen auch gefallen