Command Line Flashcards
pwd
print working directory
It outputs the name of the directory you are currently in, called the working directory.
cd
change directory
changes the working directory (when followed by an argument)
What does ‘cd ..’ do?
moves up one directory
ls
list all files and directories in the working directory
In addition to -a, 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.
mkdir
make a new directory
It takes in a directory name as an argument, and then creates a new directory in the current working directory.
touch
Here we used touch to create a new file named keyboard.txt inside the 2014/dec/ directory.
What is the ‘command line’?
The command line is a text interface for the computer’s operating system. To access the command line, we use the terminal.
filesystem
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.
$
The shell prompt
-a
The -a modifies the behavior of the ls command to also list the files and directories starting with a dot (.). Files started with a dot are hidden, and don’t appear when using ls alone.
The -a is called an option. Options modify the behavior of commands. Here we used ls -a to display the contents of the working directory in more detail.
..
parent directory link
.
current directory link
What does -l list?
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.
-alt
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.
cp
The cp command copies files or directories.
What command do you use to copy a file to a directory?
To copy a file into a directory, use cp with the source file as the first argument and the destination directory as the second argument.
How do you copy multiple files into a directory?
To copy multiple files into a directory, use cp with 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.txt into the historical/ directory.)
Copy all files in a directory
cp * directoryname/
What does * do?
Selects groups of files. Specifically selects all files in the working directory.
cp m*.txt scifi/
selects all files in the working directory starting with “m” and ending with “.txt” and copies them to scifi/
mv
moves files. Similar to “cp” in its usage.
To move a file into a directory, use mv with the source file as the first argument and the destination directory as the second argument.
To rename a file, use mv with the old file as the first argument and the new file as the second argument.
rm
The “rm” command deletes files and directories.