Presentation on theme: "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."— Presentation transcript:
Sort command Sort the lines of text files. $ sort fileName by 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 tom 6
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 $ date $date --date=“2001-3-15” 7 $date --date=“2001-3-15 11:59 AM”
Locating commands 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 ) Directory ContentDirectory Contains 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/bin 9 $ type command Graphical commands (that are used with GUIs) The last directory shown is the bin directory in the user's home directory.
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:/ho me/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.
Common shell environment variables $HOME: $HOME: your home directory $PATH: $PATH: list of directories used to find commands. $BASH: $BASH:Contains the full path name of the bash command. $PS1: $PS1: Sets the value of your shell prompt. $MAIL: $MAIL: This is the location of your mailbox file. $PWD: $PWD: This is the directory that is assigned as your current directory. $OLDPWD: $OLDPWD: The directory that was the working directory before you changed to the current working directory. $RANDOM: $RANDOM: Accessing this variable causes a random number to be generated. $UID: $UID: The user ID number assigned to your user name. 12
Rerunning commands: command line completion $ echo $PA $ ls ~/uben $ ty 14 Some 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 recall Type a command line shell’s history list history file To view history list: Run command number (!command number) Run previous command $ history $ history 8 $ !22 15 $ !! The last 8 commands, including history 8 If the command # 22 is pwd pwd will be run
Setting your prompt: $ export PS1=“[\t \w] \$” [20:26:32 /var/spool] $ 18 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 ($).
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’ 20 -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- 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.)