Server:  dns.google address:  8.8.8.8

Non-authoritative answer:
Name:    example.com
Address: 93.184.216.34

These commands are essential for navigating and managing the filesystem in Linux. They help users move around directories, view contents, search for files, and manage file and directory structures efficiently.

List of Linux Navigation Commands with Examples

Print Working Directory

pwd

  • Usage: Displays the full path of the current directory.
  • Example:
    $ pwd
    /home/user/Documents
  1. cd (Change Directory)

    • Usage: Changes the current working directory.
    • Examples:
      • Change to a specific directory:
        $ cd /var/log
      • Move up one directory (to the parent directory):
        $ cd ..
      • Return to the home directory:
        $ cd ~
      • Return to the previous directory:
        $ cd -
  2. ls (List)

    • Usage: Lists files and directories in the current directory.
    • Examples:
      • List all files and directories:
        $ ls
      • List with detailed information:
        $ ls -l
      • List all files including hidden ones:
        $ ls -a
      • List files in a specific directory:
        $ ls /etc
  3. tree

    • Usage: Displays directories and files in a tree-like format.
    • Example:
      $ tree
    • Note: You may need to install it first using sudo apt-get install tree.
  4. find

    • Usage: Searches for files and directories.
    • Examples:
      • Find a file named example.txt in the current directory and subdirectories:
        $ find . -name 'example.txt'
      • Find directories named config starting from the root:
        $ find / -type d -name 'config'
      • Find files modified in the last 24 hours:
        $ find /home/user -mtime -1
  5. locate

    • Usage: Quickly finds files by name using a database.
    • Example:
      $ locate '*.pdf'
    • Note: Update the database first with sudo updatedb.
  6. which

    • Usage: Shows the full path of shell commands.
    • Example:
      $ which python
      /usr/bin/python
  7. pushd and popd

    • Usage: Navigate between directories using a stack.
    • Examples:
      • Save current directory and change to /usr/local:
        $ pushd /usr/local
      • Return to the previous directory:
        $ popd
  8. dirs

    • Usage: Displays the directory stack.
    • Example:
      $ dirs
  9. history

    • Usage: Displays a list of previously executed commands.
    • Example:
      $ history
  10. man (Manual)

    • Usage: Shows the manual for a command.
    • Example:
      $ man ls
  11. alias

    • Usage: Creates shortcuts for commands.
    • Example:
      $ alias ll='ls -la'
  12. Tab Completion

    • Usage: Use the Tab key to auto-complete file and directory names in the shell.
    • Example:
      • Start typing a command or filename and press Tab:
        $ cd Docu[TAB]
      • Auto-completes to:
        $ cd Documents/
  13. echo $PATH

    • Usage: Displays the current PATH environment variable.
    • Example:
      $ echo $PATH
      /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
  14. touch

    • Usage: Creates an empty file or updates the timestamp of an existing file.
    • Example:
      $ touch newfile.txt
  15. mkdir (Make Directory)

    • Usage: Creates a new directory.
    • Examples:
      • Create a single directory:
        $ mkdir projects
      • Create nested directories:
        $ mkdir -p projects/2023/october
  16. rmdir

    • Usage: Removes empty directories.
    • Example:
      $ rmdir old_directory
  17. stat

    • Usage: Displays detailed information about a file or directory.
    • Example:
      $ stat myfile.txt
  18. df (Disk Free)

    • Usage: Reports file system disk space usage.
    • Example:
      $ df -h
  19. du (Disk Usage)

    • Usage: Estimates file space usage.
    • Examples:
      • Show disk usage of current directory:
        $ du -sh .
      • Show disk usage of all items in current directory:
        $ du -sh *
  20. mount and umount

    • Usage: Mounts and unmounts filesystems.
    • Examples:
      • Mount a USB drive:
        $ sudo mount /dev/sdb1 /mnt/usb
      • Unmount the USB drive:
        $ sudo umount /mnt/usb
  21. grep

    • Usage: Searches for patterns within files.
    • Example:
      $ grep 'search_term' file.txt
  22. less

    • Usage: Views text files one screen at a time.
    • Example:
      $ less largefile.txt
  23. tail

    • Usage: Displays the last part of files.
    • Example:
      $ tail -n 20 logfile.txt
  24. head

    • Usage: Displays the first part of files.
    • Example:
      $ head -n 10 data.csv
  25. findmnt

    • Usage: Displays a list of mounted filesystems.
    • Example:
      $ findmnt
  26. realpath

    • Usage: Displays the canonicalized absolute pathname.
    • Example:
      $ realpath ./relative/path
      /home/user/relative/path
  27. whereis

    • Usage: Locates the binary, source, and manual page files for a command.
    • Example:
      $ whereis ls
      ls: /bin/ls /usr/share/man/man1/ls.1.gz
  28. pwdx

    • Usage: Reports the current working directory of a process.
    • Example:
      $ pwdx 1234
      1234: /home/user/Documents
  29. chdir

    • Usage: Although not a standalone command, it is used in scripts to change the directory.
    • Example in a script:
      #!/bin/bash
      chdir /path/to/directory

