The command line, or terminal, is a text-based interface in which users interact with a computer by typing commands. It’s a powerful tool for performing various tasks, file management, and system administration. Here are some basic command line operations:
Navigation:
pwd
(Print Working Directory):
- Displays the current working directory (the directory you are currently in).
pwd
ls
(List):
- Lists the contents of the current directory.
ls
cd
(Change Directory):
- Changes the current working directory.
cd path/to/directory
mkdir
(Make Directory):
- Creates a new directory.
mkdir new_directory
cp
(Copy):
- Copies files or directories.
cp source_file destination
mv
(Move):
- Moves files or directories. It can also be used for renaming.
mv old_name new_name
rm
(Remove):
- Deletes files or directories. Use with caution.
rm file_name
File and Text Manipulation:
touch
(Create Empty File):
- Creates an empty file or updates the access and modification time of a file.
touch filename
nano
orvim
(Text Editors):
- Opens a text editor for creating or editing files.
nano filename
- To exit
nano
, pressCtrl + X
, then follow the prompts to save changes.
cat
(Concatenate and Display):- Displays the content of a file.
cat filename
echo
(Print to the Screen):- Prints text to the terminal.
echo "Hello, World!"
System Information:
whoami
(Show Current User):- Displays the username of the currently logged-in user.
whoami
date
(Display Date and Time):- Shows the current date and time.
date
cal
(Display Calendar):- Displays a calendar for the current month.
cal
Redirection and Pipes:
>
(Output Redirection):- Redirects the output of a command to a file, overwriting the file’s contents.
command > file
>>
(Append Output):- Redirects the output of a command to a file, appending to the file.
command >> file
|
(Pipe):- Takes the output of one command and uses it as input for another.
command1 | command2
Help and Manual:
man
(Manual):- Displays the manual (help) for a command.
man command
--help
(Command Help):- Displays help information for a command.
command --help
Miscellaneous:
history
(Command History):- Displays a list of previously executed commands.
history
clear
(Clear Screen):- Clears the terminal screen.
clear
chmod
(Change Permissions):- Changes the permissions of a file or directory.
chmod permissions file
These are just a few basic command line operations. The command line provides a powerful and efficient way to interact with a computer, especially for tasks related to file management, system administration, and development. As you become more familiar with the command line, you’ll discover additional commands and options to enhance your productivity.