DEV Community

Lucas Lomeu
Lucas Lomeu

Posted on • Edited on

Linux Basics: Essential Terminal Commands

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
Enter fullscreen mode Exit fullscreen mode

Example:

ls -a -l -h -R
Enter fullscreen mode Exit fullscreen mode

Change Directory

The cd command is used to navigate between directories.

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

Example:

cd [path]
Enter fullscreen mode Exit fullscreen mode

To go back one directory:

cd ..
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

Make Directory

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

Example:

mkdir [path]
Enter fullscreen mode Exit fullscreen mode

Remove Directory

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

Example:

rmdir [path]
Enter fullscreen mode Exit fullscreen mode

Empty File

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

Example:

touch [file]
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

or:

vi [file]
Enter fullscreen mode Exit fullscreen mode

Superuser

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

Example:

sudo [command]
Enter fullscreen mode Exit fullscreen mode

Clear

The clear command clears the terminal screen.

Example:

clear
Enter fullscreen mode Exit fullscreen mode

Top comments (0)