- 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 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:
- 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.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 -r
stands 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.