1 / 19

Using Linux Commands 2

Using Linux Commands 2 . Sort command. Sort the lines of text files . $ sort fileName by default it will sort in normal order(alphabetical 0-9 A-Z ). Options

nico
Télécharger la présentation

Using Linux Commands 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Linux Commands 2

  2. Sort command • Sort the lines of text files. $ sort fileName • by default it will sort in normal order(alphabetical 0-9 A-Z ). • Options • -rReverse normal order(reverse alphabetical Z-A 9-0).-nSort in numeric order(Sorts by the beginning of the number at the beginning of the line.)(A-Z 0-9)-nrSort in reverse numeric order(9-0 Z-A) • Note that this command does not sort the actual file, it just displays the sorted output on your terminal.

  3. Sequential commands • To run a sequence of commands type several commands on the same command line and separating them with semicolons(;)

  4. date commands Change or set current date and time. Syntax date [date or time string ] Examples • Show current date & time • Set date to 2001-Mar-15 • Set date as well as time

  5. Locatingcommands • Commands resides in directories. • The path consists of a list of directories that are checked sequentially for the commands you enter.(When you type a command to run, the system looks for it in the directories specified by PATH in the order specified) • To display all command’s paths • To display the command’s locations • -a ( if the command reside in several location ) Graphical commands (that are used with GUIs) The last directory shown is the bin directory in the user's home directory.

  6. If you know the directory that contains the command you want to run, one way to run it is to type the full path to that command. For example, you run the date command from the /bin directory by typing: • $ /bin/date Of course, this can be inconvenient, especially if the command resides in a directory with a long name. The better way is to have commands stored in well-known directories, and then add those directories to your shell's PATH environment variable. The path consists of a list of directories that are checked sequentially for the commands you enter. To see your current path, type the following: • $ echo $PATH/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/home/chris/bin The results show the default path for a regular Linux user. Directories in the path list are separated by colons. Most user commands that come with Linux are stored in the /bin, /usr/bin, or /usr/local/bin directories. Graphical commands (that are used with GUIs) are contained in /usr/bin/X11 and /usr/X11R6/bin directories. The last directory shown is the bin directory in the user's home directory.

  7. Common shell environment variables • $HOME: your home directory • $PATH: list of directories used to find commands. • $BASH: Contains the full path name of the bash command. • $PS1: Sets the value of your shell prompt. • $MAIL: This is the location of your mailbox file. • $PWD: This is the directory that is assigned as your current directory. • $OLDPWD: The directory that was the working directory before you changed to the current working directory. • $RANDOM: Accessing this variable causes a random number to be generated. • $UID: The user ID number assigned to your user name.

  8. Rerunning commands: command line completion • Some of the values you can type partially <Tab>: • Environment variablestext begin with$ • User nametext begin with ~ • Commands, aliases, or functiontext begin withregular char.

  9. Rerunning commands: command line recall • Type a command line shell’s history list history file • To view history list: • Run command number (!command number) • Run previous command The last 8 commands, including history 8 If the command # 22 is pwd pwd will be run

  10. Setting your prompt: • Prompt consists of a set of characters that appear each time the shell is ready to accept a command. • \[ precedes a sequence of nonprinting characters. • \] Follows a sequence of nonprinting characters. • \t prints the current time in hours, minutes, and seconds. • \w display the full path to the current working directory. • \$ shows the user prompt ($).

  11. Adding Alias • makes it possible to launch any command or group of commands by entering a pre-set string of characters. • it allows a user to create simple names or abbreviations (even consisting of just a single character) for commands regardless of how complex the original commands are and then use them in the same way that ordinary commands are used. Use the command unalias to remove alias -i interactive. With this option, rm prompts for confirmation before removing any files.

  12. The order in which the shell checks for commands 1- Aliases— Names set by the alias command that represent a particular command and a set of options. (Type alias to see what aliases are set.) 2- Shell reserved word— Words that are reserved by the shell for special use. Many of these are words that you would use in programming-type functions, such as do, while, case, and else. 3- Function— A set of commands that are executed together within the current shell. 4- Built-in commands— A command that is built into the shell. 5- File system commands— This is a command that is stored in and executed from the computer's file system. (These are the commands that are indicated by the value of the PATH variable.)

More Related