Terminal Usage and Shell commands Flashcards
What is a Shell?
A shell is an OS-level application that interprets and executes user commands.
It provides an interface between the user and the operating system, allowing users
to interact with the system through text-based commands.
When navigating through the filesystem what do the following symbols represent: ~ | / | .. | .
▶ ~ Home directory
▶ / Root directory
▶ .. Parent of current directory
▶ . Current directory
When using vim how do you do the following:
- enter insert mode
- create a new file
- exit vim
- write in the file
- how to quit without saving
- Press i to enter Insert mode.
- Enter :save example.txt to create a file.
- Enter :w to write the file without exiting.
- Enter :q to exit and :q! to exit without saving
- Enter :w to write in a file
What do the following commands do:
- whoami
- uname
- id
- df
- echo
Command: whoami
Displays the username of the current user.
ex: user123
Command: uname
Shows system information.
ex: Linux ubuntu 5.4.0-72-generic
Command: id
Displays user ID and group ID.
ex: uid=1000(user123) gid=1000(user123) groups=1000(user123),27(sudo)
Command: df
Displays disk space usage
ex: Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
Command: echo
Displays a line of text or variables.
- What command displays currently running processes?
- What command Displays real-time process monitoring?
-What command displays the manual page for other commands?
- ps, ps aux(#all running processes (a) in a user-oriented format (u),
#including those not associated with a terminal (x).)
Ex:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
root 1 0.0 0.1 169336 1144 ? Ss 10:00 0:01
user123 1836 0.1 1.5 50000 12300 ? S 10:10 0:00 - top
Ex:
top - 10:15:42 up 1:15, 2 users, load average: 0.03, 0.05, 0.01
Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie - man command
Ex: man ls
What do ls and ls -l do?
- ls - list files and directories.
- ls − l - shows child files and directories in a detailed format.
ex:
For ls -l it will display files in the mode drwxr—w-
Explain what the Permissions configuration is and what it looks like
Permissions configuration:
The first character indicates whether it is a directory (d), a file (-), or a symbolic link
(l), among others.
The following 9 characters are divided into three groups of 3 characters each:
permissions for the owner, group, and others.
▶ r (read) - Permission to read.
▶ w (write) - Permission to write.
▶ x (execute) - Permission to execute.
What do pwd and cd do?
- pwd (print working directory) - get current working directory.
- cd (change directory) - change the directory.
How do you find files in the terminal?
- Using the find command: Can be either name - case sensitive or iname - case insensitive
-Ex: find . name “my_file.txt”
-Ex: find ~ iname “my_File.txt”
How do you create a file or a directory?
mkdir (make directory) - to make a directory.
touch - create empty files.
How do you remove a file or a directory?
- rm file_name for files
- rm -r dir_name for directories
How do you copy a file or a directory?
- cp - copy files and directories.
- cp -r for directories
Ex:
cp /source/file /dest/filename #to specify a new filename
cp /source/file /dest/
Ex:
cp -r /source/dir/ /dest/dir/
How do you move a file or a directory?
- mv - move files and directories.
Ex:
mv /source/file /dest/dir/
mv /source/dir/ /dest/dir/
How do you change file permissions?
chmod (change mode) - change file permissions.
- +x for execute permission, +w for write permission, +r for read permission.
- u means user, g mean group, o means others.
Ex:
chmod u+w file.txt
How to sort lines in a file?
- sort <filename.txt> #Sort alphabetically</filename.txt>
- sort -r <filename.txt> #Reverse order</filename.txt>