Skip to main content

Basic Commands in Unix/Linux: ls, cd, pwd, etc.

Basic Commands in Unix/Linux: ls, cd, pwd, etc. Basic Commands in Unix/Linux: ls, cd, pwd, etc.

Basic Commands in Unix/Linux: ls, cd, pwd, and more

1. ls: List Directory Contents

The ls command is used to list the contents of a directory. By default, it lists the contents of the current directory.

Syntax:

ls [options] [directory]

Common Options:

  • -l: Long listing format (includes file permissions, number of links, owner, group, size, and timestamp)
  • -a: Show all files, including hidden ones (those starting with a dot)
  • -h: Human-readable format (for sizes, e.g., KB, MB)

Example:

ls -lah

2. cd: Change Directory

The cd command allows you to navigate between directories.

Syntax:

cd [directory]

Examples:

  • To move to a subdirectory:
  • cd subdirectory_name
  • To go up one directory level:
  • cd ..
  • To return to the home directory:
  • cd ~

3. pwd: Print Working Directory

The pwd command prints the full path of the current working directory.

Syntax:

pwd

Example:

pwd

4. mkdir: Make Directory

The mkdir command creates a new directory.

Syntax:

mkdir [options] directory_name

Common Options:

  • -p: Create parent directories as needed

Example:

mkdir -p parent_directory/subdirectory

5. rmdir: Remove Directory

The rmdir command removes an empty directory.

Syntax:

rmdir [directory]

Example:

rmdir empty_directory

6. rm: Remove Files or Directories

The rm command is used to remove files or directories.

Syntax:

rm [options] file_or_directory

Common Options:

  • -r: Remove directories and their contents recursively
  • -f: Force removal without prompting for confirmation

Example:

rm -rf directory_to_remove

Comments

Popular posts from this blog

Understanding sudo and su: A Comprehensive Guide

Understanding sudo and su: A Comprehensive Guide Understanding sudo and su : A Comprehensive Guide What is sudo ? The sudo (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. Essentially, sudo grants temporary administrative privileges to perform a specific task. Key Features of sudo : Granular Control: sudo allows system administrators to delegate limited root access to users, specifying exactly which commands they are permitted to run. Auditability: Every use of sudo is logged, providing a clear trail of who used sudo , what commands were executed, and when. Temporary Elevation: sudo grants elevated privileges for the duration of a single command, reducing the risk of accidental system-wide changes. Sec...

Using ping, traceroute, and netstat for Network Diagnostics

Using ping, traceroute, and netstat for Network Diagnostics Using ping, traceroute, and netstat for Network Diagnostics In the complex world of networking, diagnosing and troubleshooting issues is essential for maintaining a healthy and efficient network. Three fundamental tools often used for these purposes are ping , traceroute , and netstat . Each of these utilities offers unique insights into network performance and connectivity. Let's dive into their functionalities, use cases, and how they can be employed effectively. 1. Ping: Checking Connectivity and Latency The ping command is one of the most straightforward and commonly used network diagnostic tools. It tests the reachability of a host on an Internet Protocol (IP) network and measures the round-trip time for messages sent from the source to a destination computer. How It Works: The ping command sends Inte...

Understanding the Sticky Bit and Its Role in File Security

Understanding the Sticky Bit and Its Role in File Security Understanding the Sticky Bit and Its Role in File Security File security is a critical aspect of managing any computing environment. Among the several mechanisms and permissions available to ensure files and directories are protected, the sticky bit is one of the lesser-known but powerful tools. This article aims to provide a comprehensive understanding of the sticky bit, how it functions, and its implications for file security. What is the Sticky Bit? The sticky bit is a permission setting that can be applied to files and directories in Unix and Unix-like operating systems such as Linux. Originally, it was used to indicate that a program's executable should be retained in memory after its initial execution to improve performance. However, this functionality has become largely obsolete with modern memory mana...