What I Learned Today 💡 May 24, 2017

tail -f, ls -l -h -F -G

1. tail -f <file>

The tail command shows the last 10 lines of a file (as opposed to head which shows the first 10 lines of a file).

If you do tail -f on a file, it will show the last 10 lines of a file. But then, it will continue to monitor the file, showing appendages in real time. Simply <Ctrl-c> to stop monitoring the file and regain the shell prompt.

(I believe you can also do less +F for similar functionality)

2. ls -l

ls -l shows a long listing. If you haven’t read about long listings, you probably won’t understand the output. You can read man ls , but I’ll just summarize it here.

Suppose I did ls -l myFile and I saw the following output:

  • A —File Type: The first character, - in the string of -rw-rw-r-- .
    This represents the file type. It can take on the following values:
    b (block special file), c (character special file), d (directory), l (symbolic link), s (socket link), p (named pipe), - (regular file)
  • B — Permissions: The rw-rw-r-- represents permissions. This can be divided into 3 sections: File Owner permissions ( rw- ), Group Owner permissions ( rw- ), Others permissions ( r-- ).
    For explanatory purposes, this is what a full-privileges section would look like: rwx . r = read permissions; w = write permissions; x = execution permissions (in the case of directories, the x means searching permissions. I.e. You can view the contents of the directory.).
    An - simply means the absence of that privilege. (There are more possibilities for permissions than r w x -, but I don’t know them well enough to discuss them).
  • C — # of Hard Links
  • D — User that owns the file
  • E — Group that owns the file
  • F — File Size (in bytes): If the file is a directory (“In Unix, everything is a file” — directories are just associative arrays that pair filenames (keys) to inode numbers (values)), you will only see the size of the literal directory-file. You will not see the total size of its contents. To do that, use du -sh <dir> . du shows disk usage. The -s option summarizes the disk usage, rather than the default behavior of showing each file’s individual disk usage for all files in the <dir>. The -h option shows the disk-usage in human-readable format.
    Source: https://unix.stackexchange.com/questions/18605/how-are-directories-implemented-in-unix-filesystems/18607#18607
  • G — Date of Last Modification
  • H — File Name: If the given file is a symbolic link, the destination/target-file will be shown here.

Note: If you are on Mac, you may see a + or @ at the end of the Permissions Block. This describes extended attributes of the file. This feature is Mac-specific.

3. ls -h

The -h option shows output in human-readable format. When used alone, it does nothing. But when used in a long-listing, ls -lh , it shows file-size with units, e.g. 2.1K for 2.1 kilobytes as opposed to 2100 (bytes)

4. ls -F

Appends a / to directories shown in the output. This helps classiFy the ls output into directories and other files. On Linux, you can also use the long-option version: --classify .

5. ls -G

Colors ls output to convey various information about the files shown such as file-type (directory, regular file, device-file, named pipe, symlink, etc.) and permissions.

Opinions expressed in these articles do not reflect those of my employer.

Show your support

Clapping shows how much you appreciated Anton Paras’s story.