Week 2 - Command Line Flashcards
What is the top-level directory?
The ‘root’ directory, indicated with ‘/’.
What is an absolute path?
A path that starts from the root directory (/) and specifies the exact
location of a file or directory
▪ Example: Command: cd /etc/passwd
What is a relative path?
A path that starts from your current working directory and
specifies the location of a file or directory relative to it
▪ Current Directory: /home/user → Command: cd Downloads
What is a command option?
Options Overview: Predefined values that modify the behavior of a command. Typically, single characters after a hyphen (-) or words after two hyphens (–). Some newer commands accept word options → Example: ls –long
What is a command argument?
Arguments:
▪ Parameters that follow the command to specify targets or options
▪ Example: cd /bin
What are multiple commands?
Multiple Commands:
▪ Separate commands with semicolons (;) and press Enter after the last command
▪ Example: pwd ; date ; ls
cd
Change directory:
cd . - Stays in the current directory.
cd.. - Moves up one level.
cd ~
Returns to the home directory.
file
Outputs the type of content in the file. Example: ASCII text
cat
Output the contents of a file.
To navigate to the Downloads directory, which is inside your home directory,
what would you type?
cd ~/Downloads
ls -l
list the files in the working directory in long format.
ls /bin
List the files in the /bin directory. (Can be used for other directories.)
ls -a
List all files, including hidden files.
ls -r
Reverse the output order of the string.
ls -S
Sort by file size.
ls -r
Sort by modification time. (Newest first)
ls -d D*
Lists all directories that begin with the letter D. Without (-d) it would also display all the contents within that directory.
What are the 3 file types shown with the ls.
(-) plain file, (d) directory, (l) symbolic link
What is a hard link?
They are directory entries that reference the exact same underlying data. The data in a file is specified by its inode. Each file on a file system points to an inode but there’s no requirement that each file point to a unique inode. The where hard link reference counts come from the inode.
File Globbing
Using wildcards to match filenames based on patterns.
What does ls -d ????? do?
Lists all files in the current directory that are exactly five characters long.
What does ls * do?
Lists all files and folders including subdirectories.
What does this command do?
mv file1.txt file2.txt
Uses the move command to rename a file. If file2 does not exist, file1 is renamed to file2. If file2 exists, it is overwritten with the contents of file1.
What does this command do?
mv file1 file2 dir1/
Moves file1 and file2 into dir1. If dir1 does not exist, an error occurs
Explain:
mv dir1 dir2
If dir2 does not exist, dir1 is renamed to dir2. If dir2 exists, dir1 is moved into dir2 as a subdirectory.