What I Learned Today 💡 May 24, 2017
tail -f, ls -l -h -F -G
1. tail -f <file>
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
This represents the file type. It can take on the following values:
b(block special file),
c(character special 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 (
For explanatory purposes, this is what a full-privileges section would look like:
r= read permissions;
w= write permissions;
x= execution permissions (in the case of directories, the
xmeans searching permissions. I.e. You can view the contents of the directory.).
-simply means the absence of that privilege. (There are more possibilities for permissions than
-, 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>.
dushows disk usage. The
-soption summarizes the disk usage, rather than the default behavior of showing each file’s individual disk usage for all files in the
-hoption shows the disk-usage in human-readable format.
- 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
@ at the end of the Permissions Block. This describes extended attributes of the file. This feature is Mac-specific.
3. ls -h
-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
4. ls -F
/ 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:
5. ls -G
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.