Skip to content

06Basicmd

Basic Commands in Linuxβš“οΈŽ

Linux commands are the fundamental building blocks for interacting with the operating system through the terminal. They allow users to navigate directories, manage files, and perform system operations efficiently.


1. pwd β€” Print Working Directoryβš“οΈŽ

Displays the current directory path where the user is located.

Syntax:

pwd

Example Output:

/home/cyberadmin/Documents

2. ls β€” List Directory Contentsβš“οΈŽ

Lists files and directories in the current or specified directory.

Syntax:

ls [options] [directory]

Common Options:

  • -l β†’ Long format listing (shows permissions, owner, size, etc.)
  • -a β†’ Shows hidden files (files starting with .)
  • -h β†’ Displays sizes in human-readable format

Example:

ls -lah /home/cyberadmin

3. cd β€” Change Directoryβš“οΈŽ

Moves between directories.

Syntax:

cd [directory_path]

Examples:

cd /home/cyberadmin/Documents
cd ..        # Move one level up
cd ~         # Go to the home directory

4. mkdir β€” Make Directoryβš“οΈŽ

Creates new directories.

Syntax:

mkdir [directory_name]

Example:

mkdir projects

To create nested directories:

mkdir -p projects/python/scripts

5. rmdir β€” Remove Empty Directoryβš“οΈŽ

Deletes an empty directory.

Syntax:

rmdir [directory_name]

Example:

rmdir old_folder

For non-empty directories, use rm -r.


6. touch β€” Create Empty Files or Update Timestampsβš“οΈŽ

Creates a new empty file or updates an existing file’s modification date.

Syntax:

touch [file_name]

Example:

touch report.txt

7. cp β€” Copy Files or Directoriesβš“οΈŽ

Copies files or directories from one location to another.

Syntax:

cp [options] source destination

Common Options:

  • -r β†’ Recursively copy directories
  • -v β†’ Verbose mode (shows progress)

Example:

cp file.txt /home/cyberadmin/backup/
cp -rv project/ /home/cyberadmin/backup/

8. mv β€” Move or Rename Filesβš“οΈŽ

Moves files to another location or renames them.

Syntax:

mv [source] [destination]

Examples:

mv file.txt /home/cyberadmin/Documents/
mv oldname.txt newname.txt

9. rm β€” Remove Files or Directoriesβš“οΈŽ

Deletes files or directories permanently.

Syntax:

rm [options] [file_name]

Common Options:

  • -r β†’ Remove directories and their contents recursively
  • -f β†’ Force removal (no prompt)
  • -v β†’ Verbose mode

Examples:

rm oldfile.txt
rm -rf temp_folder/