Emdadul Islam
Posted on March 3, 2024
In the realm of command-line interfaces, understanding basic commands for file and directory manipulation is a fundamental skill. Whether you're navigating through your file system or creating, modifying, and deleting files and directories, these commands empower users to efficiently manage their digital workspace. In this guide, we'll explore essential command-line commands and create a cheat sheet for quick reference.
Navigation Commands:
-
pwd (Print Working Directory):
- Displays the full path of the current working directory.
pwd
-
ls (List):
- Lists the contents of the current directory.
ls
-
cd (Change Directory):
- Change into an existing directory.
cd directory-name
-
cd .. (Move Backward):
- Move back one directory level (to the parent directory).
cd ..
-
cd directory/sub-directory:
- Change forward through multiple directories.
cd directory/sub-directory
-
cd ../.. (Move Backward Multiple):
- Move backward through multiple directories.
cd ../..
File and Directory Manipulation:
-
mkdir (Make Directory):
- Create a new directory.
mkdir directory-name
-
touch:
- Create a new file.
touch file-name
-
echo "text" > file:
- Overwrite a file with specified text.
echo "text" > file
-
echo "text" >> file:
- Append text to the end of a file.
echo "text" >> file
-
cat file-a > file-b:
- Overwrite content of file-b with content of file-a.
cat file-a > file-b
-
cat file-a >> file-b:
- Append content of file-a to content of file-b.
cat file-a >> file-b
-
mv source-file target-file:
- Move/rename source-file to target-file.
mv source-file target-file
-
mv source-dir target-dir:
- Move/rename source-directory to target-directory.
mv source-dir target-dir
-
rm file:
- Delete a file.
rm file
-
rm -r directory:
- Delete a non-empty directory.
rm -r directory
-
rmdir directory:
- Delete an empty directory.
rmdir directory
-
cp file-a > file-b:
- Copy content of file-a into file-b (overwrite).
cp file-a > file-b
-
cp -r dir-a dir-b:
- Copy content of dir-a into dir-b (overwrite).
cp -r dir-a dir-b
Additional Commands:
-
clear:
- Clear the command line.
clear
Conclusion:
Mastering these basic command-line operations provides a solid foundation for navigating and managing files and directories in a terminal environment. Always exercise caution, double-check your commands, and remember that certain actions, such as deletion, can be irreversible. With this cheat sheet, you're well on your way to becoming proficient in command-line file and directory manipulation. Happy coding!
Posted on March 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.