Skip to content
DevNursery.com - New Web Developer Docs
GitHub

Terminal Reference

Computer File Systems

Computer file structures, also known as file systems, are hierarchical structures that organize and store data on a computer’s storage devices, such as hard drives, solid-state drives, or network drives. The most commonly used file system on Unix-like operating systems, including Linux, is called the File Hierarchy Standard (FHS).

Here’s an explanation of computer file structures with an ASCII art depiction of a file system and how commands like “cd” relate to it:

        Root Directory (/)
       /                \
  /home              /etc
    |                 /    \
   /user1         /config   /data
     |             /         /     \
    file1.txt   apache/    settings.conf
                httpd.conf

Root Directory (/): At the top of the hierarchy is the root directory, denoted by a forward slash (/). It is the starting point for the entire file system and contains all other directories and files.

/home: This directory typically contains user-specific directories. Each user has their own directory within /home, such as /home/user1. Users can store their personal files and folders within their respective home directories.

/etc: The /etc directory stores system-wide configuration files and scripts. It contains various subdirectories and files that configure the behavior of the system and applications.

/etc/config: An example of a subdirectory within /etc. This subdirectory may contain configuration files for a specific application or service.

/etc/data: Another subdirectory within /etc. It may store data files or additional configuration files related to system settings.

/etc/data/settings.conf: An example of a file within the /etc/data directory. This file may contain configuration settings for a particular system component.

Commands like “cd” (Change Directory): In this file system structure, the “cd” command is used to navigate between directories. For example:

To move from the root directory to the /home directory, you would use: cd /home.

To go from /etc to /etc/config, you would use: cd /etc/config.

The “cd” command allows you to change your current working directory within the file system, making it easier to access and manipulate files and directories. You can use absolute paths (starting from the root directory) or relative paths (based on your current directory) with “cd” to navigate the file system.

This hierarchical structure helps users and system administrators organize and manage files and directories effectively. It also serves as the foundation for many file-related commands in the Unix-like operating systems, allowing users to interact with the file system efficiently.

File Paths

Relative and absolute paths are ways to specify the location of a file or directory within a file system. They are used in various computing contexts, including operating systems, web development, and programming. Here’s an explanation of both with examples:

Relative Paths:

Relative paths specify the location of a file or directory relative to your current working directory. They are typically shorter and more concise than absolute paths because they rely on your current context.

Here are some key points about relative paths:

  • They do not begin with a forward slash (/) or drive letter (on Windows).
  • They are used when you want to reference files or directories in relation to your current position in the file system.
  • You can use special notations like . (current directory) and .. (parent directory) to navigate.

Examples of relative paths:

  • ./file.txt: This references a file named “file.txt” in the current directory.
  • ../folder/: This points to a directory named “folder” in the parent directory.
  • ../folder/file.txt: This specifies a file named “file.txt” inside the “folder” directory in the parent directory.
Absolute Paths:

Absolute paths provide the full, unambiguous path to a file or directory from the root of the file system. They are not dependent on your current working directory and are used to specify an exact location in the file system.

Here are some key points about absolute paths:

  • They begin with a forward slash (/) on Unix-like systems (Linux, macOS) or a drive letter (e.g., C:) on Windows.
  • They are used when you need to specify the exact location of a file or directory, regardless of your current working directory.

Examples of absolute paths:

  • /home/user/documents/file.txt: This is an absolute path to a file named “file.txt” in the user’s “documents” directory on a Unix-like system (Mac or Linux).
  • C:\Users\User\Documents\file.txt: This is an absolute path to a file named “file.txt” in the “Documents” folder on a Windows system.
When to Use Each:

Relative Paths: Use relative paths when you want to reference files or directories within the same project or when writing scripts that should be portable and not tied to specific directory structures. They are more flexible and maintainable in these cases.

Absolute Paths: Use absolute paths when you need to specify an exact, fixed location. For example, when configuring system settings, specifying files outside your project, or when working with scripts or commands that must consistently reference the same file or directory.

Understanding the difference between relative and absolute paths is crucial for effective file and directory navigation in various computing contexts. Your choice of path type depends on the specific task and requirements of your project or system.

Basic Commands

