codecademy-command line_filesystem
$:shell prompt (命令提示符)
- In the terminal, first you see
$. This is called a shell prompt. It appears when the terminal is ready to accept a command. - When you type
ls, the command line looks at the folder you are in, and then "lists" the files and folders inside it. The directories 2014, 2015, and the file hardware.txt are the contents of the current directory $ pwd
/home/ccuser/workspace/blogpwdstands for "print working directory". It outputs the name of the directory you are currently in, called theworking directory.Here the working directory is blog/. In Codecademy courses, your working directory is usually inside thehome/ccuser/workspace/ directory.
Together with
ls, thepwdcommand is useful to show where you are in the filesystem.$ cd 2015
cdstands for "change directory". Just as you would click on a folder in Windows Explorer or Finder,cdswitches you into the directory you specify. In other words,cdchanges the working directory.- The directory we change into is
2015. When a file, directory or program is passed into a command, it is called an argument. Here the 2015 directory is an argument for thecdcomman$ cd jan/memory
To navigate directly to a directory, use
cdwith the directory's path as an argument. Here,cd jan/memory/command navigates directly to the jan/memorydirectory.$ cd ..
To move up one directory, use
cd ... Here,cd ..navigates up from jan/memory/ to jan/. $ mkdir media
The
mkdircommand 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
mkdirto create a new directory namedmedia/ inside the feb/ directory.touch keyboard.txt
The
touchcommand creates a new file inside the working directory. It takes in a filename as an argument, and then creates an empty file in the current working directory.Here we used
touchto create a new file namedkeyboard.txt inside the 2014/dec/ directory.Congratulations! You've learned five commands commonly used to navigate the filesystem from the command line. What can we generalize so far?
- The command line is a text interface for the computer's operating system. To access the command line, we use the terminal.
- A filesystem organizes a computer's files and directories into a tree structure. It starts with theroot directory. Each parent directory can contain more child directories and files.
- From the command line, you can navigate through files and folders on your computer:
pwdoutputs the name of the current working directory.lslists all files and directories in the working directory.cdswitches you into the directory you specify.mkdircreates a new directory in the working directory.touchcreates a new file inside the working directory.$ ls -a
. .. .preferences action drama comedy genres.xt- The
lscommand lists all files and directories in the working directory. - The
-amodifies the behavior of thelscommand to also list the files and directories starting with a dot (.). Files started with a dot are hidden, and don't appear when usinglsalone.
The
-ais called an option. Options modify the behavior of commands. Here we usedls -ato display the contents of the working directory in more detail.In addition to
-a, thelscommand has several more options. Here are three common options:-a- lists all contents, including hidden files and directories-l- lists all contents of a directory in long format-t- order files and directories by the time they were last modified.$ ls -l
drwxr-xr-x 5 cc eng 4096 Jun 24 16:51 action
drwxr-xr-x 4 cc eng 4096 Jun 24 16:51 comedy
drwxr-xr-x 6 cc eng 4096 Jun 24 16:51 drama
-rw-r--r-- 1 cc eng 0 Jun 24 16:51 genres.txtThe
-loption lists files and directories as a table. Here there are four rows, with seven columns separated by spaces. Here's what each column means:- Access rights. These are actions that are permitted on a file or directory.
- Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link (
..) and current directory link (.). - The username of the file's owner. Here the username is
cc. - The name of the group that owns the file. Here the group name is
eng. - The size of the file in bytes.
- The date & time that the file was last modified.
- The name of the file or directory.
$ ls -alt
drwxr-xr-x 4 cc eng 4096 Jun 29 12:22 .
-rw-r--r-- 1 cc eng 0 Jun 29 12:22 .gitignore
drwxr-xr-x 5 cc eng 4096 Jun 30 14:20 ..
drwxr-xr-x 2 cc eng 4096 Jun 29 12:22 satire
drwxr-xr-x 2 cc eng 4096 Jun 29 12:22 slapstick
-rw-r--r-- 1 cc eng 14 Jun 29 12:22 the-office.txtThe
-toption orders files and directories by the time they were last modified.In addition to using each option separately, like
ls -aorls -l, multiple options can be used together, likels -alt.Here,
ls -altlists all contents, including hidden files and directories, in long format, ordered by the date and time they were last modified.cp frida.txt lincoln.txt
The
cpcommand copies files or directories. Here, we copy the contents of frida.txt into lincoln.txt.cp biopic/cleopatra.txt historical/
To copy a file into a directory, use
cpwith the source file as the first argument and the destination directory as the second argument. Here, we copy the filebiopic/cleopatra.txt and place it in the historical/directory.cp biopic/ray.txt biopic/notorious.txt historical/
To copy multiple files into a directory, use
cpwith a list of source files as the first arguments, and the destination directory as the last argument. Here, we copy the files biopic/ray.txt and biopic/notorious.txtinto the historical/ directory.cp * satire/
In addition to using filenames as arguments, we can use special characters like
*to select groups of files. These special characters are called wildcards. The*selects all files in the working directory, so here we usecpto copy all files into the satire/ directory.cp m*.txt scifi/
Here,
m*.txtselects all files in the working directory starting with "m" and ending with ".txt", and copies them to scifi/.The
mvcommand moves files. It's similar tocpin its usage.mv superman.txt superhero/
To move a file into a directory, use
mvwith the source file as the first argument and the destination directory as the second argument. Here we move superman.txtinto superhero/.mv wonderwoman.txt batman.txt superhero/
To move multiple files into a directory, use
mvwith a list of source files as the first arguments, and the destination directory as the last argument. Here, we move wonderwoman.txt and batman.txt intosuperhero/.mv batman.txt spiderman.txt
rm waterboy.txt
The
rmcommand deletes files and directories. Here we remove the file waterboy.txt from the filesystem.rm -r comedy
The
-ris an option that modifies the behavior of thermcommand. The-rstands for "recursive," and it's used to delete a directory and all of its child directories.Be careful when you use
rm! It deletes files and directories permanently. There isn't an undelete command, so once you delete a file or directory withrm, it's gone.Congratulations! You learned how to use the command line to view and manipulate the filesystem. What can we generalize so far?
- Options modify the behavior of commands:
ls -alists all contents of a directory, including hidden files and directoriesls -llists all contents in long formatls -torders files and directories by the time they were last modified- Multiple options can be used together, like
ls -alt
- From the command line, you can also copy, move, and remove files and directories:
cpcopies filesmvmoves and renames filesrmremoves filesrm -rremoves directories
- Wildcards are useful for selecting groups of files and directories
- Options modify the behavior of commands:
- The
codecademy-command line_filesystem的更多相关文章
- Linux Command Line learning
https://www.codecademy.com/en/courses/learn-the-command-line Background The command line is a text i ...
- ifconfig: command not found(CentOS专版,其他的可以参考)
ifconfig: command not found 查看path配置(echo相当于c中的printf,C#中的Console.WriteLine) echo $PATH 解决方案1:先看看是不是 ...
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- ENode框架单台机器在处理Command时的设计思路
设计目标 尽量快的处理命令和事件,保证吞吐量: 处理完一个命令后不需要等待命令产生的事件持久化完成就能处理下一个命令,从而保证领域内的业务逻辑处理不依赖于持久化IO,实现真正的in-memory: 保 ...
- 设计模式(六):控制台中的“命令模式”(Command Pattern)
今天的博客中就来系统的整理一下“命令模式”.说到命令模式,我就想起了控制台(Console)中的命令.无论是Windows操作系统(cmd.exe)还是Linux操作系统(命令行式shell(Comm ...
- GET command找不到
谷歌的: On running a cronjob with get command, I was getting the following error. /bin/sh: GET: command ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
- Webform(七)——内置对象(Session、Application)和Repeater的Command操作
内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...
- MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL
MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL 是因为目标板的芯片处于休眠 ...
随机推荐
- C#设计模式 - 观察者模式(使用委托)
1.概念 观察者模式(有时又被称为发布-订阅Subscribe>模式.模型-视图View>模式.源-收听者Listener>模式或从属者模式)是软件设计模式的一种.在此种模式中,一个 ...
- 新浪微博客户端(50)-解决输入Emotion表情逐渐变小的问题
UITextView+Extension.h #import <UIKit/UIKit.h> @interface UITextView (Extension) /** 插入属性文本 */ ...
- 我再也不-或许永远不-用zend studio-受够了!
zend studio背负的东西太多, 想要整合php, js, aptana, emmet, 还要git, 所以显得很累. 不过把这些它整合的东西 都用上后, 用好后, 倒确实是php的开发利器. ...
- LINUX 命令行编辑快捷键
转自:http://www.cnblogs.com/edwardlost/archive/2012/07/27/2611536.html 删除 ctrl + d 删除光标所在位置上的字符相当于VIM里 ...
- 在windows7 上安装 Sublime Text 3 及其插件
1.下载地址:http://www.sublimetext.com/3 请根据你的平台,选择适当的安装版本 安装完毕后,设定TAB键为4个空格( Preferences——>Setings-Us ...
- 避免重定向301&302 (Avoid Redirects)
这个也是Best Practices for Speeding Up Your Web Site的第12条原则: 重定向的意思是,用户的原始请求(例如请求A)被重定向到其他的请求(例如请求B).这是H ...
- Express开发实例(1) —— Hello,world!
Express是NodeJs开发中最常用的基础模块.NodeJs本身有Http模块,但是易用性并不好,因此有人在此基础上开发了Express模块. 什么是express express提供了丰富的路由 ...
- .NET之委托
有些.NET中的高级特性,比如:委托! 有一种怎么也搞不懂的赶脚... 博客读了好几篇,代码也动手写了,书中的一些介绍也看了, 各种搜索关于委托的,至今还处于"会用"的阶段. 该怎 ...
- ASP 编码转换(乱码问题解决)
ASP 编码转换(乱码问题解决) 输出前先调用Conversion函数进行编码转换,可以解决乱码问题. 注,“&参数&”为ASP的连接符,这里面很多是直接调用的数据库表字段,实际使用请 ...
- notepad++和sublime 常用插件及主题
sublime: 常用主题有: Pastels on Dark Monokai Zenburnsque 常用插件有 Anaconda Package Control Side Bar ConvertT ...