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/