CommandDescriptionExample Usage
lsList files and directories.ls -l /path/to/directory
cdChange directory.cd /path/to/directory
pwdPrint the current working directory.pwd
touchCreate an empty file.touch newfile.txt
mkdirCreate a new directory.mkdir new_directory
rmRemove files or directories.rm file.txt or rm -r directory/
cpCopy files or directories.cp file.txt newfile.txt
mvMove or rename files or directories.mv file.txt newfile.txt or mv oldname.txt newname.txt

File Manipulation

CommandDescriptionExample Usage
catConcatenate and display file contents.cat file.txt
headDisplay the beginning of a file.head -n 10 file.txt
tailDisplay the end of a file.tail -n 10 file.txt
nanoText editor for creating/editing files.nano newfile.txt
vimText editor for creating/editing files.vim newfile.txt
grepSearch for text patterns in files.grep "pattern" file.txt
findSearch for files and directories.find /path/to/search -name "*.txt"
chmodChange file permissions.chmod 755 file.txt
chownChange file ownership.chown user:group file.txt

System Information

CommandDescriptionExample Usage
topDisplay system processes.top
psList running processes.ps aux
dfDisplay disk space usage.df -h
duShow directory space usage.du -sh /path/to/dir
freeDisplay memory usage.free -m
unameShow system information.uname -a

Networking

CommandDescriptionExample Usage
pingTest network connectivity.ping google.com
ifconfigDisplay network configuration.ifconfig
ipDisplay network configuration.ip addr show
sshSecurely connect to remote servers.ssh username@hostname
scpSecurely copy files over SSH.scp file.txt remote:~/
curlDownload files from the internet.curl -O https://example.com/file.txt
wgetDownload files from the internet.wget https://example.com/file.txt
netstatNetwork statistics.netstat -tuln

Package Management

CommandDescriptionExample Usage
apt-getPackage manager for Debian/Ubuntu systems.apt-get install package_name
yumPackage manager for CentOS/RHEL systems.yum install package_name
dpkgPackage management tool for Debian/Ubuntu systems.dpkg -i package.deb
rpmPackage management tool for CentOS/RHEL systems.rpm -i package.rpm

Process Control

CommandDescriptionExample Usage
killTerminate processes.kill process_id
killallTerminate processes by name.killall process_name
ps aux | grep process_nameFind and kill a specific process.ps aux | grep process_name

Compression and Archiving

CommandDescriptionExample Usage
tarCreate and extract tarballs.tar -cvf archive.tar files or tar -xvf archive.tar
zipCompress and decompress ZIP files.zip archive.zip file.txt or unzip archive.zip
gzipCompress and decompress files using gzip.gzip file.txt or gunzip file.txt or zcat file.txt.gz

File Transfer

CommandDescriptionExample Usage
ftpTransfer files over FTP protocol.ftp ftp.example.com
sftpTransfer files over SFTP protocol.sftp username@hostname
rsyncSynchronize files and directories.rsync -av source/ destination/

Terminal Text Editors (Nano/VIM)

Terminal text editors are command-line tools that allow you to create, edit, and manipulate text files directly from a terminal or shell. They are useful for a wide range of tasks, from writing code to editing configuration files. Two popular terminal text editors are Vim and Nano. Here’s an overview of how to use them:

Vim

Opening Vim:

To open a file in Vim, use the vim command followed by the filename:

vim filename.txt

Modes:

Vim has different modes for navigation and editing:

  • Normal mode: Used for navigation and issuing commands.

  • Insert mode: Used for editing and typing text.

  • Visual mode: Used for selecting text. Basic Navigation:

  • h, j, k, l: Move left, down, up, or right respectively.

  • w, b: Move forward or backward by word.

  • 0, $: Move to the beginning or end of the line.

  • gg, G: Move to the beginning or end of the file.

Basic Editing:

  • i: Enter insert mode before the cursor.
  • a: Enter insert mode after the cursor.
  • o, O: Open a new line below or above the current line.
  • x: Delete the character under the cursor.
  • dd: Delete the current line.
  • yy: Copy the current line.
  • p: Paste copied or cut text after the cursor.

Saving and Quitting:

  • :w: Save changes.
  • :q: Quit Vim.
  • or :x:
    Save and quit.
  • !:
    Quit without saving.

