Linux Command Fundamentals Flashcards
What commands help explain the use of specific commands and their syntax?
command –help
man command
pinfo
What is the difference between su and sudo?
- su is used to open the shell as another user.
- sudo allows commands to be run in escalated mode.
What is the wheel group used for in RHEL?
The wheel group is used to assign a user root privlidges.
Users in this group can be seen in the group configuration.
$ cat /etc/group | grep wheel wheel:x:10:student
What is su - used for?
su - can be used to open a shell as another user
su - without any username will open as root (if enabled).
What is sudo used for?
sudo allows authorised users to run tasks with escalated privileges.
sudo ls -l /root
The user must be a member of the wheel group
What two types of options are often used with commands?
- Long options; these start with a – (double dash) e.g. –help
- Short options; these start with a - (single dash) e.g. ls -l and mkdir -p
What does the whoami command do?
The whoami prints the username associated with the current user.
What is the ls command used for?
The ls command lists directory contents.
What command line utility is used to administer network interfaces?
The ip utility is used to administer network interfaces.
What text user interace is used to administer network interfaces?
nmtui
What command is used to show addresses assigned to all network interfaces?
ip a (ip address)
What is the cat command used for?
The cat command is used to print files to the standard output.
Usage: cat /etc/hosts
What command line utility is used to list directory contents?
ls lists directory contents
What command is used to locate the current directory?
The pwd is used to print name of current/working directory.
What is the pwd command used for?
The pwd is used to print name of current/working directory.
What command is used to reset a password?
The passwd command is used to update a user’s authentication token(s).
What is the passwd command used for?
The passwd command is used to update a user’s authentication token(s).
What is the touch command useful for?
The touch command can be used to quickly create a file and to test if a user has permissions to modify a file e.g.
~~~
$ touch /etc/hosts
$ touch: cannot touch ‘/etc/hosts’: Permission denied
~~~
What command can be used to quickly verify if a user has permission to modify a file?
The touch command can be used to quickly create a file and to test if a user has permissions to modify a file e.g.
~~~
$ touch /etc/hosts
$ touch: cannot touch ‘/etc/hosts’: Permission denied
~~~
What commands can be used to view the manual page names and descriptions?
- apropos
- man -k
Example:
~~~
$ man -k directory
$ adcli (8) - Tool for performing actions
~~~
man -k & apropos both search the mandb based on a keyword
What could cause man -k or apropos to return “nothing appropriate”?
The database searched by apropos is updated by the mandb program; this is updated periodicallly by a cron job and may require a manul execution on newly installed systems.
To manually update the mandb, execute the command with root privileges.
$ mandb
see man man (-k) or man apropos and man mandb
What ls command displays hidden files?
The ls -a command does not ignore entries starting with . (dot).
What is ls -d option useful for?
The ls -d option is used to see the properties of the directory and not its contents.
When using the ls utility, what is the -l option used for?
The ls -l command returns the results in the long listing format.
When using the ls utility, what is the -s option used for?
The ls -s (–size) option prints the allocated size of each file, in blocks.
What is the ls -lrt command useful for?
The ls -lrt shows the last modified file last.
* -l - use a long listing format
* -r (–reverse) - reverse order while sorting
* -t - sort by time, newest first; see –time
What two commands can be used to list the contents of all directories in a parent folder?
The ls -R and tree commands returns all subfolders and their contents.
ls -R
tree
Example
$ ls -R
.:
Desktop Documents Downloads Music Pictures Public Templates users Videos
./Desktop:
./Documents:
./Downloads:
./Music:
./Pictures:
./Public:
./Templates:
./Videos:
$ tree
.
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
├── users
└── Videos
-R, –recursive list subdirectories recursively
.
What key combination can be used to access to terminal session when in desktop session?
Ctrl + Alt + F3
What key combination can be used to access the desktop session when in a terminal session?
Ctrl + Alt + F2
What command can be used to create a list of active users and their terminals?
$ who
```
$ w
~~~
What can the chvt command be used for?
The command chvt N (terminal number from who) makes the /dev/ttyN the foreground terminal.
This command must be run using escalated privildeges.
What is the difference between command options and arguments and parameters?
What are the 9 man sections?
- User command (executable programs or shell commands)
- System calls (functions provided by the kernel)
- Library calls (functions within program libraries)
- Special files (usually found in /dev)
- File formats and conventions eg /etc/passwd
- Games
- Miscellaneous (including macro packages and conventions),
- System administration commands (usually only for root)
- Kernel routines [Non standard]
The command below can used to read an introduction of a specific section
~~~
$ man N intro
~~~
Sections 1, 5 and 8 are most important for basic administration (RHCSA)
How do you search through a man page?
using / (forward slash) with a string
use n to skip forward through the search results. shift + n reverse.
How do you find a command in a specific section?
If the section is known e.g. it is an adminstrator command (8)
~~~
man -k user | grep 8
~~~
If the section is not known, the man -k user command (without grep) will return all references to user and the section.
What are the two most common editors?
nano & vim (vi improved)
What command outputs the results to a file?
’>’ (greater than)
~~~
ls > directory
~~~
What command appends the results to a text file?
’»’ (double greater than)
~~~
ls»_space; directory
~~~
What command is used to view recently used commands?
history
The history file is found under ~/.bash_history
How do you remove a line from the history file?
history -d n
How do you replay a specific command from history?
!n
The history command returns all stored commands with a row number.
What does the 2> /dev/null command do?
The 2> /dev/null is used to redirect/supress errors.
The command broken down:
* 2 refers to a standard error,
* ‘>’ (greater than) is a file redirection operator and
* /dev/null is a null device used to suppress any data written to it.
The 3 file descriptors are:
‘0’ for standard input
‘1’ for standard output
‘2’ for standard error
How do you search for files and folders begining with a specific character?
ls -d a*
How do you search for files and folders with charachters begining a, b or c?
ls -d [abc]*
How do you create a directory path?
mkdir -p /tmp/folder1
-p, –parents no error if existing, make parent directories as needed
How do you remove a directory?
rmdir -p /tmp/folder1
How do you create a directory path with multiple subfolders?
mkdir -p /tmp/{folder1, folder2, folder3}
-p, –parents no error if existing, make parent directories as needed
How do you remove a directory path with multiple specific subfolders?
rmdir -p /tmp/{folder1, folder2, folder3}
How do you copy between directories?
cp /tmp/currenthome /tmp/newhome/