Without this, the shell that is currently in use will run the script. The first line identifies the shell that will be used to run the script. Here's an example of a very simple script: #!/bin/bash Like aliases, scripts allow you to run a series of commands simply by typing the just their name. It makes it easy to add content, move around the lines in the files, replace words or lines, etc. The default on many Linux systems today is called "vim". home/justme/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbinīefore you can start creating text files - whether notes, lists or scripts - you will need to become familiar with one of the Linux text editors. You can examine your search path with a command like this: $ echo $PATH Your PATH setting should include directories like "/usr/bin" and "/usr/local/bin". ![]() ![]() If you type "date", for example, your shell will look at each location on your search path until it finds it - finds an executable by that name. Your search path on a Linux system is a sequence of file system locations separated by colons (:) that is used to find a command when you type it. alias myprocs="ps -ef | grep `whoami`" # show my processesĪlias rec="ls -ltr | tail -3" # show recent file updates bashrc file and they will be available every time you open a terminal window. In other words, you associate a word or abbreviation like "ll" with a command like "ls -l" or a single word like "recent" with a command like "history | tail -10" to view the most recent ten commands you've used.Īliases can save you time by reducing how much you have to type and can avoid typing errors by supplying all of command's details - especially if you use them often (less typing) or infrequently (less brain power required to remember how to use them). One of the most time-saving and clever things you can do as you warm up to Linux is to turn complex commands into aliases. Some of the aliases in the sections below also make use of pipes. 1 justme justme 2459 Nov 17 13:59 AllTables You can look at the most recently updated files in the current directory with a command like this: $ ls -ltr | tail -3 You can look at recently run commands with a command like this: $ history | tail -3 The wc -l command counts the lines of output sent by the who command. ![]() The who command shows you who is logged in. For example, you can count the number of people logged into a Linux server with a command like this: $ who | wc -l One of the features that I've always loved about working on the command line is the ability to use pipes expressed as vertical bars (i.e., |) to pass the output of one command to another command. You can also set up complex commands as "aliases" so that you only need to type a simple string to run them. Some of the most versatile commands you can run on the Linux command line are those that enable you to pass the output of one command to another by using something called a "pipe".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |