Hereβs a clear explanation of basic Linux commands with examples for each:
1. ls
(List Directory Contents)
Purpose: Lists files and directories in the current folder.
Common Options:
ls -l
β Detailed list (permissions, owner, size, date)ls -a
β Shows hidden files (starting with.
)ls -h
β Human-readable file sizes (KB, MB)
Example:
ls -lah # Lists all files (including hidden) in detailed, readable format
2. cd
(Change Directory)
Purpose: Moves you into a different directory.
Common Usage:
cd /path/to/folder
β Absolute pathcd folder_name
β Relative pathcd ..
β Go up one levelcd ~
orcd
β Go to home directory
Example:
cd Documents/Projects # Enters the "Projects" folder inside "Documents"
3. mkdir
(Make Directory)
Purpose: Creates a new directory (folder).
Common Options:
mkdir -p parent/child
β Creates nested directories at once.
Example:
mkdir new_folder # Creates "new_folder"
mkdir -p dir1/dir2 # Creates "dir1" and "dir2" inside it
4. rm
(Remove Files/Directories)
Purpose: Deletes files or directories.
Common Options:
rm file.txt
β Deletes a file.rm -r folder/
β Deletes a directory recursively (use with caution!).rm -f
β Forces deletion (no confirmation).
Example:
rm old_file.txt # Deletes "old_file.txt"
rm -r old_folder/ # Deletes "old_folder" and its contents
5. cp
(Copy Files/Directories)
Purpose: Copies files or directories.
Common Options:
cp file.txt new_location/
β Copies a file.cp -r folder/ backup/
β Copies a directory recursively.
Example:
cp notes.txt ~/Backups/ # Copies "notes.txt" to the "Backups" folder
cp -r project/ backup/ # Copies the entire "project" folder
6. mv
(Move/Rename Files/Directories)
Purpose: Moves files/directories or renames them.
Common Usage:
mv file.txt new_name.txt
β Renames a file.mv file.txt /target/path/
β Moves a file.
Example:
mv old.txt new.txt # Renames "old.txt" to "new.txt"
mv file.txt ~/Documents/ # Moves "file.txt" to "Documents"