Linux Bible. Christopher Negus
Чтение книги онлайн.
Читать онлайн книгу Linux Bible - Christopher Negus страница 51
.
) files that are used to store GUI properties (.kde
directory) or shell properties (.bash
files). The only non-dot file in this list is the one named letter
. Column 3 shows the directory or file owner. The /home
directory is owned by root, and everything else is owned by the user joe, who belongs to the sales group (groups are listed in column 4).
In addition to the d
or -
, column 1 on each line contains the permissions set for that file or directory. Other information in the listing includes the number of hard links to the item (column 2), the size of each file in bytes (column 5), and the date and time each file was most recently modified (column 6).
Here are a few other facts about file and directory listings:
The number of characters shown for a directory (4096 bytes in these examples) reflects the size of the file containing information about the directory. Although this number can grow above 4096 bytes for a directory that contains lots of files, this number doesn't reflect the size of files contained in that directory.
The format of the time and date column can vary. Instead of displaying “May 12,” the date might be displayed as “2019-05-12,” depending upon the distribution and the language setting (LANG variable).
On occasion, instead of seeing the execute bit (x) set on an executable file, you may see an s in that spot instead. With an s appearing within either the owner (-rwsr-xr-x) or group (-rwxr-sr-x) permissions, or both (-rwsr-sr-x), the application can be run by any user, but ownership of the running process is assigned to the application's user/group instead of that of the user launching the command. This is referred to as a set UID or set GID program, respectively. For example, the mount command has permissions set as -rwsr-xr-x. This allows any user to run mount to list mounted filesystems (although you still have to be root to use mount to actually mount filesystems from the command line, in most cases).
If a t appears at the end of a directory, it indicates that the sticky bit is set for that directory (for example, drwxrwxr-t). By setting the sticky bit on a directory, the directory's owner can allow other users and groups to add files to the directory but prevent users from deleting each other's files in that directory. With a set GID assigned to a directory, any files created in that directory are assigned the same group as the directory's group. (If you see a capital S or T instead of the execute bits on a directory, it means that the set GID or sticky bit permission, respectively, was set, but for some reason the execute bit was not also turned on.)
If you see a plus sign at the end of the permission bits (for example, -rw-rw-r--+), it means that extended attributes (+), such as Access Control Lists (ACLs), are set on the file. A dot at the end (.) indicates that SELinux is set on the file.
Identifying Directories
When you need to identify your home directory on a shell command line, you can use the following:
$HOME | This environment variable stores your home directory name. | |
~ |
The tilde (~ ) represents your home directory on the command line.
|
You can also use the tilde to identify someone else's home directory. For example, ~joe
would be expanded to the joe
home directory (probably /home/joe)
. So, if I wanted to go to the directory /home/joe/test
, I could enter cd ~joe/test
to get there.
Other special ways of identifying directories in the shell include the following:
. |
A single dot (. ) refers to the current directory.
|
.. |
Two dots (.. ) refer to a directory directly above the current directory.
|
$PWD | This environment variable refers to the current working directory. |
$OLDPWD |
This environment variable refers to the previous working directory before you changed to the current one. (Entering cd – returns you to the directory represented by $OLDPWD .)
|
As I mentioned earlier, there are many useful options for the ls
command. Return to the $HOME/test
directory in which you've been working. Here are some examples of ls
options. Don't worry if the output doesn't exactly match what is in your directory at this point.
Any file or directory beginning with a dot (.
) is considered hidden and is not displayed by default with ls
. These dot files are typically configuration files or directories that need to be in your home directory but don't need to be seen in your daily work. The -a
lets you see those files.
The -t
option displays files in the order in which they were most recently modified. With the -F
option, a backslash (/
) appears at the end of directory names, an asterisk (*
) is added to executable files, and an at sign (@
) is shown next to symbolic links.
To show hidden and non-hidden files:
$ ls -a . apple docs grapefruit pointer_to_apple .stuff watermelon .. banana grape .hiddendir script.sh .tmpfile
To list all files by time most recently modified:
$ ls -at .tmpfile .hiddendir .. docs watermelon banana script.sh . .stuff pointer_to_apple grapefruit apple grape
To list files and append file-type indicators:
$ ls -F apple banana docs/ grape grapefruit pointer_to_apple@ script.sh* watermelon
To avoid displaying certain files or directories when you use ls
, use the --hide=
option. In the next set of examples, any file beginning with g
does not appear in the output. Using a -d
option on a directory shows information about that directory instead of showing the files and directories the directory contains. The -R
option lists all files in the current directory as well as any files or directories that are associated with the original directory. The -S
option lists files by size.
To exclude any files beginning with the letter g
in the list:
$ ls --hide=g* apple banana docs pointer_to_apple script.sh watermelon
To list info about a directory instead of the files it contains:
$ ls -ld $HOME/test/ drwxrwxr-x. 4 joe joe 4096 Dec 18 22:00 /home/joe/test/
To create multiple directory layers (-p
is needed):
$ mkdir -p $HOME/test/documents/memos/
To list all files and directories recursively from current directory down:
$ ls -R ...