Читать книгу Linux Bible - Christopher Negus - Страница 91

NOTE

Оглавление

You can use the --help option with most commands to see the options and arguments that they support. For example, try typing hostname --help.

Many commands also accept arguments after certain options are entered or at the end of the entire command line. An argument is an extra piece of information, such as a filename, directory, username, device, or other item, that tells the command what to act on. For example, cat /etc/passwd displays the contents of the /etc/passwd file on your screen. In this case, /etc/passwd is the argument. Usually, you can have as many arguments as you want on the command line, limited only by the total number of characters allowed on a command line. Sometimes, an argument is associated with an option. In that case, the argument must immediately follow the option. With single-letter options, the argument typically follows after a space. For full-word options, the argument often follows an equal sign (=). Here are some examples:

 $ ls --hide=Desktop Documents Music Public Videos Downloads Pictures Templates

In the previous example, the --hide option tells the ls command not to display the file or directory named Desktop when listing the contents of the directory. Notice that the equal sign immediately follows the option (no space) and then the argument (again, no space).

Here's an example of a single-letter option that is followed by an argument:

 $ tar -cvf backup.tar /home/chris

In the tar example just shown, the options say to create (c) a file (f) named backup.tar that includes all of the contents of the /home/chris directory and its subdirectories and show verbose (v) messages as the backup is created. Because backup.tar is an argument to the f option, backup.tar must immediately follow the option.

Here are a few commands that you can try out. See how they behave differently with different options:

 $ ls Desktop Documents Downloads Music Pictures Public Templates Videos $ ls -a . Desktop .gnome2_private .lesshst Public .. Documents .gnote .local Templates .bash_history Downloads .gnupg .mozilla Videos .bash_logout .emacs .gstreamer-0.10 Music .xsession-errors .bash_profile .esd_auth .gtk-bookmarks Pictures .zshrc .bashrc .fsync.log .gvfs Pictures $ uname Linux $ uname -a Linux mydesktop 5.3.7-301.fc31.x86_64 #1 SMP Mon Oct 21 19:18:58 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux $ date Wed 04 Mar 2020 09:06:25 PM EST $ date +'%d/%m/%y' 04/03/20 $ date +'%A, %B %d, %Y' Wednesday, March 04, 2020

The ls command, by itself, shows all regular files and directories in the current directory. By adding the -a, you can also see the hidden files in the directory (those beginning with a dot). The uname command shows the type of system you are running (Linux). When you add -a, you also can see the hostname, kernel release, and kernel version.

The date command has some special types of options. By itself, date simply prints the current day, date, and time as shown above. But the date command supports a special + format option, which lets you display the date in different formats. Enter date --help to see different format indicators you can use.

Try the id and who commands to get a feel for your current Linux environment, as described in the following paragraphs.

When you log in to a Linux system, Linux views you as having a particular identity, which includes your username, group name, user ID, and group ID. Linux also keeps track of your login session: It knows when you logged in, how long you have been idle, and where you logged in from.

To find out information about your identity, use the id command as follows:

 $ id uid=1000(chris) gid=1000(chris) groups=1005(sales), 7(lp)

In this example, the username is chris, which is represented by the numeric user ID (uid) 1000. The primary group for chris also is called chris, which has a group ID (gid) of 1000. It is normal for Fedora and Red Hat Enterprise Linux users to have the same primary group name as their username. The user chris also belongs to other groups called sales (gid 1005) and lp (gid 7). These names and numbers represent the permissions that chris has to access computer resources.

Linux Bible

Подняться наверх