19
Using Linux Commands 2 Lab#5

Using Linux Commands 2 Lab#5

Embed Size (px)

DESCRIPTION

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

Citation preview

Using Linux Commands(3)

Using Linux Commands 2 Lab#5

Sort commandSort the lines of text files.$ sort fileNameby default it will sort in normal order(alphabetical 0-9 A-Z ).

Options-r Reverse normal order(reverse alphabetical Z-A 9-0).-n Sort in numeric order(Sorts by the beginning of the number at the beginning of the line.)(A-Z 0-9)-nr Sort 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.

2

Sequential commands

To run a sequence of commands type several commands on the same command line and separating them with semicolons(;)$ mkdir ng ; cd ng ; touch tom5date commandsChange or set current date and time.Syntax date [date or time string ]ExamplesShow current date & time

Set date to 2001-Mar-15

Set date as well as time$ date$date --date=2001-3-156$date --date=2001-3-15 11:59 AM Locating commandsCommands 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 commands paths

To display the commands locations

-a ( if the command reside in several location )

Directory ContentDirectoryContains common Linux user commands such as ls, sort/bin Contains a variety of other user and administrative commands./usr Contains administrative commands./sbin $ echo $PATH/usr/local/bin:/bin:/usr/bin:usr/X11R6/bin:/home/chris/bin7$ type commandGraphicalcommands (that are used with GUIs) The last directory shown is the bin directory in the user's home directory.If you knowthe 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 thedatecommand from the/bindirectory 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 currentpath, 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/bindirectories. Graphicalcommands (that are used with GUIs) are contained in/usr/bin/X11and/usr/X11R6/bindirectories. The last directory shown is the bin directory in the user's home directory.

7If you knowthe 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 thedatecommand from the/bindirectory 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 currentpath, 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/bindirectories. Graphicalcommands (that are used with GUIs) are contained in/usr/bin/X11and/usr/X11R6/bindirectories. The last directory shown is the bin directory in the user's home directory.

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.

10

Rerunning commands: command line completion$ echo $PA$ ls ~/uben$ ty 12Some of the values you can type partially :Environment variables text begin with $User name text begin with ~Commands, aliases, or function text begin with regular char.Rerunning commands: command line recallType a command line shells history list history fileTo view history list:

Run command number (!command number)

Run previous command

$ history $ history 8$ !2213$ !!The last 8 commands, including history 8If the command # 22 is pwd pwd will be runSetting your prompt: $ export PS1=[\t \w] \$[20:26:32 /var/spool] $14Prompt 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 ($).

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.

$ alias p=pw d; ls -al$ alias rm =rm i$ unalias p$ alias del=rm I $ alias copy=cp$ alias rename=mv $ alias md=mkdir 16-i interactive. With this option, rm prompts for confirmation before removing any files.Use the command unalias to remove alias

The order in which the shell checks for commands

1- AliasesNames set by thealiascommand that represent a particular command and a set of options. (Typealiasto see what aliases are set.)2- Shell reserved wordWords that are reserved by the shell for special use. Many of these are words that you would use in programming-type functions, such asdo,while,case,andelse.3- FunctionA set of commands that are executed together within the current shell.4- Built-in commandsA command that is built into the shell.5- File system commandsThis 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 thePATHvariable.)

AliasesNames set by thealiascommand that represent a particular command and a set of options. (Typealiasto see what aliases are set.)Shell reserved wordWords that are reserved by the shell for special use. Many of these are words that you would use in programming-type functions, such asdo,while,case,andelse.FunctionA set of commands that are executed together within the current shell.Built-in commandA command that is built into the shell.File system commandThis 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 thePATHvariable.)

19