Introduction to Command Line
What is the command Line?
The command line is a text interface for the computer's operating system.You can use it to traverse and edit your computer's filesystem.Though the command line, you can create new files, edit the contents of those files.delete files.and more.
On Mac and Linux systems, we access the command line through something called bash.
- Navigation
- Manipulation
- Redirection
- Configuration
Introduction
The command line is a text interface for your computer.It's a program that takes in commands and passes them on to the computer's operating system to run.
The advantage of using the command line is its power.You can run programs, write scripts to automate common tasks, and combine simple commands to handle difficult tasks.All of these traits come together to make it an important programming tool.
Filesystem
A filesystem organizes a computer’s files and directories into a tree structure:
- he first directory in the filesystem is the root directory. It is the parent of all other directories and files in the filesystem.
- Each parent directory can contain more child directories and files.
- Each directory can contain more files and child directories. The parent-child relationship continues as long as directories and files are nested.
ls
The first command we’re going to look at is ls
. A command is a directive to the computer to perform a specific task. When you type ls
, the command line looks at the directory you are in, and then “lists” all the files and directories inside of it. Be sure to type the letter l
as in “List” and not the number 1.
In the terminal, the first thing you see is $
. This is called a shell prompt. It appears when the terminal is ready to accept a command.
pwd
The next command we’re going to look at is pwd
, which stands for “print working directory.” It outputs the name of the directory you are currently in, called the working directory.
Together with ls
, the pwd
command is useful to show where you are in the filesystem.
cd I
Our next command is cd
, which stands for “change directory.” Just as you would click on a folder in Windows Explorer or Finder, cd
switches you into the directory you specify. In other words, cd
changes the working directory.
cd II
Instead of using cd
twice in order to move from 2015 to memory, we can use it once and give it a longer argument:
$ cd jan/memory
To navigate directly to a directory, use cd
with the directory’s path as an argument. Here, cd jan/memory
navigates directly to the memory directory.
To move up one directory, we use cd ..
:
$ cd ..
Here, cd ..
navigates up from jan/memory/ to jan/.
mkdir
Now that we can traverse the existing filesystem, let’s try editing it by making directories (folders) through the command line. The command for that is mkdir
:
$ mkdir media
The mkdir
command stands for “make directory”. It takes in a directory name as an argument and then creates a new directory in the current working directory.
Here we used mkdir
to create a new directory named media/ inside our working directory.
touch
Now we know how to create directories through the command line, but how do we create new files?
We can do this using the command touch
:
$ touch keyboard.txt
The touch
command creates a new file inside the working directory. It takes in a filename as an argument and then creates an empty file with that name in the current working directory.
Here we used touch
to create a new file named keyboard.txt.
Helper Commands
Now that we’ve covered the basics of navigating your filesystem from the command line, let’s look at some helpful commands that will make using it easier!
clear
is used to clear your terminal, which is useful when it’s full of previous commands and outputs. It doesn’t change or undo your previous commands, it just clears them from the view. You can scroll upwards to see them at any time.
tab can be used to autocomplete your command. When you are typing the name of an existing file or directory, you can use tab to finish the rest of the name.
The up and down arrows (↑ and ↓) can be used to cycle through your previous commands. ↑ will take you up through your most recent commands, and ↓ will take you back through to the most recent one.
相关文章
- Request To JavaBean(请求对象转换为JavaBean对象)
- 解决: Got permission denied while trying to connect to the Docker daemon socket
- [Typescript] Using Generic Context to Avoid Distributivity in Conditional Types
- [Tools] Deploy a Monorepo to Now V2
- [Nuxt] Use Vuex Actions to Delete Data from APIs in Nuxt and Vue.js
- [AngularJS] Using angular.bootstrap to Initialize Your App
- [Tools] Using z to jump to "frecent" folders - Command Line Power User
- python paramiko ssh.exec_command()启动tomcat服务器应用进程失败问题解决方法- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this progr
- 【Codeforces 231C】To Add or Not to Add
- How to Use Command to Execute Git Push with Review from Sean
- 成功解决To fix this you could try to: 1. loosen the range of package versions you‘ve specified
- 成功解决absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a str
- chromium electron 编译出现 clang 错误 clang++: error: unable to execute command: Killed
- wget命令出现Unable to establish SSL connection.错误
- 解决nvidia-docker 问题 nvidia-docker | Error: failed to run docker command
- 解决办法:nohup: failed to run command ‘java‘: No such file or directory
- MacOS,安装Wireshark后,运行提示:You don‘t have permission to capture on local interfaces.
- 解决办法:nohup: failed to run command ‘java‘: No such file or directory