Find file types and information about files.
Outcomes
View file contents and distinguish between file types.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start files-filetypes
Instructions
On the command line, list your files and directories by using different command options.
List the files and directories in your current working directory.
[student@workstation ~]$ ls
Desktop Documents Downloads Music Pictures Public README.md Templates VideosList your files and directories by using a long listing format.
[student@workstation ~]$ ls -l
total 4
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Desktop
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Documents
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Downloads
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Music
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Pictures
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Public
-rw-r--r--. 1 student student 3619 Oct 13 14:51 README.md
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Templates
drwxr-xr-x. 2 student student 6 Oct 9 22:03 VideosList your files and directories by using a long listing format and show the size of files in a human-readable format.
[student@workstation ~]$ ls -lh
total 4.0K
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Desktop
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Documents
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Downloads
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Music
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Pictures
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Public
-rw-r--r--. 1 student student 3.6K Oct 13 14:51 README.md
drwxr-xr-x. 2 student student 6 Oct 9 22:03 Templates
drwxr-xr-x. 2 student student 6 Oct 9 22:03 VideosQuery the file type of the README.md file.
[student@workstation ~]$ file README.md
README.md: UTF-8 Unicode text
UTF-8 Unicode is the file's recognized character set.
Query the number of lines, words, and characters in the README.md file.
Query the number of lines in the README.md file.
[student@workstation ~]$ wc -l README.md
88 README.mdQuery the number of words in the README.md file.
[student@workstation ~]$ wc -w README.md
448 README.mdQuery the number of characters in the README.md file.
[student@workstation ~]$ wc -c README.md
3619 README.mdView the full contents of the README.md file.
The long output scrolls off the screen and stops at the end of the file because the cat command does not paginate the output.
[student@workstation ~]$ cat README.md
...output omitted...
# Software
[Software](https://wiki.gnome.org/Apps/Software) allows users to easily find,
discover and install apps. It also keeps their OS, apps and devices up to date
without them having to think about it, and gives them confidence that their
system is up to date. It supports popular distributions, subject to those
distributions maintaining their own distro-specific integration code.
...output omitted...
# Maintainers
Software is maintained by several co-maintainers, as listed in gnome-software.doap.
All changes to Software need to be reviewed by at least one co-maintainer (who
can't review their own changes). Larger decisions need input from at least two
co-maintainers.View the README.md file head.
Then view only the first three lines.
View the first lines of the README.md file by using the head command.
The head command defaults to 10 lines.
[student@workstation ~]$ head README.md
# Software
[Software](https://wiki.gnome.org/Apps/Software) allows users to easily find,
discover and install apps. It also keeps their OS, apps and devices up to date
without them having to think about it, and gives them confidence that their
system is up to date. It supports popular distributions, subject to those
distributions maintaining their own distro-specific integration code.
The specific use cases that Software covers are [documented in more detail](./doc/use-cases.md).View the first three lines of the README.md file.
[student@workstation ~]$ head -n 3 README.md
# Software
[Software](https://wiki.gnome.org/Apps/Software) allows users to easily find,View the last three lines of the README.md file.
[student@workstation ~]$ tail -n 3 README.md
All changes to Software need to be reviewed by at least one co-maintainer (who
can't review their own changes). Larger decisions need input from at least two
co-maintainers.Query the file type of the cat command, and then attempt to view the contents of the binary file by using the cat command and the less command.
Query the full path name of the cat command file.
The system locates the cat command by sequentially searching the directories in your PATH variable.
[student@workstation ~]$ which cat
/bin/catQuery the file type of the /bin/cat file.
The output states that the cat file is an Executable and Linkable Format (ELF) binary program file.
[student@workstation ~]$ file /bin/cat
/bin/cat: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c03f9125d32e5af4ca1852b7316746ee0fafc4ec, for GNU/Linux 3.2.0, strippedAttempt to view the contents of the binary file by using the cat command.
In this example, you use the /bin/cat program as both the viewing program and the binary executable to view.
Viewing a binary file with a text viewer is not useful, but you can recognize the behavior if you make this common mistake.
[student@workstation ~]$ cat /bin/cat
ELF�'@�@8@����@@@h�h������������HzHz��PzPzPzp�|||������DDS�td���P�td�j�j�j��Q�td
R�tdPzPzPz��/lib64/ld-linux-x86-64.so.2GNU�GNU���GNU��=~���a�Z���A_��z�1u����#9�
...output omitted...If the terminal freezes, you might not continue to see the characters that you type. First, try pressing q or Ctrl+C to quit the file viewing program that you attempted.
Next, press Enter to move your cursor to a new command line.
Then, type stty sane and press Enter, even if you do not see a prompt displayed.
Your typing might not echo, but the command prompt should return.
If the command prompt does not return, then close the terminal window and start another terminal.
Attempt to view the /bin/cat binary file by using the less command.
The less command is safer because it warns that you are attempting to improperly view a binary file.
When prompted by the warning, press n to indicate that you do not want to view the file.
[student@workstation ~]$less /bin/cat"/bin/cat" may be a binary file. See it anyway?n