A Look Inside Linux series
A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)
Having covered the Linux file system, we'll now turn our gaze to the files themselves. Specifically, we'll look at files that contain data – although some of what we'll discuss also applies to user-owned directories. (Remember, “everything is a file”.)
We'll concentrate on practical aspects of working with files in the Linux file system. We'll see how to work with them at the Bash prompt, as well as with a graphical file manager. If you have a Linux box available, you can use it to follow along.
ls -a
to view at command line.In Linux, the type of data contained in a file is identified by its MIME type.
<class>/<format>
, where:text/html
, text/plain
, image/x-icon
, text/x-script.python
.py
for Python programs or .ico
for icons.Identifying the type of file varies with the tool you use.
file .bashrc
identifies its content as “ASCII text”.file .bashrc -i
identifies its content as text/plain; charset=us-ascii
. file /usr/bin/aplay
returns extensive information on the program, including liked libraries.file /usr/bin/aplay -i
returns the MIME type application/x-sharedlib; charset=binary
..py
extension.Taking a look at the contents of a file is most easily done at the command line. Two commands are most useful for this:
cat .bashrc
less .bashrc
/
), then type in the search string (a regular expression). Matches will be highlighted. You can move through them with the N
key for the next match, and the P
key for the previous match.Q
key. .tar.gz
, .zip
types, present a special case. There are command-line utilities to work with them, but I find it far easier to handle them in a GUI file browser that employs an archive manager.There are many thousands of files on your Linux box. Finding a particular file can be a challenge. A Linux desktop system provides file search capabilities at the command line and in a graphical file manager.
I tend to make command-line searches, using two utilities: ls and find.
The ls command is good for listing files that you can scan to find the one you want. It works best when looking in the current directory, or some other single directory. Let's look at how it works.
ls
returns a single-line list of files and directories in the current directory.ls <pattern>
returns a list of files in the current directory that match the pattern.ls *.pdf
lists PDF documents.ls -R
does a recursive search, returning all files in the current directory and in all subdirectories. It does not allow you to specify a pattern to narrow down the list.The find command is useful for finding particular types of files in places other than the current directory.
Let's say you want to locate icon files that are installed on your system. You know that that they're likely to be somewhere under the /usr
directory, since that's where applications are installed. You also know that icon files generally have an extension of .ico
.
You can use the find command to locate them:
find /usr -iname '*.ico'
Let's look at what's going on here. You're running the find command, telling it to start its search in the /usr
directory, and display all files with a name the ends in .ico
. Very neat. For more on how to use this command, look here.
Every file manager I've used has had some search capability. There are many file managers, each with its own interface, so I won't try to cover them here. Suffice to say that the app on your system has the ability to let you find files, if you learn to use it.
One reason I prefer the command line for this task is that it works the same in all Linux systems. I have to climb the learning curve only once, and then I can use it anywhere.
Just a quick look at what's available on Linux systems for managing files.
Linux gives you all the tools you need to work with your file system. You can use the command line, a graphical file manager – or both. You get to choose the tool that works best for you.