All linux debian commands

  • ShellCommands

?Discussion

The page is about basic command-line operation of a GNU/Linux system.

A command-line Shell accepts various kinds of commands:

executable programs installed from Debian packages
manually installed/compiled/written programs or scripts

internal commands provided by the Shell (built-ins, aliases)

  • .
  • Command-line applications

    Debian provides many command line programs through its package management system.

    Commonly used command-line programs

    coreutils

    The GNU Core Utilities (coreutils) are the basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every UNIX-like operating system.

    You should get a basic knowledge of how to list, display, edit and manipulate files before moving to more specific tasks, and/or writing shell scripts.

    Other programs

    To get detailed information on how to use a program, read its ManPage.

    awk — pattern-directed scanning and processing language

    clear — clear the terminal screen

    cmp — Compare two files

    comm — Compare two sorted files line by line

    crontab — Schedule a command to run at a later time

    date — Display or change the date & time

    dd — Data Dump — Convert and copy a file

    df — Display free disk space

    diff — Display the differences between two files

    dir — Briefly list directory contents

    dircolors — Colour setup for ls

    dirname — Convert a full pathname to just a path

    du — Estimate file space usage

    env — Display, set, or remove environment variables

    exit — Exit the shell (or press Ctrl-D)

    export — Set an environment variable

    fdisk — Partition table manipulator for Linux

    file — Tells what kind of files are those listed on command line

    find — Search for files that meet a desired criteria

    for — Expand words, and execute commands

    format — Format disks or tapes

    free — Display memory usage

    fsck — Filesystem consistency check and repair.

    ftp — Transfer/receive files from/to a remote host

    grep, egrep, fgrep, rgrep — print lines that match patterns

    groups — Print group names a user is in

    gzip/gunzip — Compress or decompress named file(s)

    head — Output the first part of file(s)

    hostname — Print or set system name

    id — Print user and group id’s

    join — Joins lines on a common field

    kill — Stops a process from running

    killall — Stops matching process from running

    less — Display output one screen at a time

    ln — Make links between files

    locate — Find files using an indexed list.

    logname — Print current login name

    logout — Exit a login shell

    lpc — Line printer control program

    lprintq — List the print queue

    ls — List information about file(s)

    mkdir — Create new folder(s)

    more — Display output one screen at a time

    mount — Mount a file system

    mv — Move or rename files or directories

    nice — Set the priority of a command or job

    passwd — Modify a user password

    printf — Format and print data

    ps — Process Status. Lists running process

    pwd — Print Working Directory

    rsync — Remote file copy (Synchronize file trees) using its own protocol. It may be used over an ssh or rsh connection.

    scp — Copy files between two machines over an ssh connection

    script — make typescript of terminal session

    sdiff — Merge two files interactively

    select — Accept keyboard input

    sftp — Secure file transfer (FTP over SSH)

    shutdown — Shutdown or restart Linux

    sleep — Delay for a specified time

    sort — Sort text files

    su — Substitute user identity

    sync — Synchronize data on disk with memory

    tail — Output the last part of files

    time — Measure Program Resource Use

    top — List processes running on the system

    touch — Change file timestamps or create an empty file

    tr — Translate, squeeze, and/or delete characters

    traceroute — Trace Route to Host

    true — Do nothing, successfully

    umask — Users file creation mask

    umount — Unmount a device

    uname — Print system information

    until — Execute commands (until error)

    useradd — Create new user account

    usermod — Modify user account

    users — List users currently logged in

    vdir — Verbosely list directory contents (ls -l -b)

    watch — Execute/display a program periodically

    wc — Print byte, word and line counts

    which — Locate a program file in the user’s path.

    who — Print all usernames currently logged in

    whoami — Print the current user id and name (`id -un’)

    xargs — build and execute command lines from standard input

    Источник

    Debian User Reference Manual (Obsolete Documentation)
    Chapter 6 — Basic Commands and Tools

    author = Oliver Elphick olly@lfix.co.uk

    topics = head, tail, grep, etc.

    Latest update to this chapter: 14th December 1997

    6.1 What this chapter covers

    This chapter tells you how to run the basic commands that you need in order to use Debian Linux.

    We assume that you have already logged in and are in a shell where you can enter commands. Refer back to Overview of a Debian GNU/Linux System, Chapter 2 for instructions on how to log in. If you are not running X-Windows, you will normally be put in an interactive shell as soon as you log in. If you are running X-Windows, you should refer to X Windows, Chapter 17 for instructions on how to start up a window with a shell.

    The available shells are described in Shells, Chapter 5. All the examples given here assume that you are using the Bourne-Again Shell, /bin/bash , though in most cases there will be no difference between the command syntax for any shell. Bash is the default shell when Debian Linux is first installed.

    6.2 Running commands

    6.2.1 How to enter commands

    To run a command, type the command at the prompt, followed by any necessary options, and then press the Enter key. The shell will interpret the command, first handling any special shell syntax, and will then start the command as a new process.

    Most commands operate silently unless they are specifically asked to say what they are doing. If there is no error message, the command should have worked.

    6.2.2 How Linux finds commands

    When you type in a command name, Linux has to find the file which contains the program you want to run. This is how it does it:

    The first word of what you type in is the command[3] itself. If this contains a slash character ( / ) the whole command is taken to be a path, either absolute (if it starts with /) or relative to the current directory. The file indicated by that path is used, provided that it exists, that it is executable and (in the case of a script) that it is readable.

    If the command does not contain a slash, the shell searches for it in your current search path. This is a list of directories, separated one from another by colons. The command search path is held in the environment variable PATH: type echo $PATH to see what it is. For example,

    Each directory is searched in turn, starting at the beginning of the list. If a match for the name is found, the shell also considers whether the file found is executable (and readable, if it is a script). As soon as such a match is found, the search stops[4]. This is why new programmers often have trouble getting their first program to run. They frequently call it test and run it without a path; the shell finds the system program test first and runs that instead.

    If you need to change your path, you should add the new directories to the end of the list; the current directory (.), if it is included at all, should go last of all[5]. The command to use is export PATH=$PATH: new_directory [6] .

    6.2.3 Command options

    The operation of most commands can be changed by putting command options immediately after the command name. There are several styles of options used, and you have to check the documentation for each command to know what options it can take, and what they do.

    The most common form of option is a letter preceded by a hyphen, thus:

    With this option style, several single-character options can be combined into one, thus:

    which is equivalent to

    Sometimes, single-letter options like this need an extra argument:

    Here : and /tmp/bar are arguments to the options -F and -f respectively.

    A few commands have options which need not be preceded by a hyphen. The one you are most likely to use is tar .

    A third option style, commonly used by GNU programs, is whole words or phrases introduced by — . Many commands can use both the single-letter and whole-word options:

    Finally, commands may define completely different option patterns for themselves, such as options preceded by + as the opposite to — .

    6.2.4 Essential commands

    These commands are the ones you really need to know to get anything done.

    We give only a brief description of the command, describing its basic use. For full details, you should always refer to the detailed documentation of the manual pages and the info files.

    Читайте также:  Activators windows 10 2020

    The brief examples given here are not by any means the only way of doing things; the key to using Unix is to learn the building blocks and their capabilities and become able to use them in your own way. Whatever the task, there is almost always more than one way to carry it out. Sometimes there will be five or six different ways!

    In this chapter, things which are optional are shown like this . Words looking like this are to be replaced by whatever is appropriate to what you are trying to do.

    6.2.4.1 Commands for reading documentation

    To avoid annoying other users by questions on elementary matters, do, please, read the manuals!

    These are the commands to let you do that:

    man [ section-number ] subject

    man shows the manual page on the command (use q or ctrl-C to get out of it if it doesn’t terminate at the end of the text). More details are given in Documentation, Chapter 3.

    This command is crucial for helping you learn how to use it and other Linux commands.

    A lot of Debian Linux documentation is provided in info format. This is similar to a hypertext format, in that you can jump to other sections of the documentation by following links embedded in the text.

    See Documentation, Chapter 3 for a full description of how to use info .

    Use help for on-line help about bash’s built-in commands.

    help by itself prints a list of subjects for which you can ask for help.

    6.2.4.2 Commands for basic file-handling

    A fuller description of file-systems and file-handling is given in Files and File Systems, Chapter 4.

    These are the commands that you really have to know:

    Show the current directory.

    Change your current directory to the named directory . If you don’t specify directory , you will be returned to your home directory.

    mkdir is used to create a new directory. new_directory can be specified as a path, or as a simple name (in which case it is created in the current directory).

    mv source target

    mv moves source file to target and deletes source ; source can be a list of files, but in that case target must be a directory.

    This is also the way to rename a file or directory.

    cp source target

    cp copies source to target . Again, target can be a directory and source a list of files.

    ln source target

    ln links source to target with hard or symbolic links according to the options.

    rm deletes files. With the -r option it can delete directories and their contents.

    Be very careful with rm ; once a file is deleted, you cannot get it back. There is no undelete command.

    rm deletes empty directories.

    chmod mode filelist

    chmod changes the permissions of files and directories. The mode is either an octal number, such as 644 , or a symbolic representation of it, such as u=rw,go=r .

    chown owner [. group ] filelist

    chown changes the ownership of files. Use the -R option to do this for an entire directory tree.

    If . group is specified as well as owner , the group ownership of the files is changed as well.

    chgrp group filelist

    chgrp changes the group ownership of files. Use the -R option to do this for an entire directory tree.

    ls lists the contents of directory ; by default, the output is sorted.

    There are more options to ls than to any other command. Those most commonly used are -l , to show the file permissions and the latest change date and -a , to show hidden dot-files.

    6.2.4.3 These commands are used for managing file-systems

    Files are organised into file-systems (see Files and File Systems, Chapter 4).

    Every Debian Linux system (and every Unix system) has a root file-system, called, simply, / . All files and devices in the system, and possibly files on other systems as well, are accessible under / . Files are placed under directories, which may themselves be placed in directories, and so on. Segments of this universal tree will be on different physical devices, or different sections (`partitions’) of a single physical device. New file-systems, each with its own directory tree, may be grafted into the universal directory tree at arbitrary `mount-points’. (These are simply directories which are nominated to be the head of the new tree.)

    The process of grafting a segment into the main tree is called `mounting’; the file system is mounted on a mount-point, which is a directory.

    df lists mounted partitions and shows the amount of space present, used and available. (The partitions will probably include /proc, which is a special `non-existent’ partition, that contains information about the current state of the Linux kernel.)

    mount [ partition directory ]

    mount by itself lists mounted partitions.

    It is also the command to use to add a partition’s file-system into the universal directory tree. For example:

    You have to be superuser (log in as root or run su ) in order to mount or unmount file-systems.

    umount removes a partition’s file-system from the universal directory tree. For example:

    You have to be superuser (log in as root or run su ) in order to mount or unmount file-systems.

    6.2.4.4 Looking at files

    Files include physical devices, executable programs and directories, as well as text files. It is as well not to look at compiled executables on the screen however. At best they will be garbage; at worst they will make everything on the screen unreadable (see Managing your screen, Section 6.2.4.5 for a way to recover from this.)

    cat dumps textfile[s] to screen without paging (like DOS’s type). If you name more than one file, each will be sent in order, with no break or heading.

    more lists the textfile[s] to the screen in pages so that you can read it. Press Space-bar to move on one page, Enter to move on one line, and b to move back one page. Use q or ctrl-c to quit.

    more will quit automatically when it gets to the end of the last file.

    less is like more but has more features and somewhat different behaviour. You have to type Q to terminate it.

    head is used to see the first few lines of a file (by default, it shows 10 lines).

    tail is used to see the last few lines of a file (by default, it shows 10 lines).

    od is used to look at the contents of binary files. With no options, it displays the file contents as a series of octal numbers. Since few people are fluent with this form, the -c and the -x options together are probably more useful. They display the file contents as real characters where possible and as octal numbers if the characters are not displayable, with, underneath, the hexadecimal representation. For example:

    The numbers in the left hand column are always octal; they indicate the byte offset of the first character on the line from the beginning of the file.

    dd if= input_file of= output_file

    dd is used for arbitrary copying between files and devices (either file1 or file2 or both could be devices instead of files.) You can use dd to copy a file while dropping its first few bytes, to break a file into chunks, to copy a disk image onto a floppy (for instance to get a Debian boot floppy), to inspect the contents of a tape, or anything else that your ingenuity can suggest.

    find directory -name filename

    find tells you where filename is in the tree starting at directory . This command has many other useful options.

    xargs is commonly used with find . It breaks long lists of files given to a command into chunks that are short enough for the shell to handle. In this way, you can run through the entire file system and execute some command on all the selected files. For example, this command looks for all files in your home directory that have been changed within the last two days, and sets group write access on them all:

    grep pattern filelist

    grep scans each file in filelist for lines which match pattern (see Regular expressions, Section 6.3).

    file reports what kind of thing file is.

    type says where to find file in your search path.

    whereis is like type , but gives more information.

    6.2.4.5 Managing your screen

    Managing your screen can be a very frustrating experience.

    When you have sat helpless for a while trying to work out why your entire display contains total garbage, or why pressing an arrow key puts irrelevant characters up, you may well feel that it’s time to tip the whole computer system into the dustbin and go back to the abacus. This section offers you a lifeline.

    First of all, here are some commands to handle what you can see on your screen. The screen can be either the whole text display or a single text window in X.

    All VDUs attached on serial cables, and all memory-mapped displays that emulate VDUs, including your text console and your xterm windows, respond to special character sequences that will change the appearance of the whole screen, or portions of it, when they are sent to the screen. Usually, these sequences start with the ESCAPE character, but they don’t have to. Because of the vast number of different VDUs produced by many different manufacturers, mostly with different control sequences, Linux has a database of the sequences that apply to different types of VDU. The database appears in two forms — the older is called termcap and the newer, terminfo.

    tput is a command that reads the terminfo database for the sequence named, translates that sequence to screen control characters and sends those characters to the screen. The clear sequence blanks the screen and puts the cursor in the top left hand corner.

    Читайте также:  Windows 10 iot enterprise x64 lite xlx

    If, intentionally or not, you display a binary file on the screen, you may chance to send to the screen the sequence that makes it display its alternative character set; this usually contains a lot of graphics line-drawing characters, card suits, odd mathematical symbols and so on. The computer’s attempt to display ordinary text in this character set produces a screen containing total garbage. The rmacs sequence switches the display out of the alternate character set. Use this command to stop the display showing garbage graphics characters and make it show proper text instead. (The effect is usually to change new characters sent to be proper text, but leave text already displayed as it is.)

    stty controls communication between a VDU and the computer. It controls characteristics such as the baud-rate, parity, number of stop-bits and handshaking, all of which should be set up for you by your system administrator (if that is you, read the System Administration manual). In the case of your console, or of an xterm window, which are mapped directly from memory, the line characteristics are irrelevant, but there are certain characteristics set by stty which are relevant to every kind of display.

    These are some characteristics could be used by you if it seemed necessary. (If it is necessary, you may find that nothing at all seems to work; this may be because the return key no longer works and Linux has reverted to using the basic default, which is new line (Ctrl-J). If nothing at all seems to work, press Ctrl-J before entering any command and finish your commands with Ctrl-J instead of return.)

    stty sane is one option to try if everything has stopped working. Remember to use Ctrl-J both before and after the command and don’t use the return key.

    Use stty echo if what you type doesn’t appear on the screen.

    Use stty intr ‘^C’ to make Ctrl-C work as your interrupt key (which will tell the running program to stop).

    Use stty -a to show you what your existing stty settings are.

    6.2.4.6 Compressed files

    In order to save space on your disks, many files are compressed. They are scanned by a program such as gzip or compress and reduced in size, often to about one third of their original size.

    Compressed files cannot be read unless they are uncompressed again.

    gunzip uncompresses file.suffix (where suffix is .gz or perhaps .Z ), deletes it and writes an uncompressed file called file .

    In spite of its name, gunzip cannot handle zip format files created by PKZIP . There is a pkunzip program that can handle such files.

    zcat does the same job as cat , but uncompresses compressed_file first, without changing it on the disk.

    zmore does the same job as more , but uncompresses compressed_file first, without changing it on the disk.

    zless does the same job as less , but uncompresses compressed_file first, without changing it on the disk.

    zgrep does the same job as grep , but uncompresses compressed_file first, without changing it on the disk.

    6.2.4.7 Commands for backup

    You need to do regular backups, in order to be able to recover your system and data in case of disaster. In order to get full access to all the files that need to be backed up, system backups must be done by the superuser. This section refers only to backups of your own home directory and of other files to which you have access.

    These programs are used for backups of various kinds:

    tar is designed to archive directories with all their contents. It has many options, but here is a simple example of using it to create a backup of your home directory to a SCSI tape:

    Here is how to read the contents of a tape that has been written with tar :

    and here is how to restore a particular directory (with its contents) from such a tape backup:

    You can also restore a single file:

    cpio is used to write individual files to a backup. A list of files is prepared in some way and then piped into the standard input of cpio . This is how to use it to archive your home directory to SCSI tape:

    Here is how to read the contents of a tape that has been written with cpio :

    and here is how to restore a set of files in one directory whose names all start with `bank’ from such a tape backup:

    afio is used like cpio to write individual files to a backup. It has the additional capability of compressing files before it writes them on the backup. This is useful if you have a lot of information to store on media of limited capacity. This is how to use it to archive your home directory to SCSI tape, using compression:

    6.2.4.8 Printing files

    There is one basic command for printing (though there are many for specialised uses):

    lpr prints file to the default printer. lpr is the user command for adding jobs to the spooler queue. The jobs will continue to print, even if you log out.

    If you have more than one printer, you can use the option -P printer to direct a job to one particular printer.

    lpq shows the current list of jobs on the printer spool queue.

    lprm removes the job identified by jobId from the spooler queue. If a job is already printing, this may not stop it; the job may already be stored in the printer’s memory

    6.2.4.9 Changing files

    See Text Editing, Chapter 8 for information on editing files.

    6.2.4.10 Session management

    A session is the series of events between logging in and logging out of the computer.

    When you first log in, you will see a prompt, which may contain your current machine’s hostname, and perhaps the current directory. The prompt ends with a dollar sign: $, which indicates that you are an ordinary user. If you become superuser, the dollar sign should change to a hash (or sharp) sign: #. You need to know that you are superuser, because you can then do a great deal of damage to your system by mistyping ordinary commands.

    These commands relate to handling your session:

    Use exit or logout to terminate your session and log out. All jobs you have started are terminated, unless they were started with nohup , and your screen should return you to the log-in prompt. You can often use Ctrl-D to do the same, but that capability can be disabled.

    Use su to become superuser. You will be asked to enter a password; this is the password for the root login.

    Becoming superuser is almost the same as logging in as root. You get the same power to do damage. Be very careful!

    Use exit , logout or ctrl-D to stop being superuser.

    If you are running one job and want to run something else in the same screen without stopping the first job, you can put the first job in the background by typing Ctrl-Z. You can then run other commands. You can start the first job running again in the background by using bg . It will continue to run in the background until it wants to send anything to the screen; then it will stop and wait. You can bring it forward again and let it continue by using the command fg .

    Use script to record everything that appears on the screen (until the next exit) in file . This is useful if you need to record what’s going on in order to include it in your message when you ask for help. Use exit, logout or ctrl-D to stop the recording session.

    Use ps to list your processes.

    You can also use ps to see all processes on the system:

    The number in the column headed PID is the identifying number of the process. Under column TT is the tty (screen or window identifier) where it is running. A question mark here means that it is not attached to any screen or window, but is running in the background.

    tty shows you which terminal (screen or window) you are in.

    6.2.4.11 Identity

    These commands relate to your identity as a user and the machine’s own identity.

    Use passwd to change the password that you use when you log in. Follow the instructions on screen about what kind of password to choose. When you type the password in, it doesn’t show on the screen, so you have to enter it twice, to ensure that you make no typing errors.

    id tells you what user you are and what group you are in.

    uid indicates your user number, gid your group number (which will be assigned to files that you create) and groups lists the other groups that you are a member of.

    who -u reports everyone who is logged on.

    uname -a reports the name, type and operating system of your machine.

    date reports the current time and date.

    The superuser can use this command to set the date and time.

    6.2.4.12 Turning off the computer

    Turning the computer on and off is really a system administration subject, but I include it here because it is something that every user who is his own administrator needs to know. If someone else is responsible for administering the machine, you should neither need nor be able to shut it down.

    shutdown -t 0 -h now

    This command shuts the computer down safely. You can also use ctrl-alt-del if your system is set up for that. (If you are in X, ctrl-alt-del will be intercepted by X. Get out of X first by using ctrl-alt-backspace.) Never turn off a Unix machine without doing a safe shutdown: if you do, you will damage your file-systems.

    Читайте также:  Windows клавиатура меню правая кнопка мыши

    6.2.5 Special characters in commands

    When you type a command, certain characters have a special meaning to the shell and are interpreted before the command starts to run. Full details are given in the chapter on shells, but you need to understand what is happening, or you will get results that you did not expect.

    Shell special characters are interpreted by the shell as soon as it is given the command. For example, if you type ls *.bak , the shell translates *.bak to the list of all files in the current directory whose names end in .bak . The ls command never sees the asterisk. So if you want to search for files which actually have an asterisk in their names, you have to escape the asterisk to stop the shell from interpreting it.

    In the example, the first command matched all files; the second matched only those with a literal asterisk at the end of their names.

    The same goes for other special characters. here is the full list:

    \ escapes itself and other specials

    [ ] encloses patterns for matching a single character

    * stands for anything (including nothing)

    ? stands for any single character

    ( ) runs the contents of the parentheses in a sub-shell

    ; terminates a command pipeline — use it to separate commands on a single line

    & runs the preceding pipeline in the background.

    This is the same as typing Ctrl-Z and then bg to an already running program.

    $word and $ are interpreted as a shell variable (use $ if there is danger of ambiguity). There are other characters that can follow $ and give other meanings. (See Shells, Chapter 5.)

    The contents of the backquotes are run as a command and its output is used as part of this command

    The contents of the quotes are treated as one argument; any specials inside the quotes, except for $ and «, are left uninterpreted.

    The contents of the single quotes are passed to the command without any interpretation.

    The vertical bar sign is used to indicate a pipe. The command on the left-hand side of the pipe sends its output to the input of the command on the right side of the pipe.

    These symbols are used for redirection; see below.

    The double ampersand is used between two commands (on the same line). It tells the shell to run the second command only if the first one was successful[8] .

    The double vertical bar is used between two commands (on the same line). It tells the shell to run the second command only if the first one was unsuccessful.

    For example, ls -d /[uv]* will list the names of all entries in the root directory that start with u or v. Unlike DOS, you can use patterns like g*.gz (with the wildcard bit in the middle).

    These characters have a special meaning only if they are the first non-space character in the command:

    If ! is immediately followed by a character other than =, it begins a history substitution; if it is followed by a space it negates the return code of the following command pipeline. (For more details see Shells, Chapter 5.)

    Quick history substitution, changing one string to another:

    # turns the line into a comment; the line is not processed in any way.

    Don’t confuse shell special characters with special characters in regular expressions (see Regular expressions, Section 6.3). Regular expressions must be protected from the shell by enclosing them in single quotes.

    6.2.6 Filters

    Many commands are filters, so you can pass the output of one command to the input of another:

    This is a fundamental concept of all Unix and Unix-like systems. Many commands are designed to be filters. They can therefore be used as building blocks to make more complex commands, in whatever way is needed at the time.

    6.2.7 Standard input, standard output and standard error

    When the shell starts a command for you, it opens files for standard input, standard output and standard error. By default, standard input is your keyboard, standard output is your screen, and standard error is also your screen.

    Although the defaults are keyboard and screen, this can easily be changed. In fact, the shell copies its own standard input, output and error when it starts a command, so the command inherits whatever the shell has. A command can change its own settings, by opening a different file, and you can tell the shell to use a file instead of the default of keyboard or screen.

    The file descriptor numbers for standard input, standard output and standard error are 0, 1 and 2 respectively.

    6.2.8 Redirection

    You can redirect standard input, output and error by adding these sequences after a command:

    file means take input from file .

    > file means send output to file (overwriting and destroying whatever is in the file already).

    You can use this feature to empty a file, by typing

    on a line by itself.

    >> file means append output to file .

    2> file means send error messages to file (overwriting). (This means that errors can be directed separately from normal output.)

    There are more complex aspects to redirection, which may be studied in the shell manual pages.

    Here are some very common uses of redirection:

    cat [ filelist ] > output_file

    We have already seen that cat can be used to look at files. In conjunction with redirection of standard output, it can be used to write files as well.

    If you omit filelist , cat will take its input from the keyboard, until you type ctrl-D.

    echo sends text to the standard output. It is commonly used in script programs to put text on the screen.

    It can also be used with redirection of output to write to a file. For example,

    6.2.9 Shell programs

    Redirection is a simple part of shell programming, for which see the manual pages of bash, zsh, tcsh, or whatever shell you have chosen. A shell program is a set of commands in a file or typed in.

    Once you have stored a shell program in a program file, you have to make it executable by running chmod:

    6.2.10 Errors

    Unix commands normally execute silently unless asked to be verbose or unless there is an error. An error means something that does not make sense to Linux; it doesn’t mean something you don’t want to happen!

    For example, I once had a client who had some unwanted files in his root directory which were named &TEMP& and so on. As superuser in the root directory he typed rm -rf /&* when he should have typed rm -rf \&* What he actually asked for was to delete his entire file system, as a background job. It did too.

    6.3 Regular expressions

    Regular expressions are a way of specifying some text to match without having to spell it out exactly. Regular expressions are used inside editors and in the grep command. They are not the same as the limited file pattern matching that is done by the command line.

    A regular expression can be very simple or very complicated. Complicated expressions are built up by joining together simple ones. In this section we are only dealing with simple uses of regular expressions in the grep and zgrep commands. The simplest expressions are called atoms, because they cannot be broken down any further.

    Here are the regular expression atoms:

    Any single character matches itself.

    A full stop matches any single character.

    A list of characters in square brackets matches any single character provided that it occurs inside the brackets. A range of characters can be expressed inside the brackets by specifying the two ends of the range separated by a minus sign. For example, the regular expression atom [ACafjl-rx] matches any one occurrence of the letters `A’, `C’, `a’, `f’, `j’, `l’, `m’, `n’, `o’, `p’, `q’, `r’ or `x’.

    The effect of this atom can be reversed by making `^’ the first character inside the brackets. This means that any character matches except those in the brackets.

    A circumflex character outside square brackets indicates the beginning of a line. (So it can only have this meaning at the beginning of a regular expression.)

    A dollar character outside square brackets indicates the end of a line. (So it can only have this meaning at the end of a regular expression.)

    A backslash escapes the character that follows it; that is, it alters that character’s meaning. For example, use \* to signify a real asterisk, or \\ to signify a real backslash.

    Some letters have special meanings if they follow a backslash: \t matches a tab character, \f matches a form feed character, and so on.

    The regular expression atoms can be affected by these modifiers (+ and ? have to be preceded by a backslash when used with grep ):

    A regular expression followed by an asterisk is matched by 0 or more occurrences of that regular expression. For example, b* matches `’, `b’, `bb’, `bbbbbb’ and so on.

    A regular expression followed by a plus sign is matched by 1 or more occurrences of that regular expression. For example, b+ matches `b’, `bb’, `bbbbbb’ and so on.

    A regular expression followed by a question mark is matched by 0 or one occurrences of that regular expression. For example, b? matches `’ or `b’.

    Here is an example of the use of a regular expression with grep :

    This command would list all lines in basic_cmds.sgml that start with a capital letter immediately followed by one or more lower case letters. The plus sign is escaped with a backslash to make it have its special meaning. The whole regular expression is in single quotes to protect it from being evaluated by the shell.

    Debian User Reference Manual (Obsolete Documentation)

    Источник

    Оцените статью