Linux commands Flashcards

1
Q

You’re logged into a shared server and want to see who else is currently using the system, what they’re doing, and how long they’ve been idle. What command do you use?

A

w

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

You need to review every command you’ve entered so far in this shell session to figure out what went wrong. Which command shows you this?

A

history

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Your terminal is full of clutter from old outputs, and you want to start fresh visually without closing the terminal window. What command do you run?

A

clear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’re unsure which user you’re currently logged in as—especially important if you recently used su or sudo. What command tells you the active username?

A

whoami

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A user has just been added to the system and logs in for the first time. They’re required to set a new password for their account. What command should they use?

A

passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’ve temporarily switched users using su and now want to return to your previous shell session without closing the terminal. What keystroke do you use?

A

Ctrl+D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’re browsing through a messy folder and need a neat list that shows file permissions, ownership, size, and modification date for each item. Which command do you use?

A

ls -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You want to check what’s inside a directory but see so many files you’d rather view them in reverse alphabetical order. Which option helps you do that?

A

ls -r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’re checking file sizes in a directory and want them displayed in a human-readable format like KB, MB, etc., instead of raw bytes. What option do you use with the listing command?

A

ls -h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You’re typing a series of related commands and want to reuse a previous one quickly without retyping it. What key helps you scroll through your recent command history?

A

