Linux terminal file system

Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

For users more familiar with a graphical user interface (GUI), the Linux command line interface can initially appear daunting. It is not always apparent how to perform common file and directory operations. Fortunately, Linux commands are very powerful and flexible, and with some practice, you can accomplish any file management operation you want. This guide explains how to navigate the Linux file structure and how to perform common management operations on files and directories.

An Introduction to the Linux File System

Linux has a directory-based structure. Files are stored within a particular directory, which is also referred to as a folder. Each directory can also contain other directories. These directories can in turn contain files and directories.

Conceptually, this can be thought of in terms of a tree structure. At the trunk of the tree is the / directory, also known as the root directory. All other directories branch off of the root directory. The root file system contains all the files and directories which are on the same disk partition as the root directory. All the files required to boot the system must be contained inside the root file system. Other file systems can be mounted as subdirectories within the root file system.

Every Linux prompt is actually a process that is associated with a location that maps to a directory within the file system. The directory a user is currently working in is known as the current working directory or present working directory (PWD). The name of this directory can be retrieved using the pwd command. It is possible to navigate from this point through the file system using either absolute or relative path names.

The root directory of most Linux file systems includes several standard, well-defined directories. The most important of these directories include the following:

  • /bin: contains user-executable programs and files.
  • /boot: contains the bootloader and the files required to boot the computer.
  • /etc: stores configuration files for the system.
  • /home: contains the home directories for the various user accounts. Each user has a subdirectory located at /home/userid . While a user is logged in, their home directory is aliased as the ~ directory.
  • /lib: shared system library files are located in this directory.
  • /root: this is the home directory for the root user. This is not the same as the root, or / directory.
  • /usr: contains shared binary, library, and documentation files for all users.
  • /var: data files are typically stored here.
Читайте также:  Замена finereader для linux

How to List Files in Linux

The ls command provides a way to list files within a directory. However, many options allow for output filtering or to change what information to display.

The ls Command

  1. To display all files and directories except hidden files, use the ls command. Specify the relative or absolute path of a directory to list files in that directory. If no directory is specified, the contents of the current directory are displayed.
cities.txt countries.txt payroll states.txt states2.txt 
accounts/ backup/ mysqlbackup/ phpcomposer/ wpbackup/ 
-rw-rw-r-- 1 userid userid 29 Aug 31 14:51 cities.txt -rw-rw-r-- 1 userid userid 42 Aug 31 14:51 countries.txt drwxrwxr-x 2 userid userid 4096 Sep 2 16:51 payroll -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states2.txt 

The . directory refers to the current working directory. The .. entry is a hard link to the parent directory. This is the directory containing the current directory.

drwxrwxr-x 3 userid userid 4096 Sep 3 10:56 . drwxr-xr-x 10 userid userid 4096 Sep 1 08:48 .. -rw-rw-r-- 1 userid userid 51 Sep 3 10:56 .states2.txt -rw-rw-r-- 1 userid userid 29 Aug 31 14:51 cities.txt -rw-rw-r-- 1 userid userid 42 Aug 31 14:51 countries.txt drwxrwxr-x 2 userid userid 4096 Sep 2 16:51 payroll -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states2.txt 
-rw-rw-r-- 1 userid userid 51 Sep 3 10:56 .states2.txt -rw-rw-r-- 1 userid userid 29 Aug 31 14:51 cities.txt -rw-rw-r-- 1 userid userid 42 Aug 31 14:51 countries.txt drwxrwxr-x 2 userid userid 4096 Sep 2 16:51 payroll -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states2.txt 
-rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states2.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states.txt drwxrwxr-x 2 userid userid 4096 Sep 2 16:51 payroll -rw-rw-r-- 1 userid userid 42 Aug 31 14:51 countries.txt -rw-rw-r-- 1 userid userid 29 Aug 31 14:51 cities.txt 
drwxrwxr-x 2 userid userid 4096 Sep 2 16:51 payroll -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:51 states2.txt -rw-rw-r-- 1 userid userid 42 Aug 31 14:51 countries.txt -rw-rw-r-- 1 userid userid 29 Aug 31 14:51 cities.txt 
drwxrwxr-x 3 userid userid 4096 Sep 2 16:51 accounts drwxrwxr-x 2 userid userid 4096 Sep 1 08:47 backup -rw-rw-r-- 1 userid userid 42 Aug 31 14:50 countries.txt -rw-rw-r-- 1 userid userid 51 Aug 31 14:43 states.txt drwxrwxr-x 3 userid userid 4096 Aug 24 17:08 phpcomposer drwxrwxr-x 2 userid userid 4096 Jul 21 13:24 mysqlbackup drwxrwxr-x 3 userid userid 4096 Jul 21 12:06 wpbackup -rw-r--r-- 1 userid userid 196 Jul 20 14:42 testconnection2.php 
drwxrwxr-x 2 userid userid 4096 Sep 1 08:47 backup drwxrwxr-x 3 userid userid 4096 Sep 3 10:56 accounts drwxrwxr-x 3 userid userid 4096 Jul 21 12:06 wpbackup drwxrwxr-x 2 userid userid 4096 Jul 21 13:24 mysqlbackup -rw-r--r-- 1 userid userid 196 Jul 20 14:42 testconnection2.php -rw-rw-r-- 1 userid userid 51 Aug 31 14:43 states.txt -rw-rw-r-- 1 userid userid 42 Aug 31 14:50 countries.txt drwxrwxr-x 3 userid userid 4096 Aug 24 17:08 phpcomposer 

