← Home

Linux Basics: Essential Terminal Commands

Linux Terminal Commands Listing The ls command is used to list files and...

On this page

Linux Terminal Commands

Listing

The ls command is used to list files and directories. Here are some common options:

  • -a or —all: Lists all files, including hidden files.
  • -l: Displays additional information about files and directories.
  • -h: Formats file sizes in a human-readable format.
  • -R: Lists directories and their contents recursively.
ls [path] -a -l -h -R

Example:

ls -a -l -h -R

Change Directory

The cd command is used to navigate between directories.

To go back to the parent directory, use ...

Example:

cd [path]

To go back one directory:

cd ..

Copy

The cp command is used to copy files or directories to another location. The -r option is used to copy directories and their contents recursively.

Example:

cp -r [source] [destination]

Move

The mv command is used to move files or directories to another location. It can also be used to rename files and directories.

Example:

mv [source] [destination]

Remove

The rm command is used to remove files or directories. The -r option removes directories and their contents recursively, while -f forces the operation without prompting for confirmation.

Use this command carefully, especially when using -r and -f.

Example:

rm -rf [path or file]

Make Directory

The mkdir command creates a new directory. You can provide either the full path or just the directory name.

Example:

mkdir [path]

Remove Directory

The rmdir command removes an empty directory. You can provide either the full path or just the directory name.

Example:

rmdir [path]

Empty File

The touch command can be used to create an empty file with the specified name.

Example:

touch [file]

Text Editor

You can open and edit text files directly from the terminal using a text editor such as nano or vi.

Example:

nano [file]

or:

vi [file]

Superuser

The sudo command is used to execute commands with elevated privileges.

Example:

sudo [command]

Clear

The clear command clears the terminal screen.

Example:

clear