Search and Replace:

  • /search-term: Search for a term (use n for next occurrence).
  • /search-term/replacement:
    Replace a term with another.
  • :%s/search-term/replacement/g: Replace all occurrences in the file.

Visual Mode:

  • v: Enter visual mode to select text.
  • V: Enter visual line mode to select entire lines. Selected text can be copied, cut, or replaced.

Customization:

Vim is highly customizable. You can configure it by editing the ~/.vimrc file.

Nano

Opening Nano: To open a file in Nano, use the nano command followed by the filename:

nano filename.txt

Basic Navigation:

  • Arrow keys: Navigate within the text.
  • Ctrl + F, Ctrl + B: Scroll forward and backward.
  • Ctrl + U, Ctrl + D: Page up and down.
  • Ctrl + A, Ctrl + E: Move to the beginning and end of the line.

Basic Editing:

  • Type to insert or edit text.
  • Ctrl + O: Save changes.
  • Ctrl + X: Exit Nano.

Search and Replace:

  • Ctrl + W: Search for a term.
  • Ctrl + : Replace a term.
  • Ctrl + T: Open the search and replace menu.

Customization:

Nano is relatively simple compared to Vim but can be customized by editing the ~/.nanorc file.

Both Vim and Nano have many more features and commands to explore. Choosing between them often comes down to personal preference and the complexity of your text editing tasks. Vim is known for its steep learning curve but offers powerful text manipulation capabilities, while Nano is more straightforward and beginner-friendly.

PowerShell vs. Bash: Understanding the Differences

What is PowerShell?

PowerShell is a powerful and extensible command-line shell and scripting language developed by Microsoft. It was first introduced in 2006 and is primarily designed for managing and automating tasks on Windows systems. PowerShell provides a rich set of features and libraries for system administration, automation, and scripting.

How PowerShell Differs from Bash

While both PowerShell and Bash are command-line shells used for interacting with computer systems, they have distinct differences:

1. Command Syntax

  • Bash: Bash primarily uses simple, text-based commands and relies on a combination of external utilities and shell built-ins for most tasks. It uses space-separated command-line arguments and pipes for command chaining.

  • PowerShell: PowerShell uses a consistent verb-noun syntax for its commands, which are called “cmdlets” (pronounced “command-lets”). Cmdlets are objects that pass data between each other using a structured format. PowerShell emphasizes object-oriented pipelines.

2. Object-Oriented Approach

  • Bash: Bash primarily deals with text streams, making it suitable for text processing. However, handling structured data and objects can be less intuitive.

  • PowerShell: PowerShell is designed with a strong focus on handling structured data and objects. It treats everything as an object, making it well-suited for managing and manipulating data in a structured manner.

3. Cross-Platform Support

  • Bash: Bash is the default shell on most Unix-like operating systems, including Linux and macOS. It is also available for Windows through third-party tools like Cygwin and Windows Subsystem for Linux (WSL).

  • PowerShell: While PowerShell was initially exclusive to Windows, Microsoft introduced PowerShell Core (now known as PowerShell 7 and later) as a cross-platform version. PowerShell Core extends support to Linux and macOS, making it available on a wider range of systems.

4. Ecosystem and Libraries

  • Bash: Bash has a rich ecosystem of Unix utilities and a long history of shell scripting. It integrates well with existing Unix tools and libraries.

  • PowerShell: PowerShell comes with an extensive set of built-in cmdlets for system administration tasks on Windows. It also integrates with the .NET Framework and has access to the vast .NET ecosystem, allowing for powerful automation and scripting.

Default Shells for Common Operating Systems

  • Linux: The default shell for most Linux distributions is Bash. However, some distributions may use alternatives like Dash for scripting due to its lightweight nature.

  • macOS: macOS also uses Bash as the default shell in most versions, although Apple has been transitioning to Zsh as the default shell in recent macOS releases.

  • Windows: On Windows, the default shell is PowerShell, specifically PowerShell 5.1 (as of Windows 10). However, PowerShell 7 (or later) can be installed for cross-platform compatibility.

In summary, PowerShell and Bash are powerful command-line shells with their own strengths and purposes. PowerShell excels in managing Windows systems and emphasizes structured data handling, while Bash is the default choice for Unix-like systems with a vast ecosystem of Unix utilities. The choice between them often depends on the target platform and specific use cases.