Linux for Beginners: The Ultimate Practical Guide to Operating System, Command Line and Programming. Improve your Computer Skills and Become a Computing Expertise. by Cooper Nathan

Linux for Beginners: The Ultimate Practical Guide to Operating System, Command Line and Programming. Improve your Computer Skills and Become a Computing Expertise. by Cooper Nathan

Author:Cooper, Nathan [Cooper, Nathan]
Language: eng
Format: epub
Published: 2020-02-06T16:00:00+00:00


CHAPTER 7. Command Syntax Patterns

Let's discuss some common usage patterns shared by many Linux commands. Having a good feel for these basics can make learning your way around much faster. Invoking a command always starts with the command name. In some cases, as with the “ls” command, just the name on its own is enough to return a result. Still, you'll generally need to add some combination of arguments and parameters to get the most of a tool. You've already learned about how adding “-a” to the “ls” command will display all the files in a directory, even hidden files. But you can get the same results using two dashes and the word “all”. Providing these alternatives make command arguments more accessible for all kinds of people, those who remember things better through more complete descriptions and those who perform a task often enough that they can enjoy the speed of a single-letter argument. Looking at the “man” file for “ls” will show you that many other short arguments also have two-dash longer equivalents. There are exceptions to that argument syntax usage. The networking administration “ip command” can use the “addr” argument without a dash to show the IP addresses associated with your system's network interfaces. On most Linux systems this can even be shortened to a simple “a”, also without a dash. You can combine multiple short arguments in a single command. “ls-l” will list the contents of a directory in long-form, displaying object permissions, ownership, size, and age details. Running that again with the “h” command will give you the file system in a human-readable format. And adding “t” will organize the objects in descending chronological order. Besides arguments, most commands can also read properly formatted parameters. This example will list the full contents of the “etc” directory from wherever you happen to be in the filesystem. As all the best system administrators are extremely lazy, you can expect that there are going to be some pretty serious command line shortcuts hiding in plain sight. The most powerful of them is probably called autocomplete. Bash watches what you're typing and can often anticipate what it is you're after. For example to see the compressed tar archive file in a directory you can start typing the “tar” command for extracting the contents. Then you can stop at the letter “n”. Rather than having to enter the entire filename, you can just hit the Tab key, and Bash will do the rest for you. Bash understands the context of the command, so it gives you the archive, but not the subdirectory that's using a similar name. If you were to run the change directory command, “cd” with the letter “n” however, hitting Tab would correctly give you the directory name. Unsurprisingly, autocomplete will only work when there's only one matching possibility in the directory. You might sometimes need to provide a few more characters to get a good match. Speaking of “cd” and shortcuts, you can type simply “cd” from anywhere in a filesystem, and you'll be taken right back to your users home directory.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.