Command Line -- Lesson 1

  • The command line is a text interface for the computer's operating system. To access the command line, we use the terminal.
  • filesystem organizes a computer's files and directories into a tree structure. It starts with the root 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:pwd outputs the name of the current working directory.
  • ls lists all files and directories in the working directory.
  • cd switches you into the directory you specify.
  • mkdir creates a new directory in the working directory.
  • touch creates a new file inside the working directory.

1. Tips of  ls 

The ls command 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.txt

The -l option lists files and directories as a table. Here there are four rows, with seven columns separated by spaces. Here's what each column means:

  1. Access rights. These are actions that are permitted on a file or directory.
  2. 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 (.).
  3. The username of the file's owner. Here the username is cc.
  4. The name of the group that owns the file. Here the group name is eng.
  5. The size of the file in bytes.
  6. The date & time that the file was last modified.
  7. 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.txt

The -t option orders files and directories by the time they were last modified.

In addition to using each option separately, like ls -a or ls -l, multiple options can be used together, like ls -alt.

Here, ls -alt lists all contents, including hidden files and directories, in long format, ordered by the date and time they were last modified.


2. Tips of  cp 

cp * satire/

The wildcards* selects all files in the working directory, so here we use cp to copy all files into the satire/ directory.

cp m*.txt scifi/

Here, m*.txt selects all files in the working directory starting with "m" and ending with ".txt", and copies them to scifi/.


3. Tips of  rm 

rm -r comedy

The -r is an option that modifies the behavior of the rm command. 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.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值