The ls command has many more options. Consult the Linux manual page for ls, also known as the command man page, for complete information.

Читайте также:  Linux mint wireguard client

How to Change Directories in Linux

It is possible to navigate the Linux file system in a relative or absolute manner. An absolute path indicates the location of a directory from the root directory, and always begins with the / symbol. A relative path is defined in relation to the current working directory.

The cd command is used to change directories. This command is very straightforward to use, but it does have a few useful shortcuts. More information about the cd command can be found on the Linux man page.

The cd Command

  1. While relatively navigating the Linux file system, it is often useful to know the path to the current directory. To display the full pathname of the present working directory, use the pwd command.

Most Linux distributions offer an auto-complete function. While typing the name of a file or directory, press the tab key. If the name is unambiguous, the system automatically completes the rest of the name. If there are multiple potential options, the system either lists all possible choices or auto-completes the characters common to all alternatives.

Источник

A beginner’s guide to navigating the Linux filesystem

As a new Linux user, one of the first skills that you need to master is navigating the Linux filesystem. These basic navigation commands will get you up to speed.

Navigating the Linux file system

The basics

Great Linux resources

Before we get into commands, let’s talk about important special characters. The dot ( . ) , dot-dot ( .. ) , forward slash ( / ), and tilde ( ~ ), all have special functionality in the Linux filesystem:

  • The dot ( . ) represents the current directory in the filesystem.
  • The dot-dot ( .. ) represents one level above the current directory.
  • The forward slash ( / ) represents the «root» of the filesystem. (Every directory/file in the Linux filesystem is nested under the root / directory.)
  • The tilde ( ~ ) represents the home directory of the currently logged in user.

I believe that the best way to understand any concept is by putting it into practice. This navigation command overview will help you to better understand how all of this works.

The pwd command prints the current/working directory, telling where you are currently located in the filesystem. This command comes to your rescue when you get lost in the filesystem, and always prints out the absolute path.

What is an absolute path? An absolute path is the full path to a file or directory. It is relative to the root directory ( / ). Note that it is a best practice to use absolute paths when you use file paths inside of scripts. For example, the absolute path to the ls command is: /usr/bin/ls .

Читайте также:  Check users permissions linux

The results of typing pwd in your terminal window.

If it’s not absolute, then it’s a relative path. The relative path is relative to your present working directory. If you are in your home directory, for example, the ls command’s relative path is: . ./../usr/bin/ls .

Change directory ( cd )

The cd command lets you change to a different directory. When you log into a Linux machine or fire up a terminal emulator, by default your working directory is your home directory. My home directory is /home/kc . In your case, it is probably /home/ .

Absolute and relative paths make more sense when we look at examples for the cd command. If you need to move one level up from your working directory, in this case /home , we can do this couple of ways. One way is to issue a cd command relative to your pwd :

Note: Remember, .. represents the directory one level above the working directory.

The other way is to provide the absolute path to the directory:

Either way, we are now inside /home . You can verify this by issuing pwd command. Then, you can move to the filesystem’s root ( / ) by issuing this command:

If your working directory is deeply nested inside the filesystem and you need to return to your home directory, this is where the ~ comes in with the cd command. Let’s put this into action and see how cool this command can be. It helps you save a ton of time while navigating in the filesystem.

My present working directory is root ( / ). If you’re following along, yours should be same, or you can find out yours by issuing pwd . Let’s cd to another directory:

$ cd /home/kc/0/1/2/3/4/5/6/7/8/9 $ pwd /home/kc/0/1/2/3/4/5/6/7/8/9 

To navigate back to your home directory, simply issue ~ with the cd command:

Again, check your present working directory with the pwd command:

The dash ( — ) navigates back to the previous working directory, similar to how you can navigate to your user home directory with ~ . If you need to go back to our deeply nested directory 9 under your user home directory (this was my previous working directory), you would issue this command:

The output of using the tilde (~) as a filesystem navigation shortcut.

Wrapping up

These commands are your navigation tools inside the Linux filesystem. With what you learned here, you can always find your way to the home (~) directory. If you want to learn more and master the command line, check out 10 basic Linux commands.

Want to try out Red Hat Enterprise Linux? Download it now for free.

Источник

Оцените статью
Adblock
detector