**List of Linux Navigation Commands with Examples**

1. **`pwd`** *(Print Working Directory)*

- **Usage**: Displays the full path of the current directory.

- **Example**:

```bash

$ pwd

/home/user/Documents

```

2. **`cd`** *(Change Directory)*

- **Usage**: Changes the current working directory.

- **Examples**:

- Change to a specific directory:

```bash

$ cd /var/log

```

- Move up one directory (to the parent directory):

```bash

$ cd ..

```

- Return to the home directory:

```bash

$ cd ~

```

- Return to the previous directory:

```bash

$ cd -

```

3. **`ls`** *(List)*

- **Usage**: Lists files and directories in the current directory.

- **Examples**:

- List all files and directories:

```bash

$ ls

```

- List with detailed information:

```bash

$ ls -l

```

- List all files including hidden ones:

```bash

$ ls -a

```

- List files in a specific directory:

```bash

$ ls /etc

```

4. **`tree`**

- **Usage**: Displays directories and files in a tree-like format.

- **Example**:

```bash

$ tree

```

- *Note*: You may need to install it first using `sudo apt-get install tree`.

5. **`find`**

- **Usage**: Searches for files and directories.

- **Examples**:

- Find a file named `example.txt` in the current directory and subdirectories:

```bash

$ find . -name 'example.txt'

```

- Find directories named `config` starting from the root:

```bash

$ find / -type d -name 'config'

```

- Find files modified in the last 24 hours:

```bash

$ find /home/user -mtime -1

```

6. **`locate`**

- **Usage**: Quickly finds files by name using a database.

- **Example**:

```bash

$ locate '*.pdf'

```

- *Note*: Update the database first with `sudo updatedb`.

7. **`which`**

- **Usage**: Shows the full path of shell commands.

- **Example**:

```bash

$ which python

/usr/bin/python

```

8. **`pushd`** and **`popd`**

- **Usage**: Navigate between directories using a stack.

- **Examples**:

- Save current directory and change to `/usr/local`:

```bash

$ pushd /usr/local

```

- Return to the previous directory:

```bash

$ popd

```

9. **`dirs`**

- **Usage**: Displays the directory stack.

- **Example**:

```bash

$ dirs

```

10. **`history`**

- **Usage**: Displays a list of previously executed commands.

- **Example**:

```bash

$ history

```

11. **`man`** *(Manual)*

- **Usage**: Shows the manual for a command.

- **Example**:

```bash

$ man ls

```

12. **`alias`**

- **Usage**: Creates shortcuts for commands.

- **Example**:

```bash

$ alias ll='ls -la'

```

13. **Tab Completion**

- **Usage**: Use the **Tab** key to auto-complete file and directory names in the shell.

- **Example**:

- Start typing a command or filename and press **Tab**:

```bash

$ cd Docu[TAB]

```

- Auto-completes to:

```bash

$ cd Documents/

```

14. **`echo $PATH`**

- **Usage**: Displays the current `PATH` environment variable.

- **Example**:

```bash

$ echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

```

15. **`touch`**

- **Usage**: Creates an empty file or updates the timestamp of an existing file.

- **Example**:

```bash

$ touch newfile.txt

```

16. **`mkdir`** *(Make Directory)*

- **Usage**: Creates a new directory.

- **Examples**:

- Create a single directory:

```bash

$ mkdir projects

```

- Create nested directories:

```bash

$ mkdir -p projects/2023/october

```

17. **`rmdir`**

- **Usage**: Removes empty directories.

- **Example**:

```bash

$ rmdir old_directory

```

18. **`stat`**

- **Usage**: Displays detailed information about a file or directory.

- **Example**:

```bash

$ stat myfile.txt

```

19. **`df`** *(Disk Free)*

- **Usage**: Reports file system disk space usage.

- **Example**:

```bash

$ df -h

```

20. **`du`** *(Disk Usage)*

- **Usage**: Estimates file space usage.

- **Examples**:

- Show disk usage of current directory:

```bash

$ du -sh .

```

- Show disk usage of all items in current directory:

```bash

$ du -sh *

```

21. **`mount`** and **`umount`**

- **Usage**: Mounts and unmounts filesystems.

- **Examples**:

- Mount a USB drive:

```bash

$ sudo mount /dev/sdb1 /mnt/usb

```

- Unmount the USB drive:

```bash

$ sudo umount /mnt/usb

```

22. **`grep`**

- **Usage**: Searches for patterns within files.

- **Example**:

```bash

$ grep 'search_term' file.txt

```

23. **`less`**

- **Usage**: Views text files one screen at a time.

- **Example**:

```bash

$ less largefile.txt

```

24. **`tail`**

- **Usage**: Displays the last part of files.

- **Example**:

```bash

$ tail -n 20 logfile.txt

```

25. **`head`**

- **Usage**: Displays the first part of files.

- **Example**:

```bash

$ head -n 10 data.csv

```

26. **`findmnt`**

- **Usage**: Displays a list of mounted filesystems.

- **Example**:

```bash

$ findmnt

```

27. **`realpath`**

- **Usage**: Displays the canonicalized absolute pathname.

- **Example**:

```bash

$ realpath ./relative/path

/home/user/relative/path

```

28. **`whereis`**

- **Usage**: Locates the binary, source, and manual page files for a command.

- **Example**:

```bash

$ whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

```

29. **`pwdx`**

- **Usage**: Reports the current working directory of a process.

- **Example**:

```bash

$ pwdx 1234

1234: /home/user/Documents

```

30. **`chdir`**

- **Usage**: Although not a standalone command, it is used in scripts to change the directory.

- **Example in a script**:

```bash

#!/bin/bash

chdir /path/to/directory

```

These commands are essential for navigating and managing the filesystem in Linux. They help users move around directories, view contents, search for files, and manage file and directory structures efficiently.

Navigating the File System

Print Working Directory

The pwd command displays the current working directory.

$ pwd
/home/user

Change Directory

The cd command changes the current directory to the specified path.

$ cd /etc
$ pwd
/etc

Change to the Root Directory

The / command moves you to the root directory

$ /
$ pwd
/


Change Your Home Directory


The / command moves you to the root directory


$ ~


$ pwd


/home/mwstout


List Directory Contents


The ls command lists the contents of a directory.


$ ls


file1.txt file2.txt directory1


Viewing and Editing Files


cat (Concatenate & Display Files)


The cat command displays the contents of a file.


$ cat file1.txt


This is the content of file1.txt.




nano and vi/vim (Text Editors)


nano and vi/vim are text editors used to edit files in the terminal.




$ nano file1.txt


# Opens file1.txt in nano editor




$ vi file1.txt


# Opens file1.txt in vi editor




File Management


cp (Copy Files)


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


$ cp file1.txt /home/user/backup/




mv (Move or Rename Files)


The mv command moves or renames files or directories.




$ mv file1.txt file2.txt


# Renames file1.txt to file2.txt




$ mv file2.txt /home/user/backup/


# Moves file2.txt to /home/user/backup/




rm (Remove Files)


The rm command deletes files.




$ rm file1.txt




rm -r (Remove Directories Recursively)


The rm -r command deletes directories and their contents recursively.




$ rm -r directory1




Disk Usage


df (Disk Free)


The df command displays the amount of free disk space on the file system.




$ df -h


Filesystem      Size  Used Avail Use% Mounted on


/dev/sda1        50G   20G   30G  40% /




du (Disk Usage)


The du command estimates file space usage.




$ du -sh /home/user


2.5G    /home/user




Process Management


ps (Process Status)


The ps command displays information about running processes.




$ ps aux


USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND


root         1  0.0  0.1 225200  9252 ?        Ss   Jul31   0:01 /sbin/init




Network Commands


ip (Show/Manipulate Routing, Devices, Policy Routing, and Tunnels)


The ip command is used to show and manipulate routing, devices, policy routing, and tunnels.




$ ip a




ping -n 9 (Send ICMP ECHO_REQUEST to Network Hosts)


The ping command checks the network connection to a host.


$ ping -c 9 google.com




netstat -an -p tcp (Network Statistics)


The netstat command displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.


$ netstat -an -p tcp




nslookup (Query Internet Name Servers)


The nslookup command queries Internet name servers interactively.




$ nslookup google.com




dig (DNS Lookup)


The dig command is used for querying DNS name servers.


$ dig google.com




Searching and Filtering


find (Search for Files in a Directory Hierarchy)


The find command searches for files in a directory hierarchy.


$ find /home/user -name "*.txt"




grep (Print Lines Matching a Pattern)


The grep command searches text using patterns.


$ grep "search_term" file1.txt




User and Permissions Management


su (Substitute User)


The su command switches to another user account.




$ su - root




sudo (Superuser Do)


The sudo command allows permitted users to execute a command as the superuser.




$ sudo apt-get update




adduser (Add a User to the System)


The adduser command adds a new user to the system.




$ sudo adduser newuser




chmod (Change File Mode Bits)


The chmod command changes the file permissions.




$ chmod 755 script.sh




Permissions Octal


The permissions octal format represents file permissions in numerical form.




$ chmod 644 file1.txt




Escaping Characters


Escaping Characters with \


The backslash (\) is used to escape characters in the shell.


$ echo "This is a \$variable"




Manual Pages


man (Manual)


The man command displays the manual pages for other commands.


$ man ls