In part 1 of our series about getting started with Linux, we learned how to download Linux, whether you should use the CLI or the GUI, how to get a SSH client, how to login to Linux and how to get help. In this post, you’ll learn how to know what type of Linux you are using and how to navigate the Linux file system.
How do I know what type of Linux I am using?
Because there are so many different types of Linux, you want to be sure you know what distribution and version you are using (for the sake of searching the right documentation on the Internet, if nothing else). Keep in mind a couple different commands to identify your Linux version.
The uname command shows the basic type of operating system you are using, like this:
[email protected]:~$ uname -a
Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2 (2017-04-30) i686 GNU/Linux
And the hostnamectl command shows you the hostname of the Linux server as well as other system information, like the machine ID, virtualization hypervisor (if used), operating system and Linux kernel version. Here’s an example:
[email protected]:~$ hostnamectl
Static hostname: debian
Icon name: computer-vm
Machine ID: 0eb625ef6e084c9181b9db9c6381d8ff
Boot ID: 8a3ef6ecdfcf4218a6102b613e41f9ee
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-686-pae
As shown above, this host is running Linux. More specifically, the host is running Debian GNU Linux version 8 (codename jessie) with a Linux 3.16 version kernel on an x86 CPU architecture. Among other things, you can also see that this Linux installation is running on a virtual machine with VMware as the hypervisor. Cool, huh?
Where do I find things?
An operating system has a file system that, similar to a filing cabinet, allows you to store and retrieve data. Most file systems use the concept of directories—also called folders—and files that are stored inside the directories. Everything in Linux, even hardware, is represented in this folder and file structure.
If you’re new to Linux, you might be wondering how the Linux file system compares to something familiar like the Microsoft Windows file system. In Windows, you may be used to drive letters (like the C: drive) being used as the highest point of a storage volume. Linux represents the highest level of the volume differently. The Linux file system can span multiple physical drives, which are all a part of the same tree. The highest point of the Linux file system is the “/,” or “root,” with all other directories branching down the tree from there, as shown in Figure 1.
Interaction with and navigation of the Linux file system is done up and down the tree with commands such as:
- pwd: Display the directory you’re currently in (short for print working directory).
- ls: List out files that are present in the folder.
- cd: Change directory.
- rm: Remove files.
- mkdir and rmdir: Make and remove folders or directories, respectively.
Figure 1. The typical Linux file system
Let’s do a quick exercise. First, by using the pwd command, you can see what directory I’m currently in.
[email protected]:~$ pwd
Next, to change to the root directory, you can use the cd command.
[email protected]:~$ cd /
To get a simple list of files, you can use the ls command. This will display a very concise list of the files and folders that exist in the current directory.
[email protected]:/$ ls
bin boot dev etc home initrd.img lib lost+found media mnt opt proc root run sbin srv sys tmp usr var vmlinuz
But, in most cases, you probably want more information than just a simple list of files. Linux uses command line flags or switches to extend what a command can do. For example, to list out all the files and folders in the current directory, along with full details about each one, you would type ls -la. This long listing format then shows you each file and directory, as well as the permissions and access rights for each object, the name of the user that owns the object (root), the name of the group that owns the object (again, root), the file size and the data and time that the object was last modified. Here’s what this output looks like for the root folder on my test system:
[email protected]:/$ ls -la
drwxr-xr-x 21 root root 4096 May 15 11:50 .
drwxr-xr-x 21 root root 4096 May 15 11:50 ..
drwxr-xr-x 2 root root 4096 May 15 12:11 bin
drwxr-xr-x 3 root root 4096 May 15 15:53 boot
drwxr-xr-x 18 root root 3200 Jul 14 01:52 dev
drwxr-xr-x 134 root root 12288 Jul 14 01:55 etc
drwxr-xr-x 3 root root 4096 May 15 15:53 home
lrwxrwxrwx 1 root root 33 May 15 11:50 initrd.img -> /boot/initrd.img-3.16.0-4-686-pae
drwxr-xr-x 19 root root 4096 May 17 00:41 lib
drwx------ 2 root root 16384 May 15 11:49 lost+found
drwxr-xr-x 3 root root 4096 May 15 11:49 media
drwxr-xr-x 2 root root 4096 May 15 11:49 mnt
drwxr-xr-x 2 root root 4096 May 15 11:49 opt
dr-xr-xr-x 150 root root 0 Jul 14 01:52 proc
drwx------ 2 root root 4096 May 16 14:29 root
drwxr-xr-x 23 root root 880 Jul 14 01:57 run
drwxr-xr-x 2 root root 4096 May 17 00:41 sbin
drwxr-xr-x 2 root root 4096 May 15 11:49 srv
dr-xr-xr-x 13 root root 0 Jul 14 01:52 sys
drwxrwxrwt 13 root root 4096 Jul 14 02:02 tmp
drwxr-xr-x 10 root root 4096 May 15 11:49 usr
drwxr-xr-x 12 root root 4096 May 15 12:12 var
lrwxrwxrwx 1 root root 29 May 15 11:50 vmlinuz -> boot/vmlinuz-3.16.0-4-686-pae
One of the most common questions from new Linux users who are at a command line is, “What are the applications available to me, and how do I run them?” As mentioned previously, most user tools are found in the directories /bin and /usr/bin and system tools are typically located in /sbin and /usr/sbin. For example, tools like cp (to copy a file), ps (for process status) and cat (to display the contents of a file) are all found in /bin. The great thing is you don’t need to go into any of these directories to run these types of tools because these directories are included in your $PATH variable by default.
The $PATH variable includes all the locations that are searched when you run a command in the CLI. Because the /bin directories are in your path, when you execute the name of any of these sample tools, they will be found. Here’s what your $PATH variable might look like (shown by using the echo command to show the $PATH variable):
[email protected]:~$ echo $PATH
You can execute applications or commands simply by typing the name of the command if the application’s location is in your $PATH. If that application is not in one of the folders listed in your $PATH, you have to do one of the following:
- Navigate to the folder where the application is found and tell Linux that you want to execute the application in that folder, like this:
(The “dot slash” refers to the current folder, with the full command saying “in the current directory, execute ‘my app.’”)
- Specify the full path of the application when you execute it, like this:
[email protected]:~$ /opt/app/bin/myapp
A useful command in determining which command will be run and from what directory it will be run is the which command. Use which with the executable of a command afterward to get a list of the location of the command that will be executed.
Besides the standard types of Linux tools, there are tens of thousands of applications you can install into Linux in just a few commands. Linux distributions offer package managers that help you search online package or application repositories and then download and install just about any application you might want. Package managers also make it easy to update your packages to get the latest version. Examples of package managers are apt, dpkg, rpm, and yum. The package manager that is available to you will be determined by the Linux distribution that you have installed. Linux running on Android mobile devices also has its own package manager (similar to the Apple “App Store”).
On Debian and Ubuntu systems, you can run:
apt list --installed and get a list of the packages that are already installed, like this:(Output truncated)
[email protected]:~$ apt list --installed
accountsservice/stable,now 0.6.37-3+b1 i386 [installed,automatic]
acl/stable,now 2.2.52-2 i386 [installed]
acpi/stable,now 1.7-1 i386 [installed]
acpi-support-base/stable,now 0.142-6 all [installed]
Any apt list command will result in very long output, so you may consider piping it to the “less” pager tool, like this:
apt list | less.
This will show you the output page by page and allow you to press the space bar after each page to see the next page.
To learn more about getting started with the Linux OS, keep an eye out for part 3 of this series, coming soon!
<< This article was originally published on blog here. >>