LogoLogo
  • Welcome
  • Explorers
    • Aptos Explorer
    • Cosmos Explorer
  • Blockchains
    • Aptos
      • Run a Validator and VFN
        • Operator
        • Node Requirements
        • Deploy Nodes
          • Using Source Code
        • Connect Nodes
          • Connect to a Network
          • Staking Pool Operations
          • Delegation Pool Operations
          • Staking Pool Voter
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
        • Modify Nodes
          • Upgrade Nodes
          • Shutdown Nodes
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Deploy a PFN using Source Code
        • Verify a PFN
        • Modify a PFN
          • Customize PFN Networks
          • Generate a PFN Identity
          • Upgrade your PFN
          • Run a PFN from Source Code
      • Bootstrap a Node with historical data
        • Bootstrap from a Backup
        • Bootstrap from a Snapshot
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor your Nodes
        • Important Node Metrics
        • Node Health Checker
        • Node Health Checker FAQ
        • Node Inspection Service
      • Building Aptos From Source
      • Aptos Networks
    • Berachain V2
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • gRPC Endpoint
      • Live Peers
      • Forest Staking Peer
      • Performance Optimizer Script
      • Discord & TG Alert System
      • RPC Load Balancer Setup
    • Casper
      • Explorer
    • Haqq
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Mantra
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Ika
    • Story Protocol
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • EVM Endpoint
      • Websocket
      • WSS
      • Discord & TG Alert System
      • RPC Load Balancer
      • Performance Optimizer Script
      • Live Peers
      • Forest Staking Peer
    • Supra
      • Explorer
      • Oracle data
    • Showdown
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Soarchain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zenrock
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Zetachain
      • Node Snapshot
      • Explorer
      • AddrBook File
      • Genesis File
      • API Endpoint
      • RPC Endpoint
      • Live Peers
      • Forest Staking Peer
    • Airchains
      • Node Snapshot
      • Explorer
  • Gunzilla - Off The Grid
    • Vision and Foundation
    • Gunzilla Hacker Dashboard
      • Key Features of the Hackers Dashboard
        • Wallet Integration and Testnet Access
        • License System with Rarity Tiers
        • Decoding Stats and Hash Power Tracking
        • Marketplace for Trading Licenses and Assets
        • Scanner Tool for Blockchain Transparency
        • Social Media Integration and Community Engagement
      • Mastering the Hackers Dashboard
      • Benefits of the Hackers Dashboard
    • Gunzilla Token Page
  • Forest Esports Team
    • Forest Hexers
  • Crypto Tools & Analytics
    • Top 10 Crypto Exchanges
      • Binance
      • Coinbase
      • Kraken
      • Bybit
      • OKX
      • KuCoin
      • Bitfinex
      • Gemini
      • Crypto.com
      • Bitstamp
    • Top 10 Wallets
      • Ledger Nano X
      • Trezor Model T
      • Exodus
      • Coinbase Wallet
      • Trust Wallet
      • MetaMask
      • Crypto.com DeFi Wallet
      • ZenGo
      • Atomic Wallet
      • SafePal
  • Top 10 Crypto Data Platforms
    • CoinMarketCap
    • CoinGecko
    • CryptoCompare
    • CoinCodex
    • Live Coin Watch
    • CoinCheckup
    • Messari
    • CoinPaprika
    • Arkham Intelligence
  • DeFi Analytics and Tracking
    • DefiLlama
    • Dune Analytics
    • DeBank
    • Zapper
    • Token Terminal
    • DeepDAO
    • Revert Finance
    • L2BEAT
  • API's
    • What are APIs?
    • How APIs Work
    • Types of APIs
    • Real-World API Use Cases
    • Benefits of Using API's
    • Challenges and Considerations of using API's
  • Node Security
    • Physical Security
    • Network Security
    • System and Software Security
    • Access Control
    • Data Security
    • Monitoring and Logging
    • Backup and Disaster Recovery
    • Best Practices for Validator Nodes
    • Cloud Security
    • Incident Response and Recovery
  • Linux Bash
    • Bash 101
      • Getting Started with Bash
      • Navigating the File System
      • File Management Basics
      • Viewing and Editing Files
      • Managing Permissions
      • Working with Processes
      • Using Pipes and Redirection
      • Bash Scripting Basics
      • Essential Networking Commands
      • Installing Software with Package Managers
    • Advanced Linux for Validator Nodes
      • Advanced Bash Scripting for Node Automation and Maintenance
      • Monitoring and Logging Essentials
      • Networking and Security Best Practices
      • Backup and Disaster Recovery
  • Staking 101
    • Understand What Staking Is and How It Works
    • Choose a Blockchain Network to Stake On
    • Set Up a Compatible Wallet for Staking
    • Purchase or Transfer Funds for Staking
    • Choose a Staking Pool
    • Connect Your Wallet to a Staking Platform
    • Confirm and Stake Your Funds
    • Monitor Staking Rewards and Performance
    • Withdraw or Re-Stake Rewards
  • Optimizing Your Infrastructure Choices
    • Infrastructure Comparison: VPS vs. Bare Metal
