11 Command Line Commands to Master
If you are working in any software or data job you are going to need to learn how to use the command line to do things like version control, working with scripting, moving files, and more.
I was always scared of the command line because it can look like a black box (figuratively, although it literally is a black box haha). The more you use it will open up your understanding and your ability to work with it.
Let’s look at the top 11 commands you need to master for the command line.
1. Display Current Directory
Windows:
cd
(with no arguments)Mac/Linux:
pwd
Description: Shows the current directory you're in.
Knowing your current directory is fundamental when navigating the file system via the command line. On Windows, typing cd
without any arguments will display your current directory. On Mac or Linux, pwd
(print working directory) will show you where you are in the file system hierarchy.
2. Change Directory
Windows:
cd [directory]
Mac/Linux:
cd [directory]
Description: Navigates to the specified directory.
To move to a different directory, use the cd
command followed by the path of the directory you want to access. Replace [directory]
with the name or path of the directory.
3. List Directory Contents
Windows:
dir
Mac/Linux:
ls
Description: Lists files and folders in the current directory.
Viewing the contents of your current directory helps you see what files and subdirectories are available. On Windows, use dir
, and on Mac/Linux, use ls
to list the directory contents.
4. Create a Directory
Windows:
mkdir [directory_name]
Mac/Linux:
mkdir [directory_name]
Description: Creates a new directory with the specified name.
Organize your files by creating new directories. Replace [directory_name]
with the desired name of your new directory.
5. Remove a Directory
Windows:
rmdir [directory_name]
Mac/Linux:
rmdir [directory_name]
Description: Removes the specified directory (directory must be empty).
To delete an empty directory, use rmdir
followed by the directory's name. Be cautious when removing directories to avoid deleting important data.
6. Create a New File
Windows:
echo.> filename.txt
Mac/Linux:
touch filename.txt
Description: Creates a new, empty file with the specified name.
Quickly create a new file without opening a text editor. On Windows, echo.> filename.txt
will create a new file named filename.txt
. On Mac/Linux, touch filename.txt
accomplishes the same.
7. Copy Files
Windows:
copy [source] [destination]
Mac/Linux:
cp [source] [destination]
Description: Copies files from one location to another.
Duplicate files by copying them from the source location to the destination. Replace [source]
with the path of the file you want to copy and [destination]
with the path where you want the copy to be placed.
8. Move or Rename Files
Windows:
move [source] [destination]
Mac/Linux:
mv [source] [destination]
Description: Moves or renames files and directories.
To move a file or directory to a new location or to rename it, use the move
command on Windows or mv
on Mac/Linux. Specify the current name or path in [source]
and the new name or destination path in [destination]
.
9. Delete Files
Windows:
del [filename]
Mac/Linux:
rm [filename]
Description: Deletes files.
Remove files you no longer need by using del
on Windows or rm
on Mac/Linux, followed by the filename.
10. View File Contents
Windows:
type [filename]
Mac/Linux:
cat [filename]
Description: Displays the contents of a file.
Read the contents of a text file directly in the command line. Use type filename.txt
on Windows or cat filename.txt
on Mac/Linux.
11. Clear the Screen
Windows:
cls
Mac/Linux:
clear
Description: Clears the terminal or command prompt screen.
Clean up your command line interface by clearing previous commands and outputs. Simply type cls
on Windows or clear
on Mac/Linux.
Mastering these basic command line commands empowers you to navigate and manage your computer's file system more effectively. The command line can perform tasks more quickly than a graphical interface once you become familiar with its operations.
Couple more tips:
Practice regularly: Consistent use of the command line will increase your comfort and proficiency.
Explore command options: Many commands offer additional options and flags for more advanced functionality. Use
command /?
on Windows orman command
on Mac/Linux to learn more.