
- 2025-02-28
- posted by Kyaw Soe Naing
- Design
Essential Terminal Commands for Developers
Hello everyone!
My name is Kyaw Soe Naing and I’m currently working as a Web Designer at WIT Lab Company. This week, I’ll be guiding you through the fundamentals of using the command line effectively.
As a developer, the command line (or terminal) is a powerful tool that allows you to interact with your system efficiently. It helps you navigate directories, manage files, and automate tasks—saving time and improving productivity. Mastering the command line can significantly enhance your workflow and make you a more efficient developer.
1. Navigation and Directory Management
When working in a project, you often need to move between directories, check where you are, and list files.
. Check Your Current Directory
pwd
pwd (Print Working Directory) – This command displays the full path of the directory you’re currently in. It's useful when you're lost and need to know your location in the file system.
. List Files and Directories
ls # Show all files ls -a # Show all files, including hidden ones (files starting with ".") ls -l # Show a detailed list (permissions, owner, size, date modified) ls -lh # Display file sizes in human-readable format (KB, MB, GB) ls -la # Show all files with details (combining -a and -l) ls -lt # Sort files by modification time (newest first)
ls (List) – This command shows the files and directories in your current location. It helps you see what’s inside a directory.
. Change Directories
cd folder_name # Move into a folder cd .. # Move up one level (to the parent directory) cd - # Switch to the last directory you were in
cd (Change Directory) – This command allows you to move between directories. If you ever need to go back, use cd - to return to your last directory.
2. File and Directory Manipulation
Creating, copying, moving, and deleting files and directories is a crucial part of development.
. Create a New Directory
mkdir my_folder # Create a single directory mkdir folder1 folder2 folder3 # Create multiple directories mkdir "My Folder" # Create a directory with spaces in the name
mkdir (Make Directory) – Use this command to create folders where you can organize your files. If a directory name contains spaces, enclose it in quotes.
. Create Empty Files
touch newfile.txt # Create a single empty file touch file1.txt file2.txt file3.txt # Create multiple empty files
touch – This command is mainly used to create new empty files or update the last modified time of an existing file.
. Copy Files and Directories
cp file1.txt backup.txt # Copy a file cp file1.txt /home/user/Documents/ # Copy a file to another directory
cp (Copy) – This command duplicates a file or directory. It's useful for creating backups or duplicating files to work on different versions.
. Move and Rename Files
mv file1.txt /home/user/Documents/ # Move a file to another directory mv oldname.txt newname.txt # Rename a file
mv (Move) – This command is used to move files or directories from one location to another. If you use it with just a filename, it acts as a rename command.
. Delete Files and Directories
rm file1.txt # Delete a single file rm -r my_folder # Delete a directory and its contents rm -i file1.txt # Ask for confirmation before deleting a file
rm (Remove) – Deletes files and directories. Be careful when using rm -r
, as it will permanently delete a directory and everything inside it.
3. File Viewing and Editing
Often, developers need to open, read, or modify files directly in the terminal.
. Edit Files Using nano
nano myfile.txt
nano – A simple text editor that allows you to create and modify files inside the terminal. It’s useful for quick edits without opening a full GUI-based editor.
. View File Content
cat newfile.txt
cat (Concatenate) – This command displays the content of a file. It’s useful for quickly viewing small files without opening them in an editor.
. Combine Multiple Files into One
cat file1.txt file2.txt > merged.txt
cat with >
(Redirect Output) – This command merges the contents of file1.txt
and file2.txt
into a new file called merged.txt
.
. Write and Append Text to Files
echo "Hello World" > newfile.txt # Overwrites file content with "Hello World" echo "New Line" >> newfile.txt # Appends "New Line" to the existing file
echo – Outputs text to the terminal or a file. Using >
overwrites the file, while >>
appends to the file.
Mastering these terminal commands will help you navigate, manage, and edit files efficiently. Whether you're developing web applications, working with servers, or managing your local projects, using the terminal can significantly speed up your workflow.
If you found this guide helpful, stay tuned for more tips and insights into web development and design!