Font size
WorksheetsQuiz 1: Commands for Searching and Working with Files
Total questions: 67
Worksheet time: 36mins
To search for text inside files:
search
locate
find
grep
How do you search only for directories with find?
find / -type d
find / -type f
find / -folder
find / -dir
You need to count how many times "Failed" appears in /var/log/syslog. Which command is correct?
wc -l /var/log/syslog
grep "Failed" /var/log/syslog
grep -c "Failed" /var/log/syslog
cat /var/log/syslog | wc -c
How do you search all .txt files in Assignment3_Ann?
grep "*.txt"
find . -name "*.txt"
ls *.txt
locate .txt
How do you search for a file named "file1.txt" in /home directory using find?
find / -name file1.txt
find /home -name file1.txt
locate file1.txt
You want to search recursively for the string “ERROR” in all .log files inside /var/log. Which command is correct?
grep ERROR /var/log/*.log
grep -r --include="*.log" "ERROR" /var/log
find /var/log --name "*.log" --exec grep ERROR
Both B and C
To search for a specific word in a file, you use:
grep
wc
cut
sort
How do you search for a specific string in a file?
locate string
find filename string
grep "string" filename
cat filename | string
The difference between local and environment variables is that:
Local variables can only be used by root
Environment variables cannot be exported
Environment variables are global to all shells
Local variables persist after logout
Using a pair of back quotes (`) will cause a shell to execute the back-quoted text as a command and substitute the output back into the original command.
True
False
What does . at the beginning of a filename indicate?
Script file
Directory
Hidden file
Executable file
What does a single dot . represent?
Home directory
Parent directory
Root directory
Current directory
The tilde (~) is used to represent:
The directory above the current working directory
Nothing, it has no special meaning
Any two single characters
A user’s home directory
Which symbol is used in commands to execute a file from the current directory?
/
~
./
...
The command echo $HOME > /home/user/docs/homepath.txt will:
The primary difference between the > and >> redirection operators is:
> overwrites a file, while >> appends output to it.
>> redirects standard error, while > redirects standard output.
> creates a binary file, while >> creates a text file.
Both are identical in function.
How do you append the current date to file3.txt?
cat date > file3.txt
echo date > file3.txt
touch file3.txt
date >> file3.txt
You are in /home/user and want to switch to /home/user/Documents using a relative path. Which command works?
cd Documents
cd ./Documents
Both A and B
cd ~/Documents
If you type cd -, which directory will you go to?
/home
Root directory
/tmp
The previous directory you were in
The cd command by itself will take you to what directory?
All are correct
Your home directory
The system root directory
The directory above the current working directory
Where is the root user’s home directory located by default?
/etc/root
/home/root
/root
/usr/root
The root directory in Linux is represented by:
C:\
/
~/
/root
You are in /home/user/Documents/Projects and want to navigate to /home/user/Downloads. Which command is correct?
cd ~/Downloads
cd ./Downloads
cd /Downloads
cd ././Downloads
Which command will allow you to change to a directory located in the root directory?
cd /
cd ...
cd ~
cd /
The cp command is used to:
Compile code
Compare files
Compress a file
Copy files
The command that creates a new directory is:
mkfile
createdir
mkdir
make
Which command removes a file permanently?
rm
erase
del
delete
Executing rmdir -p empty/inner/ removes:
Nothing — command requires -r
Both inner/ and its parent empty/ if they are empty
None of the above
Only inner/
Which command is used to create a new file in Linux?
cp
mv
touch
mkdir
How do you open file1.txt in a text editor and write your info?
nano file1.txt
cat file1.txt
touch file1.txt
ls file1.txt
Which command displays the contents of a file on the terminal?
rm filename
ls filename
touch filename
cat filename
Which command combines and displays the contents of files sequentially?
paste
join
merge
cat
To view the first 10 lines of a file:
view
start
tail
head
What is the command used to display the contents of a file in reverse order in Linux?
head
cat
less
tac
How do you copy about_me.txt to backup.txt inside docs?
nano docs/backup.txt
touch docs/backup.txt
mv about_me.txt docs/backup.txt
cp about_me.txt docs/backup.txt
You want to move file3.txt into docs and then copy about_me.txt into docs as backup.txt, all in one line. Which command is correct?
mv file3.txt docs/backup.txt && cp about_me.txt docs/
cp file3.txt docs/; mv about_me.txt docs/backup.txt
mv file3.txt docs/ && cp about_me.txt docs/backup.txt
touch docs/file3.txt docs/backup.txt
Which command is used to copy a file from one directory to another in Linux?
cp
rm
mkdir
mv
Which command is used to move a file in Linux?
move
rename
cp
mv
You want to create a hidden file .config in your home directory. Which command works?
touch config
touch /config
touch ./config
Where is the root user’s home directory located by default?
/etc/root
/home/root
/root
/usr/root
Which command displays the current username?
logname
id
who
whoami
To see current logged-in users:
log
id
who
users
Which command displays memory usage?
top
free -h
df -h
uname -r
Which command shows environment variables?
getenv
showenv
env
Which command displays the system hostname?
host
iphost
dnsname
hostname
Which command is used to display the IP address of the computer?
netstat
ipconfig
ifconfig
netconfig
Which command displays the file and directory permissions in octal format?
chmod
ls -l
chown
stat
Which command displays file type, size, permissions, and modification date?
file
ls
ls -lh
stat
To display permissions of all files in a directory:
ls -a
ls
ls -l
What is the command to list all the hidden files in a directory?
ls -a
ls -l
ls -h
ls -R
What does ~/Documents refer to?
/Documents directory in root
Documents folder in /tmp
Documents folder inside the current user's home directory
Documents folder in current directory
The file /etc/passwd contains:
User passwords
Group permissions
User account information
System logs
Which option generally works to get quick usage information for most Linux commands?
--help
man
guide
info
To get basic help for shell built-in commands, you can use:
guide
man
The ‘man’ command is used to:
Run a program as another user
Display manual pages for a command
Display a file’s contents
Create a new user
Which command displays the manual page for a command in Linux?
info
man
guide
help
What does whatis command do?
Shows a short description of a command
Opens a manual page
Shows all options for a command
Searches online Linux documentation
The whatis command is the same as man -w.
False
True
Select the command that can report the location of a command:
where
what
which
sudo
This command is normally executed to search for a command or man page:
man -k
updatedb
find
wheres
Which command compresses a file using gzip?
tar file
gzip file
zip file
compress file
Which tar command correctly creates a compressed archive using gzip?
gzip -cvf archive.tar dir/
tar -czvf archive.tar.gz dir/
tar -xvf archive.tar dir/
tar -cvf archive.tar.gz dir/
The command to extract contents of a .tar archive:
untar archive.tar
tar -xvf archive.tar
unzip archive.tar
xz -d archive.tar
What command can be used to compress a file using the LZMA algorithm?
lzma
zip
gzip
The 'grep' command is used for:
Searching for patterns in text
Editing text files
Displaying system processes
Compressing data
What does the "grep" command do?
It creates a new directory.
It removes a file or directory.
It compresses files and directories.
It searches for a specific text within a file.
Which command shows the PID, CPU%, MEM%, and COMMAND columns for all processes?
http
ps aux
top -b
pstree
