Linux commands Flashcards
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?
w
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?
history
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?
clear
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?
whoami
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?
passwd
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?
Ctrl+D
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?
ls -l
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?
ls -r
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?
ls -h
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?
Up arrow (⬆️ key)
You want to rerun the command you entered three commands ago, without looking it up. What shortcut lets you do that?
!-3
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?
!3
You just ran a command with a typo and want to rerun the exact previous command again immediately. What shortcut does that?
!!
You only want to view the last 3 commands you ran, not your full history. What command shows just those three?
history 3
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?
!ls
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?
variable1=”Good Morning”
You’ve defined a variable (variable1) and now want to print its value to the terminal to verify it. What command do you use?
echo $variable1
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?
env
You want to find out how many previous commands your shell is storing in memory. Which env variable holds that setting?
echo $HISTSIZE
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?
export value1 value2
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?
value1=”$value1 $value2”
You want to confirm whether a variable named HOME exists in your environment and see its exact value. What command should you run?
env | grep HOME
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?
env | head -n 5
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?
type ll