Commands Flashcards
Which command enables one to show all available NFS mounts on ‘server1’?
showmount -e server1
The ‘-e’ option specifies that the command show the servers export list.
Which command can be used to show all available disk space on mounted devices?
df -hT
Just ‘df’ works but the ‘-h’ option formats the output in a human readable form and the ‘-T’ option shows which file system type is used on the different mounts.
Which command gives an overview of all mounted devices?
mount
Which command would list all files/directories (including hidden ones) along with their permissions inside a given directory?
ls -al
Which command would copy the contents of the ‘/etc’ directory (including other directories) to the ‘/tmp’ directory?
cp -R /etc /tmp
The -R option stands for recursive and allows subdirectories to be copied as well.
Which command would move the ‘myFile’ file to the
‘/tmp’ directory?
mv myFile /tmp
Which command would enable one to rename ‘myFile’ to ‘myNewFile’ ?
mv myFile myNewFile
Which command would create a symbolic link to the ‘/etc/passwd’ file in the current directory?
ln -s /etc/passwd .
Which command would create a new archive named ‘archive.tar’ in the directory ‘/root’, containing the contents of the entire ‘/etc’ directory?
tar -cvf /root/archive.tar /etc
The ‘-v’ option can be omitted as it simply lists the verbose output during execution.
The ‘-f’ option is used to specify the name of the archive file. It can often be omitted.
How would one add a single file named ‘singleFile’ to the already existing ‘archive.tar’ file?
tar -rvf archive.tar singleFile
The ‘-r’ option appends files to an existing archive.
Which command lists the contents of a tar archive ‘archive.tar’ without actually extracting it?
tar -tvf archive.tar
Which command would extract the contents of the ‘/root/archive.tar’ file and move the contents to the ‘/tmp’ directory?
tar -xvf /root/archive.tar -C /tmp
Extracting also works like this for compressed archives as tar will automatically recognize compressed content and then decompress it during extraction.
The ‘-C’ option stands for ‘change directory and tells tar to change the directory to where the command output will be placed.
Which command would create a compressed archive ‘archive.tar’ of everything within the ‘/etc’ directory and place that compressed archive in the ‘/home’ directory?
tar -czvf /home/archive.tar.gz /etc
tar -cjvf /home/archive.tar.bz2 /etc
tar -cJvf /home/archive.tar.xz /etc
All three of the above options work. The ‘-z’ option compresses with gzip. The ‘-j’ option compresses via bzip2 and the ‘-J’ option compresses via xz.
Which command would enable one to set the system time to 4:24 P.M. ?
date -s 16:24
Normally, ‘date’ retrieves the current time setting but the ‘-s’ option allows one to set the time.
Which command sets the hardware time from the system clock?
hwclock –systohc
hwclock -w
Which command shows epoch time as human-readable time?
date -d ‘@nnnnnnnn’
‘nnnnnnnn’ is the number of seconds since midnight on January 1st, 1970.
The ‘-d’ option specifies that the ‘date’ command will take a string specifying a time rather than just displaying the current time.
Which command enables you to use NTP time on your server?
timedatectl set-ntp 1
Which configuration file contains the list of NTP servers to be used?
/etc/chrony.conf
Which command displays information about the current time sources that ‘chronyd’ is currently accessing?
chronyc sources
Which commands would you use to display only line number 5 from the file ‘/etc/passwd’?
head -n 5 /etc/passwd | tail -n 1
Which command filters out just the first field from the file ‘/etc/passwd’?
cut -d : -f 1 /etc/passwd
The ‘-d’ option specifies the delimiter used in the file. The ‘-f’ option specifies which field to retrieve.
Which extended regular expression will match all files/subdirectories (including ‘/etc’) within the ‘/etc’ directory?
grep -rE ‘/etc(/.*)?’
The ‘.’ matches any single character.
The ‘*’ matches zero to an infinite number of the preceding character.
The ‘?’ matches zero or one of the preceding character.
The ‘-r’ option specifies to search files in the current directory and all subdirectories.
Which regular expression will match lines that do not begin with a ‘#’ in the file ‘/etc/services’?
grep -v ‘^#’ /etc/services
The ‘-v’ option shows lines that do not match the regular expression.
Which grep command enables you to see ‘text’ as well as ‘TEXT’ in a file named ‘/home/user/files’?
grep -i ‘text’ /home/user/files
The ‘-i’ option makes the regex case insensitive.