# Common Linux Commands | Cycle.io

Canonical URL: https://cycle.io/learn/common-linux-commands

## Common Linux Commands.

Mastering the command line is a key skill for anyone working with [Linux](https://cycle.io/learn/linux-basics), whether you're managing servers, developing software, or orchestrating containers. Linux commands offer powerful ways to interact with the system, automate tasks, and manage resources efficiently. This guide covers some of the most commonly used Linux commands that form the foundation of daily tasks in a Linux environment.

### Basic Navigation and File Management Commands

#### `ls` - List Directory Contents

The `ls` command lists the files and directories in the current directory. It's often the first command you'll use when navigating the filesystem. Learn more about the [Linux File System](https://cycle.io/learn/linux-file-system).

```bash
ls
```

-   **Options**:

-   `-l`: Displays a detailed list, including file permissions, ownership, size, and modification date.
-   `-a`: Shows all files, including hidden ones (those starting with a dot `.`).
-   `-h`: Makes file sizes human-readable (e.g., KB, MB).

#### `cd` - Change Directory

The `cd` command changes the current working directory, essential for navigating the Linux file system.

```bash
cd /path/to/directory
```

-   **Shortcuts**:

-   `cd ~`: Goes to your home directory.
-   `cd ..`: Moves up one directory level.
-   `cd -`: Switches to the previous directory.

#### `pwd` - Print Working Directory

The `pwd` command shows the full path of the current working directory, helping you confirm your location in the directory structure.

```bash
pwd
```

#### `cp` - Copy Files and Directories

The `cp` command copies files or directories from one location to another.

```bash
cp source_file destination_file
```

-   **Options**:

-   `-r`: Recursively copies directories and their contents.
-   `-i`: Prompts before overwriting existing files.

#### `mv` - Move or Rename Files and Directories

The `mv` command moves or renames files and directories.

```bash
mv old_name new_name
```

-   **Use cases**:

-   Renaming a file: `mv old_name new_name`
-   Moving a file to a different directory: `mv file_name /path/to/directory`

#### `rm` - Remove Files or Directories

The `rm` command deletes files or directories.

```bash
rm file_name
```

-   **Options**:

-   `-r`: Recursively removes directories and their contents.
-   `-i`: Prompts before each removal, adding a layer of safety.

**Caution**: `rm` is irreversible, so use it carefully, especially with the `-r` option.

#### `mkdir` - Create Directories

The `mkdir` command creates new directories.

```bash
mkdir directory_name
```

-   **Options**:

-   `-p`: Creates parent directories as needed (e.g., `mkdir -p /parent/child/grandchild`).

#### `rmdir` - Remove Empty Directories

The `rmdir` command removes empty directories.

```bash
rmdir directory_name
```

For removing directories with contents, use `rm -r`.

### File Viewing and Editing Commands

#### `cat` - Concatenate and Display File Contents

The `cat` command displays the contents of a file.

```bash
cat file_name
```

-   **Options**:

-   `-n`: Numbers all output lines.

#### `less` and `more` - View File Contents Page by Page

`less` and `more` allow you to view large files one page at a time.

```bash
less file_name
```

-   **Navigation**:

-   `Space`: Move to the next page.
-   `q`: Quit the viewer.

#### `head` and `tail` - View the Beginning or End of a File

`head` shows the first few lines of a file, while `tail` shows the last few lines.

```bash
head file_name
tail file_name
```

-   **Options**:

-   `-n X`: Displays the first/last `X` lines (e.g., `head -n 10 file_name`).

#### `nano` and `vim` - Text Editors

`nano` and `vim` are command-line text editors. `nano` is more beginner-friendly, while `vim` offers powerful features for advanced users.

```bash
nano file_name
```

```bash
vim file_name
```

Learn more about [Shell Scripting Best Practices](https://cycle.io/learn/shell-scripting-best-practices) to enhance your editing and scripting skills in Linux.

### System Monitoring and Management Commands

#### `ps` - Display Running Processes

The `ps` command displays currently running processes.

```bash
ps
```

-   **Options**:

-   `aux`: Shows detailed information for all processes.

#### `top` - Real-Time System Monitoring

`top` provides a real-time view of system processes, including CPU and memory usage.

```bash
top
```

-   **Navigation**:

-   `q`: Quit `top`.

#### `htop` - Interactive Process Viewer

`htop` is an enhanced version of `top` with a more user-friendly interface (requires installation on some systems).

```bash
htop
```

#### `df` - Disk Space Usage

The `df` command displays disk space usage for the file system.

```bash
df -h
```

-   **Options**:

-   `-h`: Displays sizes in human-readable format (e.g., GB, MB).

#### `du` - Directory Space Usage

The `du` command estimates file and directory space usage.

```bash
du -h directory_name
```

-   **Options**:

-   `-h`: Displays sizes in human-readable format.
-   `-s`: Provides a summary of the directory's total size.

#### `free` - Display Memory Usage

The `free` command shows the amount of free and used memory in the system.

```bash
free -h
```

-   **Options**:

-   `-h`: Displays sizes in human-readable format.

### File Permissions and Ownership Commands

#### `chmod` - Change File Permissions

The `chmod` command changes the permissions of a file or directory.

```bash
chmod 755 file_name
```

-   **Common Permission Settings**:

-   `755`: Read and execute access for everyone, write access for the owner.
-   `644`: Read access for everyone, write access for the owner.

Learn more about [Linux File Permissions](https://cycle.io/learn/linux-file-permissions) to better understand how `chmod` works.

#### `chown` - Change File Ownership

The `chown` command changes the owner and group of a file or directory.

```bash
chown user:group file_name
```

### Networking Commands

#### `ping` - Test Network Connectivity

The `ping` command tests the network connection to a host.

```bash
ping example.com
```

-   **Options**:

-   `-c X`: Sends `X` number of packets (e.g., `ping -c 4 example.com`).

#### `ifconfig` - Configure Network Interfaces

The `ifconfig` command configures or displays network interfaces.

```bash
ifconfig
```

-   **Alternative**:

-   `ip a`: Modern command to display network interfaces.

Learn more about [Linux Networking Commands](https://cycle.io/learn/linux-networking-commands) for advanced networking tasks.

#### `curl` - Transfer Data from or to a Server

The `curl` command transfers data to or from a server, using various protocols like HTTP, FTP, and more.

```bash
curl http://example.com
```

-   **Options**:

-   `-O`: Saves the output to a file (e.g., `curl -O http://example.com/file.txt`).

#### `wget` - Download Files from the Web

`wget` is a command-line utility to download files from the web.

```bash
wget http://example.com/file.zip
```

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