Powered by GitBook
On this page

Was this helpful?

  1. Linux Bash
  2. Bash 101

File Management Basics

Bash provides a powerful set of commands for creating, moving, copying, and deleting files and directories directly from the command line. These file management commands are essential for organizing and manipulating data efficiently in Linux, especially when working on servers or systems without a graphical interface. Here’s an expanded look at each command and how it’s used in Bash:


1. touch filename – Create a New File

The touch command is primarily used to create new, empty files in the current directory or specified location. It’s a simple way to generate files quickly without needing an editor. For example:

$ touch newfile.txt

This command creates an empty file named newfile.txt. If the file already exists, touch updates its timestamp to the current date and time without modifying the contents. This is useful for marking files as recently accessed or modified without changing their data.


2. mkdir directoryname – Create a New Directory

The mkdir (make directory) command is used to create a new directory (folder) in the current directory or specified path. Directories are essential for organizing files into manageable groups. Here’s how it works:

$ mkdir newfolder

This command creates a directory named newfolder. You can also create multiple directories at once:

$ mkdir folder1 folder2

To create nested directories (directories within directories) in one step, use the -p option:

$ mkdir -p parent/child

This command creates both parent and child directories, even if parent didn’t previously exist. The -p option is useful for setting up directory structures with multiple layers.


3. cp source destination – Copy Files and Directories

The cp (copy) command copies files or directories from one location to another. It’s commonly used to duplicate files for backup or organizational purposes. Here’s the basic usage:

$ cp originalfile.txt copyfile.txt

This command copies originalfile.txt to copyfile.txt in the same directory. The original file remains unchanged, and copyfile.txt contains an identical copy.

  • Copying Directories:

    • Use the -r (recursive) option to copy entire directories and their contents:

      $ cp -r sourcedir destinationdir
    • This command copies sourcedir and all of its files and subdirectories into destinationdir. The -r option is essential for copying directories, as cp only works with files by default.

  • Preserving Attributes:

    • Add the -a (archive) option to preserve file attributes, including permissions and timestamps:

      $ cp -a sourcedir destinationdir
    • This is helpful for maintaining original file metadata, especially when creating backups or moving files between directories.


4. mv source destination – Move or Rename Files and Directories

The mv (move) command moves files or directories from one location to another and can also rename them in the process. It’s an efficient way to reorganize files and rename items without needing to copy and delete them separately.

  • Moving Files:

    • $ mv filename.txt /path/to/destination/
    • This command moves filename.txt to the specified directory, removing it from the original location.

  • Renaming Files or Directories:

    • $ mv oldname.txt newname.txt
    • This renames oldname.txt to newname.txt in the same directory. The file contents and metadata remain unchanged, only the name is updated.

  • Moving Multiple Files:

    • You can move multiple files into a directory by listing them before the destination:

      $ mv file1.txt file2.txt /path/to/destination/

The mv command does not create a copy; it simply relocates or renames the file, making it more efficient for organizing large files or directories.


5. rm filename – Delete Files and Directories

The rm (remove) command deletes files and directories. Unlike moving items to a trash bin, rm permanently deletes files, so it’s essential to use this command carefully, as deleted files cannot be recovered without backups.

  • Deleting Files:

    • $ rm filename.txt
    • This command deletes filename.txt from the directory permanently.

  • Deleting Directories:

    • Use the -r (recursive) option to delete directories and their contents:

      $ rm -r directoryname
    • This command deletes directoryname along with all its files and subdirectories. It’s a powerful option that should be used with caution, as it removes everything in the specified directory.

  • Adding Confirmation with -i:

    • The -i (interactive) option prompts you for confirmation before each deletion:

      $ rm -i filename.txt
    • This is helpful if you’re deleting multiple files and want to double-check each removal.

  • Force Deletion with -f:

    • The -f (force) option bypasses prompts and forces deletion, even for write-protected files:

      $ rm -rf directoryname
    • This command is often used for automated cleanup scripts, but it should be used cautiously to avoid accidental deletion.


PreviousNavigating the File SystemNextViewing and Editing Files

Last updated 6 months ago

Was this helpful?

Page cover image