Up arrow (⬆️ key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You want to rerun the command you entered three commands ago, without looking it up. What shortcut lets you do that?

A

!-3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You typed a useful command earlier, and it was the third command in your session. You want to run it again without retyping it. What syntax lets you do that instantly?

A

!3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You just ran a command with a typo and want to rerun the exact previous command again immediately. What shortcut does that?

A

!!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You only want to view the last 3 commands you ran, not your full history. What command shows just those three?

A

history 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You ran a file listing command earlier and now want to repeat it, but can’t remember its position in the history. What shortcut lets you rerun the most recent use of that specific command?

A

!ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You want to create a simple variable named variable1 with the value Good Morning for use later in the session. What assignment syntax should you use?

A

variable1=”Good Morning”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You’ve defined a variable (variable1) and now want to print its value to the terminal to verify it. What command do you use?

A

echo $variable1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You’re trying to view a list of all environment variables currently available in your session, including user, path, shell, and more. What command shows the full list?

A

env

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You want to find out how many previous commands your shell is storing in memory. Which env variable holds that setting?

A

echo $HISTSIZE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You’ve just created two shell variables, value1=Hi and value2=there, and want them to be available to all child processes. What command makes both variables part of the environment?

A

export value1 value2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

value1=Hi
value2=there
After setting two variables, you want to combine their values into a single variable that holds the phrase “Hi there”. What is the correct syntax to do this while preserving the space between words?

A

value1=”$value1 $value2”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You want to confirm whether a variable named HOME exists in your environment and see its exact value. What command should you run?

A

env | grep HOME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You want to quickly view only the first five environment variables in your session just to get a general idea. Instead of viewing everything with env, what command would you use to show only the top portion of the list?

A

env | head -n 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You created an alias called ll for a custom ls -l output a while ago, and now you want to confirm if it’s still active in your session. What command lets you check what this alias currently points to?

A

type ll

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
You've already assigned a value to a variable and want to print its current content to the terminal. What command shows the value stored in value1?
echo $value1
5
You have a large text file called words and you only want to see lines that mention the word “ bull”. What command filters that for you?
cat words | grep bull
5
You were testing a temporary variable in your shell session but no longer need it. You want to remove it so it doesn’t interfere with future commands. What command would you run to delete a shell variable called variable1?
unset variable1
5
You suspect that your system can’t find certain commands because something might be wrong with your list of search directories. What command shows you all the directories your shell checks when looking for commands?
echo $PATH
5
You want to find all locations of the ls command, including whether it exists as a shell built in or in multiple directories. What command reveals all forms of ls your shell knows about?
type -a ls
5
You typed a common command (ls for example) and want to know whether it’s a shell builtin, a function, or an external file. What command gives you that classification?
type ls
5
You’re printing a price value in a message (This car costs 100 dollars) that includes a dollar sign, like "$100", and you don’t want the shell to treat it like a variable. What command outputs that message literally?
echo 'This car costs $100'
5
You installed a custom script in /user/bin/custom and want your system to prioritize this directory when searching for commands. What command prepends it to your existing path without removing anything?
PATH=/user/bin/custom:$PATH
5
You’re not sure where the executable file for the grep command is located. What command helps you find the full path to it?
which grep
5
You want to change into your Documents directory and immediately display the contents of a file named alpha.txt, all in one line. What command does that?
cd Documents ; cat alpha.txt
5
You often mistype clear as cls, so you want to create a shortcut for yourself that runs the correct command when you type the wrong one. What command sets up this kind of shortcut?
alias cls='clear'
5
You want to print a string that says (This is glob) but it contains special globbing characters like ?, *, and [ ], but you don’t want the shell to interpret them. What command ensures the characters are shown as-is?
echo "This is glob ?*[]"
5
You want to test creating a small shell function named greet that prints "Hello, world" every time it’s called. What command would you use to define that in your terminal session?
greet() { echo "Hello, world" }
5
You’re displaying a message ( The service costs$1 and the path is $PATH) that contains both a dollar sign that shouldn't be interpreted ($1) and one that should ($PATH). What command outputs the dollar amount as-is while still expanding the path variable?
echo The service costs\$1 and the path is $PATH
6
You want to display today’s date inside a sentence like “Today is ...” and have the current date automatically inserted into the message. What command lets you do that?
echo Today is \date
6
You try to cat a file that might not exist (fake.txt) . If the command fails, you want to display a custom message like “File not found!” immediately after. What command structure lets you run the second command only if the first fails?
cat fake.txt || echo "File not found!"
6
You want to move to a folder named Documents/School , and only if it does work, print the message "success". What command structure lets you run the second action only if the first one succeeds?
cd Documents/School && echo Success
6
You want to learn more about how a command like ls works and see its official documentation directly from your terminal. What command do you use to open its manual page?
man ls
6
You're inside a manual page and want to exit quickly. What key do you press?
Q
6
After finding the first match in your man page search, you want to jump to the next match. What key lets you continue searching forward through the page?
n
6
You opened a man page and are confused. You want to see a help screen showing how to navigate within the page. What single key do you press to view navigation help?
H
6
While reading a man page, you want to search for the word “size”. What key lets you begin a forward search through the page content?
/size
6
You’re reading a man page and want to go back to the previous search match instead of the next one. What key lets you reverse the search direction?
Shift+n
6
You're not sure which section of the man pages a command is in. You want a quick summary of what the (ls) command does and which section it's located in. Which 2 commands give you this summary line?
man -f ls (or) whatis ls
6
You want to know how many total files on your system match the word "cron". You don't want to see the file names, just the count. What command gives you that?
locate -c cron
6
You want to read about how the ls command works in terms of file formats and system configuration, not just how to run it. What command lets you view the manual page for ls in section 5 (file formats)?
man 5 ls
7
You're trying to find any man page that references networking. Which commands helps you search all manual page descriptions for a keyword?
man -k networking (or) apropos networking
7
You remember a file you used earlier in /etc, but can’t recall its name. You want to quickly search your system’s file database for any path that includes “passwd”. What command shows all matches?
locate passwd
7
You're only interested in files named exactly “passwd”, not paths that merely contain it. What command restricts results to those whose final component matches exactly?
locate -b '\passwd'
7
You’re inside an info page and want to scroll up one full screen of content. What key do you press?
u
7
You want to get a more structured, hyperlinked, and readable version of the documentation for ls, rather than the classic man page. What command opens this kind of help page?
info ls
7
While browsing an info manual, you want to view the location of the current node you're reading and how it fits within the overall document. What key shows this info?
L
7
You want a one-line summary of how to use the tar command without opening its manual. What command gives you a short, quick overview right in the terminal?
tar --help
7
You're inside an info manual and want to open a quick summary of all navigation keys and their functions. What key combo do you press?
Shift+h
8
You want to quickly switch to another user's home directory—specifically, john—without typing the full path. What shortcut can you use?
cd ~john
8
You're deep inside some subdirectories and want to verify your exact current location in the filesystem. What command shows the full path to where you are right now?
pwd
8
You want to view the contents of a directory without viewing auto color settings, which command do you use?
\ls
9
You're in a folder and want to move one level up to the parent directory. What command do you use?
cd ..
10
You want to see all files in a directory, including hidden files like .bashrc. What command shows you everything, even files starting with a dot?
ls -a
10
You’re interested only in the permissions and metadata of a directory itself (Documents for example)—not its contents. What command displays that information without listing the directory’s contents?
ls -ld Documents
10
You want to see how much disk space each file in the current directory is using. What command shows the size (in blocks) alongside file names?
ls -s
11
You're comparing file timestamps and want to see which files were modified most recently. What command lists files sorted by modification time?
ls -t
11
You're auditing log files and need to know the exact timestamp, down to the second, for when each file was modified. What command gives you full date and time details?
ls --full-time
11
You want to print a table of ASCII values from a command line tool that specifically shows characters and codes. What command displays the ASCII reference chart in the terminal?
ascii
12
You want to learn about the ASCII character set and how characters map to numbers. What command shows you the ASCII table from the system's manual database?
man -s 7 ascii (or) man 7 ascii
13
You’re organizing project files and want to view only the .txt documents in your current directory to quickly check which ones need editing. What command would you run?
ls *.txt
13
You're debugging and want to inspect only the files named error1.log, error2.log, and error3.log (but not error10.log). How would you list just those?
ls error?.log
13
You’re in a folder containing subdirectories like alpha, beta, gamma, and you want to list only the ones that start with a consonant. What command lets you exclude names starting with vowels?
ls [!aeiou]*
14
You're filtering a group of files and want to match any file that starts with log followed by either a, b, or c. What wildcard pattern lets you do that?
ls log[abc]
14
You're inside a folder and only want to confirm the name of the folder itself, not its contents. What command shows just the folder entry without listing what’s inside it?
ls -d
15
You're preparing a backup of report.txt before making edits. You want to duplicate it in the same directory with the name report_backup.txt. What command should you use?
cp report.txt report_backup.txt
15
Q: You're copying a folder named Templates into another folder called Archive, including everything inside Templates. What command should you use to copy it with its contents?
cp -r Templates Archive
16
You’re trying to copy data.txt to a location where a file with the same name already exists (/some/path/data.txt). You want to be prompted before overwriting. What command protects you with a prompt?
cp -i data.txt /some/path/data.txt
16
You're copying notes.txt to notes_backup.txt and want to see a confirmation line printed for each file copied, to keep track of progress. What command do you use?
cp -v notes.txt notes_backup.txt
17
You're copying summary.txt to a directory (/some/path/), but you want to silently skip the copy if the file already exists. What command ensures the original isn’t overwritten?
cp -n summary.txt /some/path/
17
You want to rename draft.txt to final.txt in the same directory. What command accomplishes this renaming?
mv draft.txt final.txt
18
You're moving report.pdf to a Documents/ directory and want to see a message confirming the move. What command would you use?
mv -v report.pdf Documents/
18
You’re moving invoice.pdf to Archive/ but want the system to ask you before overwriting anything with the same name. What command do you use?
mv -i invoice.pdf Archive/
19
You want to move slides.pptx to the Presentations/ directory but only if a file with that name doesn’t already exist there. What command prevents overwriting silently?
mv -n slides.pptx Presentations/
20
You're creating a blank file named notes.txt to begin drafting your ideas. What command initializes the file?
touch notes.txt
20
You want to delete temp.log, but want the system to ask before removing it, just in case you make a mistake. What command provides this safeguard?
rm -i temp.log
21
You want to delete the entire folder OldProjects/ along with everything inside it. What command removes it ?
rm -r OldProjects/
22
You want to delete an empty folder called logs/. What command would you use, knowing it must be empty to work?
rmdir logs/
23
You want to compress a file called data.csv using a standard compression method to save space. What command should you use?
gzip data.csv
24
You have a .gz file named data.csv.gz and want to restore it to its original uncompressed form. What command should you use?
gunzip data.csv.gz (or) A: gzip -d data.csv.gz
24
You want to compress a large file project.tar using the bzip2 compression method to get better compression than gzip. What command do you use?
bzip2 project.tar
25
You need to decompress a file named project.tar.bz2 that was compressed with bzip2. What command do you use to extract it?
bunzip2 project.tar.bz2
25
You’ve downloaded a file called bigdata.csv and want to compress it using the xz compression format to maximize space savings. What command do you use?
xz bigdata.csv
26
You want to uncompress bigdata.csv.xz so you can view the raw CSV data again. What command decompresses the file?
unxz bigdata.csv.xz
26
27
28
28
28
29
29
29
30
30